コード例 #1
0
def api_basic_agent_reset(game_type):

    global basic_gs
    basic_gs = TicTacToeGameState()

    data = {"status": 200, "message": "Game State reseted", "game": "basic"}
    return jsonify(data)
コード例 #2
0
from agents import QuantumAgent, QuantumGroverAgent
from environments.tictactoe import TicTacToeGameState
from runners import run_to_the_end

if __name__ == "__main__":
    gs = TicTacToeGameState()
    agent0 = QuantumAgent()
    agent1 = QuantumGroverAgent()

    print(gs)
    run_to_the_end([agent0, agent1], gs)
    print(gs)
コード例 #3
0
from agents import CommandLineAgent, DeepQLearningAgent, DDQNAgentWithPER
from environments.tictactoe import TicTacToeGameState
from runners import run_for_n_games_and_print_stats, run_step

if __name__ == "__main__":
    gs = TicTacToeGameState()
    agent0 = DeepQLearningAgent(action_space_size=gs.get_action_space_size(), neurons_per_hidden_layer=128,
                                hidden_layers=5)
    agent1 = DDQNAgentWithPER(action_space_size=gs.get_action_space_size(), neurons_per_hidden_layer=128,
                                hidden_layers=5)
    agent0.alpha = 0.1
    agent0.epsilon = 0.005
    agent1.alpha = 0.1
    agent1.epsilon = 0.005

    for i in range(100):
        run_for_n_games_and_print_stats([agent0, agent1], gs, 1000)

    agent0.epsilon = -1.0
    agent1.epsilon = -1.0
    run_for_n_games_and_print_stats([agent0, agent1], gs, 100)

    gs_clone = gs.clone()
    while not gs_clone.is_game_over():
        run_step([agent0, CommandLineAgent()], gs_clone)
        print(gs_clone)

    gs_clone = gs.clone()
    while not gs_clone.is_game_over():
        run_step([CommandLineAgent(), agent1], gs_clone)
        print(gs_clone)
from agents import CommandLineAgent, DeepQLearningAgent, PPOAgent, RandomAgent
from environments.tictactoe import TicTacToeGameState
from runners import run_for_n_games_and_print_stats, run_step

if __name__ == "__main__":
    gs = TicTacToeGameState()
    agent0 = PPOAgent(state_space_size=gs.get_vectorized_state().shape[0],
                      action_space_size=gs.get_action_space_size())
    agent1 = RandomAgent()

    for i in range(100):
        run_for_n_games_and_print_stats([agent0, agent1], gs, 5000)

    run_for_n_games_and_print_stats([agent0, agent1], gs, 100)

    gs_clone = gs.clone()
    while not gs_clone.is_game_over():
        run_step([agent0, CommandLineAgent()], gs_clone)
        print(gs_clone)

    gs_clone = gs.clone()
    while not gs_clone.is_game_over():
        run_step([CommandLineAgent(), agent1], gs_clone)
        print(gs_clone)
from agents import CommandLineAgent, DeepQLearningAgent
from environments.tictactoe import TicTacToeGameState
from runners import run_for_n_games_and_print_stats, run_step

if __name__ == "__main__":
    gs = TicTacToeGameState()
    agent0 = DeepQLearningAgent(action_space_size=gs.get_action_space_size())
    agent1 = DeepQLearningAgent(action_space_size=gs.get_action_space_size())
    agent0.alpha = 0.1
    agent0.epsilon = 0.005
    agent1.alpha = 0.1
    agent1.epsilon = 0.005

    for i in range(100):
        run_for_n_games_and_print_stats([agent0, agent1], gs, 5)

    agent0.epsilon = -1.0
    agent1.epsilon = -1.0
    run_for_n_games_and_print_stats([agent0, agent1], gs, 100)

    gs_clone = gs.clone()
    while not gs_clone.is_game_over():
        run_step([agent0, CommandLineAgent()], gs_clone)
        print(gs_clone)

    gs_clone = gs.clone()
    while not gs_clone.is_game_over():
        run_step([CommandLineAgent(), agent1], gs_clone)
        print(gs_clone)
from agents import RandomRolloutAgent, MOMCTSAgent, RandomAgent, HalfAlphaZeroAgent
from environments.tictactoe import TicTacToeGameState
from runners import run_to_the_end, run_for_n_games_and_print_stats

if __name__ == "__main__":

    import tensorflow as tf

    tf.compat.v1.disable_eager_execution()

    gs = TicTacToeGameState()
    agent0 = HalfAlphaZeroAgent(10, gs.get_action_space_size(), keep_memory=True)
    agent1 = RandomAgent()

    for _ in range(1000):
        run_for_n_games_and_print_stats([agent0, agent1], gs, 100, shuffle_players=True)
from agents import RandomRolloutAgent, MOMCTSAgent, RandomAgent, ExpertApprenticeAgent
from environments.tictactoe import TicTacToeGameState
from runners import run_to_the_end, run_for_n_games_and_print_stats

if __name__ == "__main__":

    import tensorflow as tf

    tf.compat.v1.disable_eager_execution()
    gs = TicTacToeGameState()
    agent0 = ExpertApprenticeAgent(100, gs.get_action_space_size())
    agent1 = RandomAgent()

    for _ in range(1000):
        run_for_n_games_and_print_stats([agent0, agent1], gs, 1000)
from agents import TabQLearningAgent, CommandLineAgent, RandomAgent
from environments.tictactoe import TicTacToeGameState
from runners import run_for_n_games_and_print_stats, run_step

if __name__ == "__main__":
    gs = TicTacToeGameState()
    agent0 = TabQLearningAgent()
    agent1 = TabQLearningAgent()
    agent0.alpha = 0.1
    agent0.epsilon = 0.005
    agent1.alpha = 0.1
    agent1.epsilon = 0.005

    for _ in range(100):
        run_for_n_games_and_print_stats([agent0, agent1], gs, 5000)

    agent0.epsilon = -1.0
    agent1.epsilon = -1.0
    run_for_n_games_and_print_stats([agent0, agent1], gs, 100)

    gs_clone = gs.clone()
    while not gs_clone.is_game_over():
        run_step([agent0, CommandLineAgent()], gs_clone)
        print(gs_clone)

    gs_clone = gs.clone()
    while not gs_clone.is_game_over():
        run_step([CommandLineAgent(), agent1], gs_clone)
        print(gs_clone)
コード例 #9
0
from flask import Flask, render_template, jsonify, request
from runners import run_step
from agents import CommandLineAgent, QuantumAgent, WebAgent, QuantumGroverAgent
from environments.tictactoe import TicTacToeGameState
from runners import run_to_the_end

app = Flask(__name__, template_folder='static')

player_agent = WebAgent()
basic_agent = QuantumAgent()
grover_agent = QuantumGroverAgent()

basic_gs = TicTacToeGameState()
grover_gs = TicTacToeGameState()

# OLD SYNCHRONOUS CODE
# run_to_the_end([player_agent, basic_agent], basic_gs)
# run_to_the_end([player_agent, grover_agent], grover_gs)


######## FAST WEB ROOTING ##########
@app.route('/basic')
def basic_index():
    data = {"title": "Basic Agent", "game": "basic"}
    return render_template('html/index.html', data=data)


@app.route('/grover')
def grover_index():
    data = {"title": "Grover Agent", "game": "grover"}
    return render_template('html/index.html', data=data)