Python: Tic Tac Toe program Using Python write code to build a graph of all the
ID: 3567767 • Letter: P
Question
Python: Tic Tac Toe program
Using Python 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
1. How many vertex represent a win for X (should be 626)
2. How many vertex represent a win for O (should be 316)
3. How many vertex represent a tie (board must be full, should be only 16)
4. Total number of legal boards that occur in the tic-tac-toe game (that count the number of vertices, should be 5,478)
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
100% Fresh answer, guaranteed to get you best grades possible. Just check it out: http://programmingtutor3.tk/
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.