Пример #1
0
    def do_ttt(self, inp):
        """ /ttt <username> <x> <y> """
        inp = inp.split(' ')
        try:
            clientname = inp.pop(0)
            client = clients[clientname]
            if not client:
                self.send_msg("user not connected", [self])
                return
            x = int(inp.pop(0))
            y = int(inp.pop(0))
            if not (  0 <= x <= 2 and  0 <= x <= 2):
                self.send_msg("wrong position", [self])
                return
        except:
            self.send_msg("wrong entry", [self])

        # init game
        if self.ttt is None or self.ttt[1] != client:
            game = TicTacToe()
            self.ttt = (game, client)
            client.ttt = (game, self)
        else:
            game = self.ttt[0]

        if game.play(x, y):
            self.send_msg("\n" + game.__str__(), [client, self])
            if game.winner is not None:
                self.send_msg(f"{self.username} won", [client, self])
                self.ttt = None
            else:
                self.send_msg(f"[TTT] do /ttt {self.username} <x> <y>", [client])
        else:
            self.send_msg(f"Invalid pos {x} {y} \n" + game.__str__(), [self])
from ttt import TicTacToe,AutoPlayer,HumanPlayer
from pprint import pprint
import operator



game = TicTacToe()

a1 = AutoPlayer(symb=1,greedy=True)
a2 = AutoPlayer(symb=2,epsilon=0.2,step_size=0.4)
h1 = HumanPlayer(symb=1)

game.play(a1,a2,iter=40000)

a1.setGreedy(False)
a1.setEpsilon(0.1)
a2.setStepSize(0.2)
game.play(a1,a2,iter=40000)

a1.setGreedy(True)
a2.setStepSize(0.1)
game.play(a1,a2,iter=40000)

#print('---- LIVE GAME ------')
game.reset_board()
a2.setGreedy(True)
game.play(h1, a2, iter=1, stats=False, printBoard=True)