def calculate_moves(self, dices: Die, board) -> [(int, int)]: print("throw", dices) moves_options = generate_moves(self, Die(dices.first, dices.second), board) moves = [] if len(moves_options) > 0: moves = choice(moves_options) self.slow(board) return moves
def test_parallel_move_dark_checker_from_bar_in(self): self.game.board.board = self.game.board.clear_board() self.game.board.place_at(0, self.black.color, 1) print(self.game.board) moves = generate_moves(self.black, Die(2, 3), self.game.board) expected_moves = [[(0, 22), (22, 20)], [(0, 23), (23, 20)]] pprint.pprint(moves) self.assertEqual(moves, expected_moves)
def calculate_moves(self, dices: Die, board) -> [(int, int)]: print("throw", dices) moves_options = generate_moves(self, Die(dices.first, dices.second), board) if len(moves_options) == 0: return moves_options future_boards = self.get_future_boards(moves_options, board) node_data = [self.mapper.to_nodes(b, self.color) for b in future_boards] win_chance_white: [float] = self.ai.predict(node_data) extreme = max(win_chance_white) if self.color == Checker.BLACK: extreme = min(win_chance_white) return moves_options[win_chance_white.index(extreme)]
def calculate_moves(self, dices: Die, board) -> [(int, int)]: self.items[Items.CURRENT_PLAYER_NAME].set(self.name) self.items[Items.CURRENT_PLAYER] = self self.items[Items.CURRENT_DIE].set(str(dices.get_roll())) self.uiBoard.draw_game_state(board) possible_moves = generate_moves(self, dices, board) moves = [] if possible_moves: for i in range(len(possible_moves[0])): self.items[Items.NEXT_PLAYER_BUTTON].wait_variable( self.items[Items.PLACED_CHECKER]) moves.append(self.items[Items.LATEST_MOVE]) print(self.items[Items.LATEST_MOVE]) self.items[Items.PLACED_CHECKER].set(0) print(moves) if any(t < 0 for _, t in moves): moves = self.map_out_moves(moves, possible_moves) return moves
def test_move_white_checker_from_bar_in(self): self.game.board.board = self.game.board.clear_board() self.game.board.place_at(0, self.white.color, 1) moves = generate_moves(self.white, Die(2, 3), self.game.board) expected_moves = [[(0, 22), (22, 20)], [(0, 23), (23, 20)]] self.assertEqual(moves, expected_moves)
def test_move_generator_one_and_two_and_one_out_black(self): self.game.board.remove_from(19) self.game.board.place_at(0, self.black.color) pprint.pprint(generate_moves(self.black, Die(1, 2), self.game.board))
def test_move_generator(self): self.game.board.board = self.game.board.clear_board() self.game.board.place_at(23, self.white.color, 2) pprint.pprint(generate_moves(self.white, Die(4, 6), self.game.board))
def test_move_generator_five_six_in_home_one_out(self): self.fill_home() self.game.board.place_at(0, self.white.color) moves = generate_moves(self.white, Die(5, 6), self.game.board) pprint.pprint(moves) self.assertEqual(len(moves), 3)
def test_move_generator_double_six_black(self): pprint.pprint(generate_moves(self.black, Die(6, 6), self.game.board))
def test_move_generator_one_and_two_one_not_in_home(self): self.fill_home() self.game.board.place_at(7, self.white.color) pprint.pprint(self.game.board) pprint.pprint(generate_moves(self.white, Die(5, 6), self.game.board))
def test_move_generator_one_and_two(self): pprint.pprint(generate_moves(self.white, Die(2, 3), self.game.board))
def test_move_generator_double_three(self): pprint.pprint(generate_moves(self.white, Die(3, 3), self.game.board))
def test_move_generator_double_two(self): pprint.pprint(generate_moves(self.white, Die(2, 2), self.game.board))
def test_move_generator_double_six(self): pprint.pprint(generate_moves(self.white, Die(6, 6), self.game.board))