Exemplo n.º 1
0
 def choose_action(self, board: Board):
     while True:
         print(board.pretty())
         row = input('Row: ')
         col = input('Col: ')
         try:
             board.pick((int(row) - 1, int(col) - 1))
             break
         except ValueError:
             print(f'Bad action: {row, col}. Try again.')
             pass
Exemplo n.º 2
0
 def test_pick_removes_cell(self):
     board = Board(2, 2)
     self.assertEqual(4, len(board.available_actions()))
     board.pick((1, 1))
     self.assertEqual(3, len(board.available_actions()))
     board.pick((1, 0))
     self.assertEqual(2, len(board.available_actions()))
     board.pick((0, 1))
     self.assertEqual(1, len(board.available_actions()))
Exemplo n.º 3
0
 def test_pick_shrinks_list_when_whole_row_is_picked(self):
     board = Board(4, 1)
     self.assertEqual(4, len(board._grid))
     board.pick((2, 0))
     self.assertEqual(2, len(board._grid))
Exemplo n.º 4
0
 def test_pick_same_cell_throws(self):
     board = Board(2, 2)
     board.pick((1, 1))
     with self.assertRaisesRegex(ValueError, 'Invalid action'):
         board.pick((1, 1))
Exemplo n.º 5
0
 def choose_action(self, board: Board):
     action = self.agent.choose_action(
         board.available_actions(),
         lambda x: self._copy_board_and_get_new_hash(x, board)
     )
     board.pick(action)