Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- board = {'A':' ', 'B':' ', 'C':' ',
- 'D':' ', 'E':' ', 'F':' ',
- 'G':' ', 'H':' ', 'I':' '}
- def play(move):
- if board[move] == '':
- board[move] = 'X'
- def printBoard(board):
- print(board['A']+ '|' + board['B'] + '|' + board['C'])
- print('-+-+-')
- print(board['D']+ '|' + board['E'] + '|' + board['F'])
- print('-+-+-')
- print(board['G']+ '|' + board['H'] + '|' + board['I'])
- def didYouWin(board, letter):
- return ((board['A']==letter and board['B']==letter and board['C']==letter) or
- (board['D']==letter and board['E']==letter and board['F']==letter) or
- (board['G']==letter and board['H']==letter and board['I']==letter) or
- (board['A']==letter and board['E']==letter and board['I']==letter) or
- (board['A']==letter and board['D']==letter and board['G']==letter) or
- (board['C']==letter and board['E']==letter and board['G']==letter) or
- (board['C']==letter and board['F']==letter and board['I']==letter) or
- (board['B']==letter and board['E']==letter and board['H']==letter))
- turn = 'X'
- for i in range(9):
- printBoard(board)
- print('player ' + turn + ' what is your move??')
- move = input()
- board[move] = turn
- if didYouWin(board,turn):
- printBoard(board)
- print('YAY! you won, player '+ turn)
- break
- if turn == 'X':
- turn = 'O'
- else:
- turn = 'X'
- printBoard(board)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement