def player(id, key, strategy): res = send2([2, key, [103652820, 192496425430]]) joinres = JoinResult.parse(res) total = joinres.budget fake_state = from_python([ 6, [ 0, 10, -1, id, 0, 2, [], [], 4, [], [256, 1, [total, 1, 64], [16, 128], []], [], [] ], 9, [] ]) print(f'Send 2 res: {res}, available: {total}') initial_stats = strategy.pick_stats(res) state = send2([3, key, initial_stats]) images = [] T = 0 while True: T += 1 state = send2([4, key, strategy.apply(state)]) # images.append(drawState(fake_state, from_python(state))[1]) # intermediate gif saves # if T % 10 == 0: # images[0].save(f'player{id}.gif', save_all=True, append_images=images[1:]) if state[1] == 2: print('done') break
def main(): server_url = sys.argv[1] player_key = sys.argv[2] print('ServerUrl: %s; PlayerKey: %s' % (server_url, player_key)) sender = lambda msg: send2(msg, server_url=server_url) # strategy = OrbiterStrategy(do_laser=True, printships=False, duplicate=True) strategy = SwarmerStrategy() player(int(player_key), strategy, sender=sender)
import random from multiprocessing import Process from parser import drawState, from_python from states import State, JoinResult from orbiter import OrbiterStrategy from swarmer import SwarmerStrategy from interaction import send2 from orbit_util import sign, trace_orbit _, [p1, p2] = send2([1, 0]) def survivor_strategy(state): pid = state[2][1] actions = [] my_ships = [] enemy_ships = [] for obj in state[3][2]: if obj[0][0] == pid: print(obj) my_ships.append(obj) else: enemy_ships.append(obj) for my_ship in my_ships: my_pos = my_ship[0][2] thrust = (-sign(my_pos[0]), 0) if abs(my_pos[0]) > abs(my_pos[1]) else (0, -sign(my_pos[1])) actions.append([0, my_ship[0][1], thrust]) if enemy_ships: