Beispiel #1
0
    def put(token, x, y):
        if token.upper() != game.token:
            return "you cant, you are {}".format(game.token)

        x = x.replace("a", "1")
        x = x.replace("b", "2")
        x = x.replace("c", "3")
        x, y = int(x)-1, int(y)-1
        b = game.board
        try:
            if b[x][y] != "_":
                return "its already occupied"
            b[x][y] = game.token
            print("done")
        except Exception:
            return "are you mad?"

        if logic.who_wins(b) != "_" or logic.is_full(b):
            game_over()
            return ""
        print("ia is playing")
        ix, iy = logic.dumb_ia_turn(game.board, x, y, "X")
        if not ix is None:
            b[ix][iy] = game.token == "X" and "O" or "X"
        print("done")
        if logic.who_wins(b) != "_" or logic.is_full(b):
            game_over()
            return ""
        return "now its your turn"
Beispiel #2
0
    def put(token, x, y):
        if token.upper() != game.token:
            return "you cant, you are {}".format(game.token)

        x = x.replace("a", "1")
        x = x.replace("b", "2")
        x = x.replace("c", "3")
        x, y = int(x) - 1, int(y) - 1
        b = game.board
        try:
            if b[x][y] != "_":
                return "its already occupied"
            b[x][y] = game.token
            print("done")
        except Exception:
            return "are you mad?"

        if logic.who_wins(b) != "_" or logic.is_full(b):
            game_over()
            return ""
        print("ia is playing")
        ix, iy = logic.dumb_ia_turn(game.board, x, y, "X")
        if not ix is None:
            b[ix][iy] = game.token == "X" and "O" or "X"
        print("done")
        if logic.who_wins(b) != "_" or logic.is_full(b):
            game_over()
            return ""
        return "now its your turn"
Beispiel #3
0
 def game_over():
     print("game over")
     winner = logic.who_wins(game.board)
     if winner == "_":
         storage_increment("draw")
         print("nobody win")
         print("its a draw")
     elif winner == game.token:
         storage_increment("win")
         print("{} wins".format(winner))
         print("you win")
     else:
         storage_increment("lost")
         print("{} wins".format(winner))
         print("you lose")
     game.context = "lobby"
Beispiel #4
0
 def game_over():
     print("game over")
     winner = logic.who_wins(game.board)
     if winner == "_":
         storage_increment("draw")
         print("nobody win")
         print("its a draw")
     elif winner == game.token:
         storage_increment("win")
         print("{} wins".format(winner))
         print("you win")
     else:
         storage_increment("lost")
         print("{} wins".format(winner))
         print("you lose")
     game.context = "lobby"