Created
April 13, 2011 17:07
-
-
Save flopezluis/917918 to your computer and use it in GitHub Desktop.
Just for fun
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
players = ('0','X') | |
turn = 0 | |
exit = False | |
board = {0:'-', 1:'-',2:'-', 3:'-', 4:'-',5:'-',6:'-', 7:'-',8:'-'} | |
win_combinatios= [[0,1,2], \ | |
[3,4,5], \ | |
[6,7,8], \ | |
[0,3,6], \ | |
[1,4,7], \ | |
[2,5,8], \ | |
[0,4,8], \ | |
[2,4,6]] | |
def get_string_board(): | |
str_board = [''.join(row) for row in board.values()] | |
return ''.join(board.values()) | |
def check_win(key): | |
for com in win_combinatios: | |
if key in com: | |
com[com.index(key)] = board[key] | |
if com.count(board[key]) == 3: return True | |
return False | |
if __name__ == "__main__": | |
while (not exit): | |
new_turn = input(get_string_board() + "\n:") | |
if board[new_turn] != "-": | |
print "Repeat please\n" | |
else: | |
board[new_turn]=players[turn] | |
turn = not turn | |
if check_win(new_turn): | |
print "WIN ->%c" %board[new_turn] | |
exit = True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment