lab_tic_tac_toe/notes.md

3.4 KiB

Tic Tac Toe notes

Checkpoint 1 Notes

Which class is responsible for each of the following behaviors? For each, explain how the behavior is accomplished.

Checking to see whether the game is over

TTTGame is the class that checks if the game is over. The function is is_over and it operates by checking a series of other functions (with an or) based on the game's state. These other functions are board_is_full which checks each space and if there is an empty space (-) returns false and if there are no empty spaces returns true (and the game is over). If this is False, the is_over function will check for a winner for x and then for y. These functions will be written in checkpoint 2.

Determining which actions are available at a particular state

TTTGame also checks which actions are available at a particular state using get_actions which returns the board with a list of the unused spaces. It checks each space in the game and returns a list of any empty spaces (value of - instead of x or o). These values are then printed in TTTView.

Showing the board

TTTView is the class that shows the board. Print_board is the function in the class that most direclty prints the board. The class works by greeting the user greet(self) and then asks the user where they would like to put their X or O with get_action which also prints the board based on the printing directions in print_board. Print_board relies on format_row and format_value to decide where to put each x,o, or blank space.

Choosing which action to play on a turn

TTTHumanPlayer or TTTComputerPlayer select the action. TTTHumanPlayer allows the player to input a choice after seeing the baord, and then checks the choice to make sure it is an open space. If yes, it proceeds by returning the action which is then used in TTTGame. If the action is not permitted, such as when the space is already occupied or a non 1-9 vlaue is entered, the user is prompted again (although I can't find the code that specifically prints that error message!)

Checkpoint 2 Notes

TTT Strategy

For each of the following board states, if you are playing as X and it's your turn, which action would you take? Why?

| O | O | | O | X | X | O |
---+---+--- ---+---+--- ---+---+--- ---+---+--- X | X | | X | X | O | O | |
---+---+--- ---+---+--- ---+---+--- ---+---+--- | | | | O | | | |

View 1- Put x in Space 5, to win the game

View 2- Put x in Space 5, to precent the O's from winning

View 3- Put the x in Space 0, so there are then 2 possible ways to get 3 in a row on your next turn (space 3 or space 6)

View 4- Put the x in space 4, to block o from being able to get 3 in a row down the middle.

Initial game state

You can get the inital game state using game.get_initial_state(). What is the current and future reward for this state? What does this mean?

If state is set to game.get_initial_state(), there is a very large (but nonetheless finite), list of possible game outcomes that get printed out in the terminal. This means that there are many possibilites for either x to win, or o to win, or for the game to end in a tie. I'm not sure if there is a way to see which reward 0,1,or -1 is more likely. For example is there a way to see if the person who goes first has more paths to winning- I would think so, but it would be nice to know how much more likely!