Exemple #1
0
    possible_board_states = [
        game.pretend_to_move_piece(move.oldLoc, move.newLoc)
        for move in possible_moves_lst
    ]

    possible_state_vecs = [
        state.get_alt_state_vec() for state in possible_board_states
    ]

    scores = [model.predict(vec)[0, 0] for vec in possible_state_vecs]

    return possible_moves_lst[max_index(scores)]


if __name__ == "__main__":
    while not game.is_game_over()[0]:
        if game.current_turn == 1:
            best_move = get_moves_computer(thing_1)

            game.move_piece(best_move.oldLoc, best_move.newLoc)
        else:

            if HUMAN_PLAYING:
                piece, move = get_moves_human()
                game.move_piece(piece, move)

            else:
                game.flip_board_nocopy()  # flip it for use

                best_move = get_moves_computer(thing_2)
            print("Iteration:", super_itr)
            thing1_data = []
            thing2_data = []

            for i in range(games_per_itr):  # play multiple games
                should_display_game_results = i == games_per_itr - 1
                game = CheckerBoard()
                game.scramble()
                thing1_state_vecs = []
                thing2_state_vecs = []

                # by flippping the board we switch teams but actually stay on team 1 according to the game object
                team_for_real = 1
                moves_taken = 0
                while not game.is_game_over()[0]:  # play 1 game

                    moves = game.get_all_possible_moves()

                    possible_moves_lst = []

                    for piece, possible_piece_moves in moves.items():
                        for possible_piece_move in possible_piece_moves:
                            possible_moves_lst.append(Move(piece, possible_piece_move))
                    random.shuffle(possible_moves_lst)

                    possible_board_states = [game.pretend_to_move_piece(move.oldLoc, move.newLoc) for move in
                                             possible_moves_lst]

                    possible_state_vecs = [state.get_alt_state_vec() for state in possible_board_states]