Esempio n. 1
0
 def delegate_decision_to_the_algorithm(self, message):
     message = json.dumps(message)
     self.send_message_to_algorithm(message)
     response = run_with_time_limit(self.timeout, self.receive_message_from_algorithm)
     if response:
         response = json.loads(response)
         error = response.get('error', None)
         if error:
             raise AlgorithmError('Algorithm error: %s' % error)
         else:
             return self.process_response(response)
Esempio n. 2
0
 def save_command(self, command):
     command.read_context(self)
     self.log(command.pretty_log(), logging.INFO)
     # take a snapshot of the object to avoid the original be modified
     self.commands.append(json.loads(json.dumps(command.replay_data())))
Esempio n. 3
0
 def printable_data(self, data):
     if GATLogger.is_verbose():
         return json.dumps(data, sort_keys=True, indent=2 * ' ')
     else:
         return json.dumps(data, sort_keys=True)
Esempio n. 4
0
 def __str__(self):
     data = self.replay_data()
     return json.dumps(data, sort_keys=True)
Esempio n. 5
0
 def test_gat_player_must_be_serializable(self):
     result = json.dumps(StubGATPlayer(['python',  'x']))
     self.assertEquals('{}', result)
print('Client connected.')

def send_message(message):
    if sys.version_info[0] == 2:
        conn.sendall(message)
    else:
        conn.sendall(bytes(message, 'utf-8'))

while True:
    try:
        # print('\nWaiting for request')
        message = conn.recv(8192) # 2**13
        if not message or message == 'stop':
            break
        # print('\nRequest received: %s' % json.loads(message))
        message = json.loads(message)

        # print('Context %s' % message['context'])

        response = {'action': 'upcard', 'hand_card': message['context']['hand']['cards'][0]}

        # print('\nAnswer: %s' % response)
        response = json.dumps(response) + '\n'
        send_message(response)
        # print('\nSent' % response)
    except Exception as e:
        response = json.dumps({'error': str(e)})
        send_message(response)

conn.close()
Esempio n. 7
0
        conn.sendall(message)
    else:
        conn.sendall(bytes(message, 'utf-8'))


while True:
    try:
        # print('\nWaiting for request')
        message = conn.recv(8192)  # 2**13
        if not message or message == 'stop':
            break
        # print('\nRequest received: %s' % json.loads(message))
        message = json.loads(message)

        # print('Context %s' % message['context'])

        response = {
            'action': 'upcard',
            'hand_card': message['context']['hand']['cards'][0]
        }

        # print('\nAnswer: %s' % response)
        response = json.dumps(response) + '\n'
        send_message(response)
        # print('\nSent' % response)
    except Exception as e:
        response = json.dumps({'error': str(e)})
        send_message(response)

conn.close()
Esempio n. 8
0
 def test_gat_player_must_be_serializable(self):
     result = json.dumps(StubGATPlayer(['python', 'x']))
     self.assertEquals('{}', result)