Exemple #1
0
def test_correct_names_are_accepted():
    interface = TestInterface()
    interface.add_input_expectation('abc')
    interface.add_input_expectation('def')

    tictactoe = games.TicTacToe(interface)
    tictactoe.initialize()
    assert(tictactoe.players == ['abc', 'def'])
Exemple #2
0
def test_names_should_not_be_the_same():
    interface = TestInterface()
    interface.add_input_expectation('cat')
    interface.add_input_expectation('cat')
    interface.add_input_expectation('human')

    tictactoe = games.TicTacToe(interface)
    tictactoe.initialize()
    assert(tictactoe.players == ['cat', 'human'])
Exemple #3
0
def test_long_names_are_rejected():
    interface = TestInterface()
    interface.add_input_expectation('daenerys targaryen the unburnt')
    interface.add_input_expectation('daenerys')
    interface.add_input_expectation('ulfric stormcloak the bear of markath')
    interface.add_input_expectation('ulfric')

    tictactoe = games.TicTacToe(interface)
    tictactoe.initialize()
    assert(tictactoe.players == ['daenerys', 'ulfric'])
Exemple #4
0
def test_empty_name_should_be_repeated():
    interface = TestInterface()
    interface.add_input_expectation('')
    interface.add_input_expectation('abc')
    interface.add_input_expectation('')
    interface.add_input_expectation('def')

    tictactoe = games.TicTacToe(interface)
    tictactoe.initialize()
    assert(tictactoe.players == ['abc', 'def'])
Exemple #5
0
def buildGame(brd):
    #This function builds the game based off of the input.
    ttt = games.TicTacToe()
    gBoard, mv = buildBoard(brd)
    turn = findTurn(brd)
    util = checkForTerminal(brd, mv)
    my_state = games.GameState(to_move=turn,
                               utility=util,
                               board=gBoard,
                               moves=mv)
    return ttt, my_state
Exemple #6
0
def test_mcts():
    import games

    margin = 0.5
    tests = [([0, -1, 0, 0, 1, 0, 0, 0, 0, 1], 1),
             ([0, 1, 0, 0, -1, 0, 0, 0, 0, -1], -1),
             ([0, 0, 0, 0, 0, 0, 0, 0, 0, 1], 0)]

    for test in tests:
        state, score = test
        # TODO: Move this decoding state logic in games.py
        t = games.TicTacToe(board=state[:9], turn=state[-1])

        mcts = MCTS(t)

        for _ in range(1000):
            mcts.step()

        # forced white win
        mcts_score = mcts.root.avg_reward()
        assert abs(mcts_score -
                   score) < margin, f'got {mcts_score} want {score} pos: {t}'
Exemple #7
0
import games

game = games.TicTacToe()
state = game.initial

#print games.play_game(game, games.random_player, games.alphabeta_player)

player = 'X'

while True:
    print "Jugador a mover:", game.to_move(state)
    game.display(state)

    if player == 'O':
        coor_str = raw_input("Movimiento x,y: ")
        coor = str(coor_str).strip().split(",")
        x, y = int(coor[0]), int(coor[1])

        state = game.make_move((x, y), state)
        player = 'X'
    else:
        print "Thinking..."
        #move = games.minimax_decision(state, game)
        move = games.alphabeta_full_search(state, game)

        state = game.make_move(move, state)
        player = 'O'
    print "-------------------"
    if game.terminal_test(state):
        game.display(state)
        print "Final de la partida"
 def __init__(self, bot):
     self.tictac = games.TicTacToe()
     self.pokemon = Pokedex()
     self.bot = bot
     self.insult = Insults()
     self.names = {
         "walk": "walkstr8t",
         "soba": "cold..soba",
         "ella": "ellamenope",
         "child": "creature",
         "cweature": "creature",
         "kierkegaard": "creature",
         "wife-e": "macey",
         "wife": "macey",
         "meika_": "meika",
         "nabb-e": "nabbit",
         "shift": "makeshiftartist",
         "makeshift": "makeshiftartist",
         "d'arby": "darby",
         "kratos": "darby",
     }
     self.friends = {
         "defy": {
             "message": "f**k me",
             "reacts": ["👉", "👌"],
             "id": 625719520127877136,
         },
         "walkstr8t": {
             "message": "put on the cat ears",
             "reacts": [u"\U0001f43e"],
             "id": 456972240311943170,
         },
         "cesar": {
             "message": "Shut the f**k up",
             "reacts": ["<a:spinpikachu:796939118571421747>"],
             "id": 691099809720958980,
         },
         "cold..soba": {
             "message": "Put on the maid outfit ",
             "reacts": [u"\U0001f52b"],
             "id": 773690510698741760,
         },
         "creature": {
             "message": "lblblbllblblllbllbllblblbl",
             "reacts": [u"\U0000fe0f"],
             "id": 425665226721984514,
         },
         "macey": {
             "message": "*Gay screams*",
             "reacts": [u"\U0001F3F3\uFE0F\u200D\U0001F308"],
             "id": 756323850257563709,
         },
         "meika": {
             "message": "**pisses aggressively**",
             "reacts": ["<:doitagain:798790082009235476>"],
             "id": 527342369729806336,
         },
         "nabbit": {
             "message":
             "I'm fast. Faster than you. That's all you need to know",
             "reacts": [u"\U0001f344"],
             "id": 651244875915853825,
         },
         "ellamenope": {
             "message": "ily \U0001f642 hugs",
             "reacts": [u"\U0001f49c"],
             "id": 645783211955322961,
         },
         "makeshiftartist": {
             "message": "Your toes, hand 'em over",
             "reacts": [u"\U0001f608"],
             "id": 386839413935570954,
         },
         "darby": {
             "message":
             "Do that again and I'll f**k you \U0001f924\U0001f609",
             "reacts": [],
             "id": 670135524396367872,
         },
     }
Exemple #9
0
                turn = 'Computer'

            # Computer turn
            else:
                move = games.alphabeta_player(game, state)
                print('The ' + turn + ' made a move')

                # update the game state
                state = game.result(state, move)
                # game.display(state)
                turn = 'Player'

            if game.terminal_test(state):
                game.display(state)
                return


# decide who goes first


def firstMove():
    if random.randint(0, 1) == 0:
        return 'Computer'
    else:
        return 'Player'


if __name__ == "__main__":
    game = games.TicTacToe()  # create a new game object
    play_ttt(game)  # play the game
Exemple #10
0
#!/bin/python

import games

interface = games.TerminalInterface()
tictactoe = games.TicTacToe(interface)
tictactoe.play()