def setUpClass(cls) -> None:
     cls.input_board = '                ' \
                       '                ' \
                       'ppppppp         ' \
                       '                ' \
                       '                ' \
                       '                ' \
                       '       p        ' \
                       '                ' \
                       '                ' \
                       '       P        ' \
                       '                ' \
                       '                ' \
                       '                ' \
                       'PPPPPPP         ' \
                       '                ' \
                       '                '
     cls.opponent = 'test_opponent'
     cls.board_id = 'abcde12345'
     cls.color = 'white'
     ConfigManager({})
     ConfigManager.set('username', 'test_player')
     cls.server = MockServerAdapter()
     cls.strategy = MockAIStrategy()
Exemple #2
0
 async def cli_listener(self):
     while True:
         try:
             msg = self.cli_commands.get_nowait()
             command = msg.split(' ')
             if command[0] == 'users':
                 await self.server.send('get_connected_users', {})
             elif len(command) >= 2 and command[0] == 'challenge':
                 if len(command) > 2:
                     await self.server.send(
                         'challenge',
                         {
                             'username': command[1],
                             'message': command[2:],
                         }
                     )
                 else:
                     await self.server.send(
                         'challenge',
                         {'username': command[1]}
                     )
             elif command[0] == 'randomchallenge':
                 await self.server.send(
                     'challenge',
                     {
                         'username': self.user_list[randint(0, len(self.user_list)-1)],
                     }
                 )
             elif len(command) == 2 and command[0] == 'auto-accept':
                 if command[1] == 'on':
                     ConfigManager.set('accept_challenges', True)
                 elif command[1] == 'off':
                     ConfigManager.set('accept_challenges', False)
             elif command[0] == 'quit':
                 asyncio.get_event_loop().stop()
             elif command[0] == 'abort' and len(command) == 2:
                 await self.server.send('abort', {'board_id': command[1]})
             elif command[0] == 'config' and len(command) == 3:
                 value = command[2]
                 if value.isdigit():
                     value = int(value)
                 elif value.lower() in ['true', 'on']:
                     value = True
                 elif value.lower() in ['false', 'off']:
                     value = False
                 ConfigManager.set(command[1], value)
         except queue.Empty:
             await asyncio.sleep(0.5)