if (not zeros_move): # ... and it's the TTF's move ... i = int(raw_input("Enter X in row __: ")) # ... prompt the TTF for the coordinates of their move. j = int(raw_input("Enter X in col __: ")) while (i < 0 or i > 2): # If the row number is not in {0, 1, 2} ... i = int(raw_input("Row should be between 0 and 2: ")) # ... prompt them again. while (j < 0 or j > 2): # Do the same for column number. j = int(raw_input("Col should be between 0 and 2: ")) Grid[i][j] = 'X' # Put an 'X' on the grid, once you have valid coordinates. print("\nYou: ") # Tell the TicTacFoe that the next grid they see will show their move. else: # ... otherwise if it's our (Zeros') move ... Grid[0][0] = '0' # ... play a default move of putting a '0' in the first row, first column. print("\nEarth's Mightiest Zeros: ") # This default move is a significant optimization, will be covered in the document. state = Gamestate(Grid, not zeros_move) # Now, make a Gamestate object that represents the current grid, and call it 'state'. state.make_states() # Generate the game's tree. state.calculate_value() # Compute each state's value. first_move = False # And it's no longer the first move, hence. else: # For every move after the first one ... if (not zeros_move): # ... if it's the TTF's move ... i = int(raw_input("Enter X in row __: ")) # ... prompt the TTF for the coordinates of their move. j = int(raw_input("Enter X in col __: ")) while (i < 0 or i > 2): # If the row number is not in {0, 1, 2} ... i = int(raw_input("Row should be between 0 and 2: ")) # ... prompt them again. while (j < 0 or j > 2): # Do the same for column number. j = int(raw_input("Col should be between 0 and 2: ")) while (isCross(state.grid, i, j) or isZero(state.grid, i, j)): # Now since this is not the first move, the board may not be empty, and ... print "Please enter unoccupied coordinates" # ... we need to check that the coordinates TTF is trying to play on are empty. i = int(raw_input("Enter X in row __: ")) # Prompt them again. j = int(raw_input("Enter X in col __: "))
from Gamestate import * Grid = [[' ', ' ', ' '], [' ', ' ', ' '], [' ', ' ', ' ']] state = Gamestate(Grid, True, 1) state.make_states() state.calculate_value() for st in state.states: printToConsole(st.grid), print("Value: "), print(st.value)