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) moves = [] if len(moves_options) > 0: moves = choice(moves_options) self.slow(board) return moves
def test_two_out_can_move_only_one(self): self.game.board.board = self.game.board.clear_board() self.game.board.place_at(0, self.black.color, 1) self.game.board.place_at(0, self.black.color, 1) self.game.board.place_at(19, self.white.color, 1) self.game.board.place_at(19, self.white.color, 1) moves = generate_moves_serial(self.black, Die(2, 6), self.game.board) expected_moves = [[(0, 23)]] self.assertEqual(moves, expected_moves)
def test_black_move_out(self): rand_black = RandomPlayer(Checker.BLACK) human_white = RandomPlayer(Checker.WHITE) game = Game(player_1=human_white, player_2=rand_black, create_protocol=False) game.board.board = game.board.clear_board() game.current_player = rand_black game.current_dice = Die(4, 6) game.board.place_at(19, Checker.BLACK, 1) game.board.place_at(22, Checker.BLACK, 1) game.board.place_at(18, Checker.WHITE, 4) game.run() moves = generate_moves_serial(self.black, Die(4, 6), game.board.get_view(True)) print(moves)
def test_black_move_out_4(self): self.game.board.board = self.game.board.clear_board() self.game.board.place_at(22, self.black.color, 4) self.game.board.place_at(21, self.black.color, 2) self.game.current_player = self.black self.game.board.place_at(23, self.white.color, 6) moves = generate_moves_serial(self.black, Die(4, 4), self.game.board.get_view(True)) moves = gui.HumanPlayer.map_out_moves([(3, 0), (4, 0), (3, 0), (4, 0)], moves) expected_moves = [(3, -1), (3, -1), (4, 0), (4, 0)] self.assertEqual(sorted(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 readProtocol(self): lines = self.protocol_file.readlines() count = 0 # Strips the newline character for line in lines: count += 1 line = line.strip() if len(line) < 4: # to short for further checks continue # if line[0] == ';' or not line[0].isdigit() or 'match' in line: # continue if not (line[0].isdigit() and line[1] == ')') \ and not (line[0].isdigit() and line[1].isdigit() and line[2] == ')') \ and not (line[0].isdigit() and line[1].isdigit() and line[2].isdigit() and line[3] == ')'): continue protocol_logger.debug("Line{}: {}".format(count, line.strip())) # delete turn number # print(line) line = (line.split(")")[1]).strip() # split by space # example line : 63: 25/22 22/16 64: 21/15 15/11 lineElements = line.split(" ") die = None turn = [] moves = [] got_dices = False for element in lineElements: if ":" in element: if len(moves) != 0 or got_dices: tempturn = Turn(die, moves) self.game_proto.append(tempturn) moves = [] die = None got_dices = False element = element.replace(":", "").strip() die = Die(element[0], element[1]) got_dices = True elif "/" in element: # print(str(element.split("/")[0])) src = int(((element.split("/"))[0]).replace('*', '').strip()) trg = int(((element.split("/"))[1]).replace('*', '').strip()) moves.append(Move(src, trg)) if len(moves) != 0 or got_dices: self.game_proto.append(Turn(die, moves))
def test_move_checkers_invalid_checker_fail(self): self.game.current_dice = Die(1, 4) pprint(self.game.board.board) self.assertRaises(ValueError, lambda: game_moves_are_valid(self.white, [(13, 14), (12, 8)], self.game))
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_checkers_from_valid_to_valid_with_no_items_out_and_not_in_home_success(self): self.game.current_dice = Die(3, 4) print(self.game.board) self.assertIsNone(game_moves_are_valid(self.black, [(13, 9), (13, 10)], self.game))
def test_move_checkers_from_valid_to_invalid_target_location_with_no_items_out_and_not_in_home_fail(self): self.game.current_dice = Die(1, 4) self.assertRaises(ValueError, lambda: game_moves_are_valid(self.black, [(13, 12), (13, 9)], self.game))
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))
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_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_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_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_double_six_black(self): pprint.pprint(generate_moves(self.black, Die(6, 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)