STEP 2: How to calculate win for step 1.1: same move spans across (horizontally) on one row # assuming we are checking for the move x NOTE: There will always be only 2 digonals. if the same move spans diagonally across the game, that is or.if the same move spans vertically along a column, that is or or are all of the same move.if the same move spans across (horizontally) on one row, that is, or or are all of the same move.Now, lets talk about the implementation of the algorithmįor this example, we will be taking X as our "winning" move (to make things easier). Why? This is because we need to keep track of a move and the tile number the move was made on. Inside each row we have a tile, which is represented as python dictionaries.The other 3 lists inside the "container list" stand for the 3 rows.We have one list (named as data) which is like the container.In our code above, we have the same structure: Why the above format? take a look at the image belowįrom the above image, we can see that there is one big block which is like the container, we have rows (the blocks that run horizontally from left to right) and columns (blocks that run vertically from up to down) and each row has 3 smaller blocks or tiles. # the lists are rows while the individual dictionaries are tiles (the move made and the tile number) NOTE: this algorithm assumes that the game data is passed in the following format data = [ In this article, we have presented an algorithm to check win and loss for a given Tic Tac Toe configuration.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |