def play_games():
    won_games = []
    with tf.name_scope('play_game'):
        for _ in range(ITTERCOUNT):
            #generate new game
            game = TicTac(net=True, rand=True)

            # Get board state as flat vector
            inputs = list(game.boards[0])
            inputs.extend(game.boards[1])

            res = sess.run(results, feed_dict={x: [inputs]})

            while game.winner == False:
                game.visual()
                game.doturn(netvals=res[0])
                game.winner = game.check_win()
            if game.history[0] == 'X':
                #learn the last two moves
                won_games.append(game.history[1:])
        #take winning games and build training data
        print(len(won_games))
        for game in won_games:
            for move in game:
                inputvals.append(move[0])
                targetvals.append(vote_for(move[1]))
        print(len(won_games) / float(ITTERCOUNT))
Example #2
0
def main():
    print("Welcome to Tic Tac Toe")
    game = TicTac()
    game.print()
    while True:
        game.player_turn()
        game.cats()
        game.find_win()
        if game.cats() or game.find_win():
            break
        game.computer_turn()
        game.cats()
        game.find_win()
        if game.cats() or game.find_win():
            break
Example #3
0
        t1.bclick(int(data))

    # example of an action
    # action: notify
    async def notify_users(self):
        '''notify the number of current connected clients'''
        if self.USERS:  # asyncio.wait doesn't accept an empty list
            message = json.dumps({'type': 'users', 'count': len(self.USERS)})
            await asyncio.wait([user.send(message) for user in self.USERS])

    # action: action
    async def action(self, cnt):
        '''this is an action which will be executed when user presses on button'''
        print(cnt)
        if self.USERS:  # asyncio.wait doesn't accept an empty list
            message = str(cnt)
            await asyncio.wait([user.send(message) for user in self.USERS])

    # expose action
    def do_activate(self, cnt):
        '''this method is exposed to outside, not an async coroutine'''
        # use asyncio to run action
        # must call self.action(), not use self.action, because it must be a async coroutine
        asyncio.get_event_loop().run_until_complete(self.action(cnt))


threadWebSocket = WebSocketThread("websocket_server")
threadWebSocket.start()
t1 = TicTac(threadob=threadWebSocket)
t1.root.mainloop()