def test_infer_speed_investment(): """Test how we infer speed.""" magikarp = Pokemon(name="magikarp", moves=["tackle"]) spinda = Pokemon(name="spinda", moves=["tackle"]) ppgs1 = PokemonPlayerGameState() ppgs2 = PokemonPlayerGameState() gamestate = {} gamestate["team"] = [] gamestate["active"] = magikarp opp_gamestate_dict = {} opp_gamestate_dict["team"] = [] opp_gamestate_dict["active"] = spinda opp_gamestate = anonymize_gamestate_helper(opp_gamestate_dict) ppgs1.update_gamestate(gamestate, opp_gamestate) ppgs2.update_gamestate(opp_gamestate_dict, anonymize_gamestate_helper(gamestate)) new_info = {} new_info["type"] = "ATTACK" new_info["move"] = MOVE_DATA["tackle"] new_info["attacker"] = "player2" new_info["defender"] = "player1" new_info["pct_damage"] = 27 new_info["damage"] = 46 new_info["atk_poke"] = "spinda" new_info["def_poke"] = "magikarp" new_info = [new_info] * 2 test_infer_speed_faster(ppgs2, new_info) test_infer_speed_slower(ppgs1, new_info)
def test_battle_posn_one(): """Test battle position functions work.""" magikarp = Pokemon(name="magikarp", moves=["tackle"]) magikarp_opp = Pokemon(name="magikarp", moves=["tackle"]) pa1 = PokemonAgent([magikarp]) gamestate = {} gamestate["team"] = [] gamestate["active"] = magikarp opp_gamestate_dict = {} opp_gamestate_dict["team"] = [] opp_gamestate_dict["active"] = magikarp_opp opp_gamestate = anonymize_gamestate_helper(opp_gamestate_dict) pa1.update_gamestate(gamestate, opp_gamestate) assert pa1.calc_position() == 1 assert pa1.calc_opp_position() == 1 assert pa1.battle_position() == 1 # We're now in a bad position magikarp.current_hp = 1 pa1.update_gamestate(gamestate, opp_gamestate) assert pa1.calc_position() < 0.1 assert pa1.calc_opp_position() == 1 assert pa1.battle_position() < 1 # Now we're in a better position. magikarp.current_hp = magikarp.max_hp / 2 magikarp_opp.current_hp = 1 opp_gamestate = anonymize_gamestate_helper(opp_gamestate_dict) pa1.update_gamestate(gamestate, opp_gamestate) assert pa1.calc_position() == 0.5 assert pa1.calc_opp_position() < 0.1 assert pa1.battle_position() > 1
def test_opp_gamestate(): """Test that opponent's gamestate is updated properly.""" spinda = Pokemon(name="spinda", moves=["tackle"]) ppgs1 = PokemonPlayerGameState() ppgs2 = PokemonPlayerGameState() gamestate = {} gamestate["team"] = [] gamestate["active"] = spinda opp_gamestate = anonymize_gamestate_helper(gamestate) # Update the gamestate ppgs1.update_gamestate(gamestate, opp_gamestate) ppgs2.update_gamestate(gamestate, opp_gamestate) # Gamestate updating happens properly. assert ppgs1.opp_gamestate["data"] assert not ppgs1.opp_gamestate["data"]["team"] assert ppgs1.opp_gamestate["data"]["active"]["name"] == "spinda" turn_info = {} turn_info["type"] = "ATTACK" turn_info["attacker"] = "player2" turn_info["move"] = spinda.moves[0] turn_info["pct_damage"] = 28 turn_info["def_poke"] = "spinda" turn_info["atk_poke"] = "spinda" turn_info = [turn_info] # Give new info ppgs1.new_info(turn_info, "player1") # New info is stored properly assert len(ppgs1.opp_gamestate["moves"]["spinda"]) == 1
def test_battle_posn_multiple(): """Test that battle position functions work with multiple pokemon.""" magikarp = Pokemon(name="magikarp", moves=["tackle"]) magikarp_opp = Pokemon(name="magikarp", moves=["tackle"]) spinda = Pokemon(name="spinda", moves=["tackle"]) pa1 = PokemonAgent([magikarp, spinda, spinda]) gamestate = {} gamestate["team"] = [spinda, spinda] gamestate["active"] = magikarp opp_gamestate_dict = {} opp_gamestate_dict["team"] = [spinda] opp_gamestate_dict["active"] = magikarp_opp opp_gamestate = anonymize_gamestate_helper(opp_gamestate_dict) # Everything maximum HP pa1.update_gamestate(gamestate, opp_gamestate) assert pa1.calc_position() == 3 assert pa1.calc_opp_position() == 2 assert pa1.battle_position() == 1.5 # Good position, opponent has low HP magikarp_opp.current_hp = 1 opp_gamestate = anonymize_gamestate_helper(opp_gamestate_dict) pa1.update_gamestate(gamestate, opp_gamestate) assert pa1.calc_position() == 3 assert pa1.calc_opp_position() < 2 assert pa1.calc_opp_position() > 1 assert pa1.battle_position() > 1.5 assert pa1.battle_position() < 3 # Bad position, we have low HP magikarp_opp.current_hp = magikarp_opp.max_hp magikarp.current_hp = 1 opp_gamestate = anonymize_gamestate_helper(opp_gamestate_dict) pa1.update_gamestate(gamestate, opp_gamestate) assert pa1.calc_position() < 3 assert pa1.calc_position() > 2 assert pa1.calc_opp_position() == 2 assert pa1.battle_position() < 1.5 assert pa1.calc_position() > 1
def init_gamestates(player_poke, opp_poke): """Initialize player and opponent gamestates.""" player_gs = {} player_gs["team"] = [] player_gs["active"] = player_poke opp_gs = {} opp_gs["team"] = [] opp_gs["active"] = opp_poke opp_gs = anonymize_gamestate_helper(opp_gs) return player_gs, opp_gs
def test_infer_investment(): """Make sure investment is properly inferred.""" magikarp = Pokemon(name="magikarp", moves=["tackle"]) spinda = Pokemon(name="spinda", moves=["tackle"]) ppgs1 = PokemonPlayerGameState() ppgs2 = PokemonPlayerGameState() # Set the gamestate gamestate = {} gamestate["team"] = [] gamestate["active"] = magikarp opp_gamestate_dict = {} opp_gamestate_dict["team"] = [] opp_gamestate_dict["active"] = spinda opp_gamestate = anonymize_gamestate_helper(opp_gamestate_dict) ppgs1.update_gamestate(gamestate, opp_gamestate) ppgs2.update_gamestate(opp_gamestate_dict, anonymize_gamestate_helper(gamestate)) # Set the new info new_info = {} new_info["type"] = "ATTACK" new_info["move"] = MOVE_DATA["tackle"] new_info["attacker"] = "player1" new_info["defender"] = "player2" new_info["pct_damage"] = 27 new_info["damage"] = 46 new_info["atk_poke"] = "spinda" new_info["def_poke"] = "magikarp" new_info = [new_info] test_infer_defending(ppgs2, new_info) test_infer_attacking(ppgs1, new_info) test_infer_speed_investment() # Test with misses ppgs1 = PokemonPlayerGameState() ppgs1.update_gamestate(gamestate, opp_gamestate) test_infer_miss(ppgs1)
def test_switch_faint(): """Test that switch_faint() picks a valid pokemon.""" exploud = Pokemon(name="exploud", moves=["tackle"]) pa1 = PokemonAgent([exploud]) gamestate = {} gamestate["team"] = [exploud, exploud, exploud] gamestate["active"] = None opp_gamestate = anonymize_gamestate_helper(gamestate) pa1.update_gamestate(gamestate, opp_gamestate) val = pa1.switch_faint() assert val in range(3)
def init_bppa(): """Initialize the Player for these tests.""" spinda = Pokemon(name="spinda", moves=["tackle", "frustration"]) magikarp = Pokemon(name="magikarp", moves=["tackle"]) exploud = Pokemon(name="exploud", moves=["tackle"]) gamestate = {} gamestate["team"] = [exploud, magikarp] gamestate["active"] = spinda opp_gamestate = anonymize_gamestate_helper(gamestate) # Update the gamestate bppa = BasicPlanningPokemonAgent(tier="pu", team=[spinda]) bppa.update_gamestate(gamestate, opp_gamestate) bppa.init_opp_gamestate(opp_gamestate["team"], opp_gamestate["active"]) return bppa
def test_determine_faster(): """ Test ability to determine if player faster. A -> Abomasnow, S -> Spinda Under normal conditions, A is faster. When A is paralyzed, S is faster. When S is boosted, S is faster. When A and S are both boosted, A is faster. When A and S are both boosted, and A is paralyzed, S is faster. """ player_spinda = Pokemon(name="spinda", moves=["tackle"]) opp_abomasnow = Pokemon(name="abomasnow", moves=["tackle"]) player_move = ("ATTACK", 0) opp_move = ("ATTACK", "tackle") player_gs = {"team": [], "active": player_spinda} player = BasicPlanningPokemonAgent(tier="pu", team=[player_spinda]) # Slower than regular abomasnow opp_gs = { "data": anonymize_gamestate_helper({ "team": [], "active": opp_abomasnow }) } player.update_gamestate(player_gs, opp_gs) player.init_opp_gamestate(opp_gs["data"]["team"], opp_gs["data"]["active"]) assert not player.determine_faster(player.game_state.gamestate, opp_gs, player_move, opp_move) # Faster than paralyzed abonasnow opp_abomasnow.status = PAR_STATUS opp_gs = { "data": anonymize_gamestate_helper({ "team": [], "active": opp_abomasnow }) } player.update_gamestate(player_gs, opp_gs) assert player.determine_faster(player.game_state.gamestate, opp_gs, player_move, opp_move) # Faster than regular abomasnow at +6 player_gs["active"]["boosts"]["spe"] = 6 opp_abomasnow.status = None opp_gs = { "data": anonymize_gamestate_helper({ "team": [], "active": opp_abomasnow }) } player.update_gamestate(player_gs, opp_gs) assert player.determine_faster(player.game_state.gamestate, opp_gs, player_move, opp_move) # Slower than regular abomasnow when both at +6 opp_abomasnow.boosts["spe"] = 6 opp_gs = { "data": anonymize_gamestate_helper({ "team": [], "active": opp_abomasnow }) } player.update_gamestate(player_gs, opp_gs) assert not player.determine_faster(player.game_state.gamestate, opp_gs, player_move, opp_move) # Faster than paralyzed abomasnow when both at +6 opp_abomasnow.status = PAR_STATUS opp_gs = { "data": anonymize_gamestate_helper({ "team": [], "active": opp_abomasnow }) } player.update_gamestate(player_gs, opp_gs) assert player.determine_faster(player.game_state.gamestate, opp_gs, player_move, opp_move)