예제 #1
0
def player_selection_to_bot(selection):
    if selection == 1:
        return gofish.HumanController()
    elif selection == 2:
        return bots.RandomBot()
    elif selection == 3:
        return bots.BadBot()
    elif selection == 4:
        return bots.GoodBot(default_ask='random_high')
    elif selection == 5:
        return bots.GoodBot(default_ask='same_high')
    elif selection == 6:
        return bots.GoodBot(default_ask='random_all')
    raise ValueError('Incorrect Selection')
예제 #2
0
파일: main.py 프로젝트: petecog/OXbot
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Apr  3 07:23:14 2020

@author: terrylines
"""

import OX_short
import DP_bot
import bots
import MonteCarloEpsilonGreedy_bot

player1 = bots.RandomBot("Terry")
player2 = bots.RandomBot("Mikey")
player3 = bots.OXMasterBot("Peter")
player4 = DP_bot.OXDynamicProgrammingBot("Nick")
player5 = DP_bot.OXDynamicProgrammingBot("Rob")

# show that two random players get a zero avg scroe
scores2 = player2.play(Game=OX_short.OX,
                       reward=bots.marginReward,
                       opponents=[player1],
                       repeats=1)
sum(scores2) / 10000

# a simple tactic of taking centre gets an 0.2 avg score
scores3 = player3.play(Game=OX_short.OX,
                       reward=bots.marginReward,
                       opponents=[player1],
                       repeats=10000)
예제 #3
0
import gofish_env
import bots


replay_buffer_size = 20000
fc_layer_params = (256,64)
learning_rate = 5e-5
init_collection_steps = 10000
num_iterations = 100000
collect_steps_per_iteration = 1
log_interval = 100
eval_interval = 10000
num_eval_episodes = 100
train_reward_run_amount = 0.99

bot = bots.RandomBot()

memory_features = True
lose_on_illegal_move = False
drawless = False
conv_features = True

train_py_environment = gofish_env.GoFishEnv(bot, max_visible_opponent_hand_size=10, max_visible_deck_size=10, drawless=drawless, lose_on_illegal_move=lose_on_illegal_move, memory_features=memory_features, conv_features=conv_features)

print('Validating env.')
utils.validate_py_environment(train_py_environment, episodes=5)
print('Validation complete.')

eval_py_environment = gofish_env.GoFishEnv(bot, max_visible_opponent_hand_size=10, max_visible_deck_size=10, drawless=drawless, lose_on_illegal_move=lose_on_illegal_move, memory_features=memory_features, conv_features=conv_features)
train_env = tf_py_environment.TFPyEnvironment(train_py_environment)
eval_env = tf_py_environment.TFPyEnvironment(eval_py_environment)
예제 #4
0
def main(argv):

    if len(argv) == 1:
        print(
            'To play against bot or local, run binary with appropriate flags:')
        print('\tpython3 run_game.py bot')
        print('\tpython3 run_game.py remote SERVER_ADDRESS')

    window = pygame.display.set_mode((WIDTH, WIDTH))
    pygame.display.set_caption("Split")

    opponent = 'local' if len(argv) == 1 else argv[1]  # bot/local/remote

    if opponent == 'remote':
        host = argv[2]
        ui_state = UIState(
            window,
            players=[remote_play.RemotePlayer(host),
                     game.GamePlayer()])
        if ui_state.players[0].client_id == 0:
            temp_p = ui_state.players.pop(0)
            ui_state.players.append(temp_p)
    else:
        opponent_player = bots.RandomBot(
        ) if opponent == 'bot' else game.GamePlayer()
        ui_state = UIState(window,
                           players=[opponent_player,
                                    game.GamePlayer()])
        random.shuffle(ui_state.players)

    run = True

    while run:

        current_player = ui_state.players[ui_state.state.next_player - 1]
        other_player = ui_state.players[2 - ui_state.state.next_player]
        if not current_player.local_human:
            if ui_state.intro_state == 1:
                choice = current_player.choose_color(ui_state.state)
                ui_state.choose_color(choice)
                other_player.update_color_choice(choice)
            else:
                move = current_player.get_move(ui_state.state)
                ui_state.make_move(move)
                other_player.update_move(move)

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()

            # Reverse transform mouse
            mouse_position = pygame.mouse.get_pos()
            mouse_position = game.GamePoint(
                (mouse_position[0] - ui_state.pan[0]) / ui_state.zoom,
                (mouse_position[1] - ui_state.pan[1]) / ui_state.zoom)

            if ui_state.can_draw_fill():
                if event.type == pygame.MOUSEBUTTONDOWN:
                    if event.button == 4:
                        ui_state.zoom *= 1.5
                    elif event.button == 5:
                        ui_state.zoom /= 1.5
                    elif event.button == 3:
                        ui_state.cancel_move()
                    else:
                        ui_state.mouse_click(mouse_position)
                if event.type == pygame.MOUSEMOTION:
                    ui_state.mouse_move(mouse_position)
        keys = pygame.key.get_pressed()  #checking pressed keys
        if keys[pygame.K_w]:
            ui_state.pan[1] += 1
        if keys[pygame.K_a]:
            ui_state.pan[0] += 1
        if keys[pygame.K_s]:
            ui_state.pan[1] -= 1
        if keys[pygame.K_d]:
            ui_state.pan[0] -= 1
        if ui_state.can_choose_color():
            if keys[pygame.K_1]:
                ui_state.choose_color(True)
            if keys[pygame.K_2]:
                ui_state.choose_color(False)

        ui_state.render()
예제 #5
0
파일: main.py 프로젝트: atarist/AI-games
def test():
    p1 = bots.RandomBot(consts.X)
    p2 = bots.RandomBot(consts.O)
    game = TicTacToe(p1, p2)
    game.run(100000)