AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
![]() ![]() || gameAsString.charAt(idx-1) = '0') //only 1-9 are valid ![]() If(gameAsString.indexOf('' + idx) = -1 //only valid if every digit from 1-9 is found In order to determine if a combination is valid, we use the following Javascript snippet, which checks that the nine digit number does not contains zeros and contains all of the digits 1 to 9: //gameAsString contains the current number, e.g. In order to find every valid combination we simply start with that lowest number and iterate up to nine nines, attempting to determine if each number is a valid combination and if it is, record the results of the game. Most of the numbers are illegitimate because each cell is only allowed to be filled once, so for example the number 222222222 does not represent a valid combination. ![]() It’s not a perfect game because the first player misses a few opportunities to win and in the end it’s a draw.Įvery possible combination of moves making up unique games of tic-tac-toe are hence found somewhere between the numbers 123456799999 (although probably iterating up to 987654321 suffices). The game could continue and once completed could be written as “134258769”. These first four moves can be written down as “1342”. As an example, take the game where X moves top left, followed by O moving top right, then X going middle left followed by O going top middle. As part of a machine learning project, I had to understand tic-tac-toe better, and so I have written an algorithm which a) finds all the possible unique games and b) gathers statistical information about those games.īased on Wikipedia’s tic-tac-toe article, consider a board with the nine positions numbered as follows:Īssume X always starts. ![]()
0 Comments
Read More
Leave a Reply. |