Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Exercise 27 - Tic Tac Toe Draw
- def end_of_game ( game ):
- full_set = set()
- for i in range(len(game)):
- full_set.update(game[i])
- return full_set == {"X", "O"}
- def ask_move():
- move_str = input("Player "+str(player)+", please enter Your move (row,col): ")
- move = move_str.split(",")
- moveX = int(move[0].strip())-1
- moveY = int(move[1].strip())-1
- return [moveX,moveY]
- def play ( game, symbol, X, Y ):
- if game[X][Y] == 0:
- game[X][Y] = symbol
- else:
- print("This move has been played already.")
- move = ask_move()
- play(game,symbol,move[0],move[1])
- def next_player ( player ):
- list_of_players = list(players)
- current = list_of_players.index(player)
- if len(list_of_players[current:]) == 1:
- return list_of_players[0]
- else:
- return list_of_players[current+1]
- if __name__ == "__main__":
- game = [[0, 0, 0],
- [0, 0, 0],
- [0, 0, 0]]
- players = {1: "X", 2: "O"}
- player = 1
- while not end_of_game(game):
- move = ask_move()
- play(game,players[player],move[0],move[1])
- print(game)
- player = next_player(player)
- print("End of game.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement