def evaluate(individual):
    def cuanteti_heuristic(agent, game, depth):
        square_value = {'X': 1, 'O': -1, '.': 0}
        square_factors = individual
        board_value = sum([square_value[s] * p for s, p in
                           zip(game.board, square_factors)])

        return board_value if agent.player == 'Xs' else -board_value

    # Amount of matches played as 'X' and as 'O'.
    matches = 50
    wins = 0
    agent1 = MiniMaxAgent(heuristic=cuanteti_heuristic)
    agent2 = RandomAgent()

    for i in range(matches):
        result = run_match(Cuanteti(), agent1, agent2)
        if result[0]['Xs'] > 0:
            wins += 1

    for i in range(matches):
        result = run_match(Cuanteti(), agent2, agent1)
        if result[0]['Os'] > 0:
            wins += 1

    return wins,
def run_test(agent1, agent2, matches=1000):
    """
    Test a heuristic function as agent1 against an agent2.
    """
    wins = 0
    draws = 0
    loses = 0

    for i in range(matches):
        result = run_match(Cuanteti(), agent1, agent2)[0]['Xs']

        if result > 0:
            wins += 1
        elif result == 0:
            draws += 1
        else:
            loses += 1

    for i in range(matches):
        result = run_match(Cuanteti(), agent2, agent1)[0]['Os']
        if result > 0:
            wins += 1
        elif result == 0:
            draws += 1
        else:
            loses += 1

    return wins, loses, draws
Example #3
0
def run_test_game(agent1=None, agent2=None):
    if not agent1:
        from adversarial_search.agents.mcts import MCTSAgent
        agent1 = MCTSAgent('Computer', simulation_count=10)
    if not agent2:
        from adversarial_search.agents.files import FileAgent
        agent2 = FileAgent(name='Human')
    from adversarial_search.core import run_match
    run_match(Cuanteti(), agent1, agent2)
Example #4
0
def run_test_game(agent1=None, agent2=None):
    if not agent1:
        from adversarial_search.agents.minimax import MiniMaxAgent
        agent1 = MiniMaxAgent('Computer', 3, heuristic=TicTacToe.simple_heuristic)
    if not agent2:
        from adversarial_search.agents.files import FileAgent
        agent2 = FileAgent(name='Human')
    from adversarial_search.core import run_match
    run_match(TicTacToe(), agent1, agent2)
def run_test_game(agent1=None, agent2=None):
    if not agent1:
        from adversarial_search.agents.random import RandomAgent
        agent1 = RandomAgent(name='Computer')
    if not agent2:
        from adversarial_search.agents.files import FileAgent
        agent2 = FileAgent(name='Human')
    from adversarial_search.core import run_match
    run_match(ToadsFrogs(None, 0, 5, 4), agent1, agent2)