Beispiel #1
0
    async def accept(self, ctx, *args):
        #should be log
        print("accept read from", ctx.author)
        now = datetime.now()  #used to clear out old self.challenges

        #go through the challenges
        for idx in range(len(self.challenges)):
            challenge = self.challenges[idx]

            if (challenge[3] - now) > timedelta(minutes=15):
                print("challenge timed out")
                self.challenges.pop(idk)
                continue

            #first see if the challenge is the same channel as the accept
            if challenge[2] == ctx.channel:

                #if there is a game already in the channel, do not start another
                for game in self.ongoing_games:
                    if game.channel == ctx.channel:
                        return

                #see if the accepter is one of the people challenged
                for mention in challenge[0]:
                    if mention.id == ctx.author.id:
                        #see if accepter @'d someone, if not just accept first challenge
                        if (len(ctx.message.mentions)) == 0:
                            print("game start between ", ctx.author,
                                  challenge[1], "in channel", ctx.channel)
                            self.ongoing_games.append(
                                ChessGame(challenge[1], ctx.author,
                                          ctx.channel, challenge[4]))
                            await self.ongoing_games[-1].start_game()
                            self.challenges.pop(idx)
                            return
                        else:
                            #find the challenger who the accepter @'d
                            for mention2 in ctx.message.mentions:
                                if mention2.id == challenge[1]:
                                    print("@ game start between ", ctx.author,
                                          challenge[1], "in channel",
                                          ctx.channel)
                                    self.ongoing_games.append(
                                        ChessGame(challenge[1], ctx.author,
                                                  ctx.channel, challenge[4]))
                                    await self.ongoing_games[-1].start_game()
                                    self.challenges.pop(idx)
                                    return
Beispiel #2
0
    async def challenge(self, ctx, *args):
        #should be log
        print("challenge read from", ctx.author)
        #must challenge another user
        if len(args) == 0:
            return

        #cannot challenge everyone
        if not ctx.message.mention_everyone:
            #if the bot is being challenged start the game
            if ctx.bot.user in ctx.message.mentions:
                #check if game already in channel
                for g in self.ongoing_games:
                    if g.channel == ctx.channel:
                        return
                self.ongoing_games.append(
                    ChessGame(ctx.author, 0, ctx.channel, args[-1]))
                await self.ongoing_games[-1].start_game()
            else:
                now = datetime.now()
                try:
                    #Cannot challenge self, try to remove
                    self.challenges.append(
                        (ctx.message.mentions.remove(ctx.author), ctx.author,
                         ctx.channel, now, args[-1]))
                except:
                    self.challenges.append((ctx.message.mentions, ctx.author,
                                            ctx.channel, now, args[-1]))
Beispiel #3
0
 def setUp(self) -> None:
     self.player_turn = 1
     self.chess_game = ChessGame()
     self.chess_board = self.chess_game.board
     self.chess_game.player_turn = self.player_turn
     self.start_space = Vec2(5, 5)
     self.king = King(team=self.player_turn)
     self.knight = Knight(team=self.player_turn)
     self.pawn = Pawn(team=self.player_turn)
     self.enemy_pawn = Pawn(team=2)
     self.p1_pawn = Pawn(team=1)
Beispiel #4
0
 def precmd(self, line):
     # Maybe change later for better way to take things out of queue
     # Think about using try except
     while not self.data_streamer.challenges.empty():
         challenge = self.data_streamer.challenges.get()
         self.challenges[challenge['id']] = challenge
     while not self.data_streamer.games.empty():
         new_game, date = self.data_streamer.games.get()
         self.games[new_game['id']] = ChessGame(self.username, new_game,
                                                date)
     while not self.data_streamer.updates.empty():
         # update is tuple of (game_id, message)
         game_id, message, date = self.data_streamer.updates.get()
         if message['type'] == 'gameState':
             self.games[game_id].update_game(message, date)
     return line
Beispiel #5
0
def main():
    print("Welcome to our chess AI! Please select your difficulty:")
    print("Easy: 1")
    print("Medium: 2")
    print("Hard: 3")
    diff = input("")

    depth = 0
    if diff == "1":
        depth = 1
    elif diff == "2":
        depth = 2
    elif diff == "3":
        depth = 3

    demo_human_agent = HumanAgent(True)
    demo_opponent_agent = OrderedAgentTrans(False,
                                            combined,
                                            depth,
                                            load_hh=True)

    demo_game = ChessGame(demo_human_agent, demo_opponent_agent)
    demo_game.play_game(True)
Beispiel #6
0
 def transform(self, algebraic_moves):
     game = ChessGame()
     return ''.join(
         game.make_move_from_algebraic_and_return_uci(move)
         for move in algebraic_moves)
Beispiel #7
0
def main():

    game = ChessGame(setup_pieces=True)
    game.run()
Beispiel #8
0
def main():
    my_game = ChessGame(GreedyAgent, RandAgent)
    my_game.play_game()
Beispiel #9
0
def main():
    selected_game_mode = -1
    while (selected_game_mode < 0 or selected_game_mode > 3):
        print('Select game mode:')
        print('1. Normal chess')
        print('2. Reverse chess (suicide mode)')
        selected_game_mode = int(input('Selection: '))
        print('')

    selected_scenario = -1
    while (selected_scenario < 0 or selected_scenario > 7):
        print('Select game scenario:')
        print('1. Train AI')
        print('2. Watch trained AI vs trained AI')
        print('3. Watch trained AI vs normal AI')
        print('4. Watch normal AI vs normal AI')
        print('5. Play against trained AI')
        print('6. Play against normal AI')
        selected_scenario = int(input('Selection: '))

    # Select playing color if human vs ai
    selected_color = -1
    if (selected_scenario > 4 and selected_scenario <= 6):
        while (selected_color < 0 or selected_color > 3):
            print('Select Color:')
            print('1. White')
            print('2. Black')
            selected_color = int(input('Selection: '))

    game_variant = None
    if (selected_game_mode == 1):
        game_variant = 'chess'
    elif (selected_game_mode == 2):
        game_variant = 'suicide'
    else:
        raise Exception('Invalid game mode!')

    # Load train data if a scenario including 'trained AI' is selected
    # train_data = np.load('train_file.npy')

    # [1. Train AI]
    if (selected_scenario == 1):
        # todoooooooooooooooooooooooooo------------------------------------------
        pass
    else:
        white_player = None
        black_player = None
        # [2. Watch trained AI vs trained AI]
        if (selected_scenario == 2):
            white_player = AIPlayer(is_white=True,
                                    depth=3,
                                    piece_square_table=None)
            black_player = AIPlayer(is_white=False,
                                    depth=3,
                                    piece_square_table=None)
        # [3. Watch trained AI vs normal AI]
        elif (selected_scenario == 3):
            white_player = AIPlayer(is_white=True,
                                    depth=3,
                                    piece_square_table=None)
            black_player = AIPlayer(is_white=False,
                                    depth=3,
                                    piece_square_table=None)
        # [4. Watch normal AI vs normal AI]
        elif (selected_scenario == 4):
            white_player = AIPlayer(is_white=True,
                                    depth=3,
                                    piece_square_table=None)
            black_player = AIPlayer(is_white=False,
                                    depth=3,
                                    piece_square_table=None)
        # [5. Play against trained AI]
        elif (selected_scenario == 5):
            # [1. White]
            if (selected_color == 1):
                white_player = HumanPlayer(is_white=True)
                black_player = AIPlayer(is_white=False,
                                        depth=3,
                                        piece_square_table=None)
            # [2. Black]
            elif (selected_color == 2):
                white_player = AIPlayer(is_white=True,
                                        depth=3,
                                        piece_square_table=None)
                black_player = HumanPlayer(is_white=False)
            else:
                raise Exception('Invalid color!')
        # [6. Play against normal AI]
        elif (selected_scenario == 6):
            # [1. White]
            if (selected_color == 1):
                white_player = HumanPlayer(is_white=True)
                black_player = AIPlayer(is_white=False,
                                        depth=3,
                                        piece_square_table=None)
            # [2. Black]
            elif (selected_color == 2):
                white_player = AIPlayer(is_white=True,
                                        depth=3,
                                        piece_square_table=None)
                black_player = HumanPlayer(is_white=False)
            else:
                raise Exception('Invalid color!')
        else:
            raise Exception('Invalid scenario!')

        chess_game = ChessGame(white_player=white_player,
                               black_player=black_player,
                               variant=game_variant,
                               max_turn=None)

        gameover = False
        result = None
        while (not gameover):
            gameover, result = chess_game.play_half_turn()
        print(gameover)
        print(result)
Beispiel #10
0
from chess_game import ChessGame

_DEBUG = False

if __name__ == '__main__':
    my_game = ChessGame()
    my_game.run()
Beispiel #11
0
 def process_result_value(self, uci_moves_string, dialect):
     if isinstance(uci_moves_string, basestring):
         playable_game = ChessGame()
         return playable_game.make_moves_from_long_uci_string(
             uci_moves_string)
     return uci_moves_string
Beispiel #12
0
 def moves_list(self):
     return ChessGame().make_moves_from_long_uci_string(self.moves)