python question! Practice project: The tic-tac-toe game we are going to create i
ID: 3675103 • Letter: P
Question
python question!
Practice project: The tic-tac-toe game we are going to create is the well-known game: There is a 3x3 board (matrix). initially empty. There are two players, the X-player and the O-player, that take turns each making one move' at a time. A move, is the placement of an X, or an 'O' in a currently empty position of the board by the X-player or the O-player. respectively (depending on whose turn it is to play). The X-player always starts first. The winner is the first player that will fill a horizontal or a vertical or a main diagonal line with his/her symbol (i.e., three consecutive 'X's or 'O's). Note that the game may end without a winner (actually kids stop playing the game once they realize that, after a little thought, draw is always the end-result). In this project, there are two possibilities for the game: either both players are human (2-player mode) or one player is human and the other player is the computer. To simplify things, let's always assume that the X- player is human. To help the player(s), after every move, the computer outputs the current state of the board in the following formatExplanation / Answer
def newprint_board(newboard): print "The board look like this: " for i in range(3): print " ", for j in range(3): if newboard[i*3+j] == 1: print 'X', elif newboard[i*3+j] == 0: print 'O', elif newboard[i*3+j] != -1: print board[i*3+j]-1, else: print ' ', if j != 2: print " | ", print if i != 2: print "-----------------" else: print def print_instruction(): print “select position " newprint_board([2,3,4,5,6,7,8,9,10]) def get_input(turn): valid = False while not valid: try: user = raw_input("which position do you want to place at " + turn + " (1-9)? ") user = int(user) if user >= 1 and user 4: winner = inordertocheck_win(newboard) if winner != -1: out = "The winner is " out += "X" if winner == 1 else "O" out += " :)" quit_game(newboard,out) elif move == 9: quit_game(newboard,"No winner :(") if __name__ == "__main__": main()Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.