serious answer only please and also stop posting same answer you find in chegg b
ID: 3568617 • Letter: S
Question
serious answer only please and also stop posting same answer you find in chegg because I already read them and most are of them are wrong and I won't reward you.
READ THE INTRUCTIONS:
Write code to build a graph of all the possible tic-tac-toe games that uses the pythons.graphs Graph and Vertex classes.
Each vertex represents a unique board, and each edge represents a legal move from a given board position to the new board.
Assume that X always moves first.
Then print the following
Just use a string like: "XO X OX " where the string is always 9 chars long and uses X, O, and spaces to represent the board. use this string as the id of the vertex. That way the id also has everything you need to represent the board.
I recommend writing a set of methods to find legal moves for O or X give a current board, and a method to test if X or O has won. And way to detect if game is tie (no more moves, and no one has won).
Example of vertex and edges within graph
" " -----> " X " edge for beginning board transition where X plays into center square.
" X " -----> "O X " edge from previous move where O now plays in upper left corner
"O X " -----> "OX X " edge from previous move where X now plays in upper middle square
Explanation / Answer
def print_board(board): print "The board look like this: " for i in range(3): print " ", for j in range(3): if board[i*3+j] == 1: print 'X', elif board[i*3+j] == 0: print 'O', elif board[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 "Please use the following cell numbers to make your move" print_board([2,3,4,5,6,7,8,9,10]) def get_input(turn): valid = False while not valid: try: user = raw_input("Where would you like to place " + turn + " (1-9)? ") user = int(user) if user >= 1 and user 4: winner = check_win(board) if winner != -1: out = "The winner is " out += "X" if winner == 1 else "O" out += " :)" quit_game(board,out) elif move == 9: quit_game(board,"No winner :(") if __name__ == "__main__": main()Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.