Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
play tic tac toe org random bot
// https://playtictactoe.org/
function playGame(){
var restart = document.querySelector("div.restart");
if(restart.style.display=="block"){
restart.click()
}else{
var squares = document.querySelectorAll("div.square > div:not(.x):not(.o)");
var item=Math.floor(Math.random()*squares.length)
squares[item].parentElement.dispatchEvent(new Event('mousedown'));
}
}
var playBot = window.setInterval(playGame,500);
//window.clearInterval(playBot);
// And my notes that I used during recon when building the code
/*
restart div overlay
div.restart
document.querySelector("div.restart").click()
document.querySelector("div.restart").style.display
div.square
div.square > div:not(.x):not(.o)
document.querySelectorAll("div.square")[0].dispatchEvent(new Event('mousedown'))
document.querySelectorAll("div.square > div:not(.x):not(.o)")[0].parentElement.dispatchEvent(new Event('mousedown'))
true
document.querySelectorAll("div.square > div:not(.x):not(.o)")[0].dispatchEvent(new Event('mousedown', {"bubbles":true}))
*/
@eviltester

This comment has been minimized.

Copy link
Owner Author

@eviltester eviltester commented May 28, 2020

I was inspired to automate this game based on Angie Jones video using Java and WebDriver to provide another example of automating the same game.

Angie's video:

https://www.youtube.com/watch?v=nZZD2aFAm_A

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.