Last active
September 17, 2015 07:38
-
-
Save sahildua2305/5686ebbd0051424e1762 to your computer and use it in GitHub Desktop.
sds
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# '-' for empty position | |
# 'O' for marking O is there | |
# 'X' for marking X has made a turn there | |
board = "---------" | |
# Assuming I already have a dictionary `board_states` for lookup | |
def nextMove(curr_move): | |
board[curr_move] = 'X' | |
# simply lookup the value of next move from the dictionary | |
index = board_states[board] | |
board[index] = 'O' | |
return index | |
# Optimal strategy | |
# To reduce the number of states to be stores in the dict, one way is to remove the duplicates. | |
# Initially let's say we have stores only the unique board states. | |
# Now for lookup, we will check for 4 possible rotations of the current board state and check whichever state is available in the dict and return the corresponding next move. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment