def test_oil_passage_block(self): state = setup_state() state.player.oils = 1 x = 100 y = 2 def set_xy(_x, _y): x = _x y = _y state.player.x = x state.player.y = y assert offensive_search(state) == Cmd.NOP set_xy(x, 1) assert offensive_search(state) == Cmd.OIL set_xy(x, 4) assert offensive_search(state) == Cmd.OIL set_xy(x, 2) state.map[x, y - 1] = Block.MUD state.map[x, y + 1] = Block.MUD assert offensive_search(state) == Cmd.OIL
def test_tweet_behind(self): state = setup_state() state.player.tweets = 1 state.player.x = 100 state.opponent.x = 100 assert offensive_search(state) == Cmd.NOP state.player.x = 90 assert offensive_search(state) == Cmd.NOP
def calc_cmd(self): if self.state.player.speed < 5: self.search_depth = 4 self.opp_search_depth = 0 elif self.state.player.speed < 8: self.search_depth = 3 self.opp_search_depth = 1 else: self.search_depth = 3 self.opp_search_depth = 2 search_res = search(self.state, self.pred_opp, max_search_depth=self.search_depth) cmds = score(search_res, self.state, self.weights, self.pred_opp) cmd = cmds[0] if cmd == Cmd.NOP: # increase search depth for better opponent prediction in offensive # search self.opp_search_depth = 3 cmd = offensive_search(self.state, cmds, self.pred_opp) # place oil block on map if we're dropping oil if cmd == Cmd.OIL: x, y = self.state.player.x, self.state.player.y self.state.map.global_map[x, y] = Block.OIL_SPILL return cmd
def test_emp_min_max_lanes(self): state = setup_state() state.player.emps = 1 state.player.x = 100 state.player.y = 2 state.opponent.x = 150 state.opponent.y = 1 assert offensive_search(state) == Cmd.EMP state.player.y = 3 state.opponent.y = 4 assert offensive_search(state) == Cmd.EMP
def test_emp_opp_behind(self): state = setup_state() state.player.emps = 1 # behind state.player.x = 100 state.player.y = 2 state.opponent.x = 90 state.opponent.y = 2 assert offensive_search(state) == Cmd.NOP # same x state.opponent.x = 100 state.opponent.y = 1 assert offensive_search(state) == Cmd.NOP
def test_close_behind_oil_drop(self): state = setup_state() state.player.x = 100 state.player.y = 2 state.player.oils = 1 state.opponent.x = state.player.x - 10 state.opponent.y = state.player.y assert offensive_search(state) == Cmd.OIL
def test_emp_samelane(self): state = setup_state() state.player.emps = 1 state.player.x = 100 state.player.y = 2 state.opponent.x = 150 state.opponent.y = 2 assert offensive_search(state) == Cmd.EMP
def test_emp_no_emp(self): state = setup_state() state.player.emps = 0 state.player.x = 100 state.player.y = 2 state.opponent.x = 110 state.opponent.y = 2 assert offensive_search(state) == Cmd.NOP
def test_emp_safety(self): state = setup_state() state.player.emps = 1 state.player.x = 100 state.player.y = 2 state.opponent.x = 104 state.opponent.y = 2 assert state.player.x + state.player.speed >= state.opponent.x assert offensive_search(state) != Cmd.EMP
def test_tweet_dont_place_ahead_of_player(self): state = setup_state() state.player.tweets = 1 state.player.y = 2 state.player.x = 200 state.opponent.y = 2 state.opponent.x = 199 pred = lambda s: Cmd.NOP assert offensive_search(state, pred_opp=pred) == Cmd.NOP
def test_tweet_place_in_future_path(self): state = setup_state() state.player.tweets = 1 state.player.x = 200 state.opponent.y = 1 state.opponent.x = 100 pred = lambda s: Cmd.RIGHT nstate = next_state(state, Cmd.NOP, pred(state)) nnstate = next_state(nstate, Cmd.NOP, pred(nstate)) match = Cmd(Cmd.TWEET, pos=(nstate.opponent.x + 3, nnstate.opponent.y)) assert offensive_search(state, pred_opp=pred) == match
def test_tweet_ignore_fix(self): state = setup_state() state.player.tweets = 1 state.player.x = 100 state.opponent.x = 10 state.opponent.y = 4 state.opponent.damage = 2 def pred(state): if state.opponent.damage > 0: return Cmd.FIX return Cmd.LEFT nstate = next_state(state, Cmd.NOP, Cmd.LEFT) nnstate = next_state(nstate, Cmd.NOP, Cmd.LEFT) match = Cmd(Cmd.TWEET, pos=(nstate.opponent.x + 3, nnstate.opponent.y)) assert offensive_search(state, pred_opp=pred) == match
def test_dont_tweet_on_own_pos(self): state = setup_state() state.player.tweets = 1 state.player.x = 200 state.player.y = 2 state.opponent.x = state.player.x - state.opponent.speed - 3 state.opponent.y = state.player.y pred = lambda s: Cmd.NOP nstate = next_state(state, Cmd.NOP, pred(state)) nnstate = next_state(nstate, Cmd.NOP, pred(nstate)) assert nstate.opponent.y == state.player.y assert nstate.opponent.x + 3 == state.player.x match = Cmd(Cmd.TWEET, pos=(nstate.opponent.x + 2, nnstate.opponent.y)) assert match.pos[0] == state.player.x - 1 assert match.pos[1] == state.player.y assert offensive_search(state, pred_opp=pred) == match
def test_tweet_no_tweet(self): state = setup_state() state.player.tweets = 0 assert offensive_search(state) == Cmd.NOP
def test_excessive_oil_drop(self): state = setup_state() state.player.y = 2 state.player.oils = 4 assert offensive_search(state) == Cmd.OIL
def test_nop(self): state = setup_state() assert offensive_search(state) == Cmd.NOP