Ejemplo n.º 1
0
 def test_downward_diagonal_win(self):
     x_token = XToken()
     grid = Grid(3, 3)
     grid_controller = GridController()
     grid_controller.assign_grid(grid)
     grid.add_token_position(x_token, 0, 0)
     grid.add_token_position(x_token, 1, 1)
     grid.add_token_position(x_token, 2, 2)
     winner = grid_controller.check_for_win()
     assert winner == x_token
Ejemplo n.º 2
0
 def test_upward_diagonal_win(self):
     o_token = OToken()
     grid = Grid(3, 3)
     grid_controller = GridController()
     grid_controller.assign_grid(grid)
     grid.add_token_position(o_token, 0, 2)
     grid.add_token_position(o_token, 1, 1)
     grid.add_token_position(o_token, 2, 0)
     winner = grid_controller.check_for_win()
     assert winner == o_token
Ejemplo n.º 3
0
 def test_horizontal_win(self):
     x_token = XToken()
     grid = Grid(3, 3)
     grid_controller = GridController()
     grid_controller.assign_grid(grid)
     grid.add_token_position(x_token, 0, 0)
     grid.add_token_position(x_token, 0, 1)
     grid.add_token_position(x_token, 0, 2)
     winner = grid_controller.check_for_win()
     assert winner == x_token
Ejemplo n.º 4
0
 def game_won(
     self,
     player_controllers: List[PlayerController],
     grid_controller: GridController,
 ) -> bool:
     winning_token = grid_controller.check_for_win()
     if winning_token is not None:
         for player_controller in player_controllers:
             if player_controller.retrieve_token() == winning_token:
                 player_controller.print_player()
                 print(data.WINNING_MESSAGE)
                 self.__game.game_over = True
                 return True
     else:
         return False
Ejemplo n.º 5
0
 def test_no_winner_board_full(self):
     x_token = XToken()
     o_token = OToken()
     grid = Grid(3, 3)
     grid_controller = GridController()
     grid_controller.assign_grid(grid)
     grid.add_token_position(x_token, 0, 0)
     grid.add_token_position(x_token, 0, 1)
     grid.add_token_position(x_token, 1, 2)
     grid.add_token_position(x_token, 2, 0)
     grid.add_token_position(x_token, 2, 1)
     grid.add_token_position(o_token, 0, 2)
     grid.add_token_position(o_token, 1, 0)
     grid.add_token_position(o_token, 1, 1)
     grid.add_token_position(o_token, 2, 2)
     winner = grid_controller.check_for_win()
     assert winner is None
     assert grid_controller.grid_is_full()