Esempio n. 1
0
def main():
    player1 = None
    player2 = None
    player1Type = util.get_arg(1)
    player2Type = util.get_arg(2)

    if player1Type == None or player2Type == None:
        print('Invalid use of connect3 game')
        return

    if player1Type == 'human':
        player1 = HumanPlayer('X')
    elif player1Type == 'random':
        player1 = RandomPlayer('X')
    elif player1Type == 'minimax':
        player1 = MinimaxPlayer('X')

    if player2Type == 'human':
        player2 = HumanPlayer('O')
    elif player2Type == 'random':
        player2 = RandomPlayer('O')
    elif player2Type == 'minimax':
        player2 = MinimaxPlayer('O')

    game = Game(player1, player2)
    winner = game.play()
    print('Winner:', winner)
Esempio n. 2
0
def make_player(p: str = "", c: str = ""):
    if p[0] == "h":
        return HumanPlayer(c)
    if p[0] == "r":
        return RandomPlayer(c)
    if p[0] == "m":
        return MinimaxPlayer(c)
    print("Please enter a valid player string: [human, random, minimax]")
    exit()
Esempio n. 3
0
from ai import AiPlayer
from human import HumanPlayer

# Initialize pygame and make the window. #
pygame.init()
pygame.display.set_caption('Durak!')
screen = pygame.display.set_mode(utils.SCREEN_SIZE)

deck = utils.get_deck_array(None)
trump_card = deck.pop(0)
trump_suit = trump_card.suit

deck = utils.get_deck_array(trump_card)
discard = []

players = [HumanPlayer(), AiPlayer()]
currentStarterIndex = random.randrange(0, 2)
currentPlayerIndex = currentStarterIndex

# Deal the cards. #
for index in range(0, 12):
    if index % 2 == 0:
        players[0].hand.append(deck.pop(index))
    else:
        players[1].hand.append(deck.pop(index))

attackingCard = None
cardsInPlay = []

turnInit = False
turnComplete = False
from board import Board, GameResult
from agent import Agent
from human import HumanPlayer

# p1 = Agent("p1")
# p2 = Agent("p2")

# st = Board(p1, p2)
# print("training...")
# st.simulation(50000)

# p1.savePolicy()
# p2.savePolicy()

p1 = Agent("computer", q_init=0)
p1.loadPolicy("policy_p1")

p2 = HumanPlayer("human")

st = Board(p1, p2)
st.play2()
Esempio n. 5
0
#-open log files for storing player moves
now = time.time()
try:
    filename = Constants.GAME_LOG_PATH + 'p1-log-%d.dat' % now
    p1log = open( filename, 'w' )
    filename = Constants.GAME_LOG_PATH + 'p2-log-%d.dat' % now
    p2log = open( filename, 'w' )
except IOError as iox:
    print 'error opening player log file [' + filename + ']: ' + str( iox )
    sys.exit()
#-initialise player objects
#player1 = Player( 1 )
#player1 = RandomPlayer( 1 )
player1 = NNPlayer( 1, Constants.TRAINED_NN_PATH + 'player1-weights.txt', p1log )
# player2 = NNPlayer( 2, Constants.TRAINED_NN_PATH + 'nn-online-steps1000.2', p2log )
player2 = HumanPlayer( 2 )
#-mark cells in arena where each player starts
arena[XSTART1][YSTART1] = True
arena[XSTART2][YSTART2] = True
#-initialise matplotlib figure for displaying animation
fig = plt.figure()
fig.hold( True )
fig.gca().set_xlim( Constants.XMIN, Constants.XMAX )
fig.gca().set_ylim( Constants.YMIN, Constants.YMAX )
fig.gca().set_xticklabels( '' )
fig.gca().set_yticklabels( '' )
fig.gca().set_axis_bgcolor( 'k' )
#-initialise event handler to be called on "key release" events
if ( player1.mode == "human" ):
    cid = fig.canvas.mpl_connect( 'key_release_event', player1.on_key )
if ( player2.mode == "human" ):
Esempio n. 6
0
# -*- coding: utf-8 -*-

from human import HumanPlayer
from bord import Board
import numpy as np
import chainerrl
from dqn import QFunctions
import chainer
from randomAct import RandomActor

human_player = HumanPlayer()
b = Board()
ra = RandomActor(b)


# 環境の次元数
obs_size = 9
# 行動の次元数
n_actions = 9
q_func = QFunctions(obs_size,n_actions)
optimizer = chainer.optimizers.Adam(eps=1e-2)
optimizer.setup(q_func)

# 報酬の割引率
gamma = 0.95
# epsilon-greedyを使ってたまに冒険
explorer = chainerrl.explorers.LinearDecayEpsilonGreedy(
    start_epsilon=1.0, end_epsilon=0.3, decay_steps=50000, random_action_func=ra.random_action
)
replay_buffer = chainerrl.replay_buffer.ReplayBuffer(capacity=10**6)
# agentの生成
Esempio n. 7
0
 def human_player(self):
     player = HumanPlayer()
     return player