Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
def test_move_accuracy():
    """Test ability to 'risk' with move accuracy."""
    # Set up Pokemon
    floatzel = Pokemon(name="floatzel", moves=["hydropump", "tackle"])
    opp_stunfisk = Pokemon(name="stunfisk", moves=["discharge"])
    floatzel.current_hp = 1
    opp_stunfisk.current_hp = 1

    # Set up player gamestates and agents
    # Floatzel uses tackle because it guarantees to kill
    player_gs, opp_gs = init_gamestates(floatzel, opp_stunfisk)
    bppa = init_bppa_acc(floatzel, player_gs, opp_gs)

    move = bppa.make_move()
    assert move[0] == "ATTACK"
    assert move[1] == 1

    # Skuntank Test (priority)
    # Floatzel uses aqua jet because it outprioritizes SP
    floatzel = Pokemon(name="floatzel", moves=["hydropump", "aquajet"])
    opp_skunk = Pokemon(name="skuntank", moves=["suckerpunch"])
    floatzel.current_hp = 1
    opp_skunk.current_hp = 1

    player_gs, opp_gs = init_gamestates(floatzel, opp_skunk)
    bppa = init_bppa_acc(floatzel, player_gs, opp_gs)
    move = bppa.make_move()

    assert move[0] == "ATTACK"
    assert move[1] == 1

    # 2ndary accuracy test
    # Floatzel uses Hydro Pump because it will kill, even though it might miss
    floatzel = Pokemon(name="floatzel", moves=["surf", "hydropump"])
    opp_stunfisk = Pokemon(name="stunfisk", moves=["discharge"])
    floatzel.current_hp = 1
    opp_stunfisk.current_hp = int(0.6 * opp_stunfisk.current_hp)
    player_gs, opp_gs = init_gamestates(floatzel, opp_stunfisk)

    bppa = init_bppa_acc(floatzel, player_gs, opp_gs)
    move = bppa.make_move()

    assert move[0] == "ATTACK"
    assert move[1] == 1

    # Damage test
    # Floatzel uses Hydro Pump because it'll out-damage tackle
    opp_stunfisk.current_hp = opp_stunfisk.max_hp
    floatzel.current_hp = floatzel.max_hp
    player_gs, opp_gs = init_gamestates(floatzel, opp_stunfisk)
    bppa = init_bppa_acc(floatzel, player_gs, opp_gs)
    move = bppa.make_move()

    assert move[0] == "ATTACK"
    assert move[1] == 1
Ejemplo n.º 3
0
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
Ejemplo n.º 4
0
def test_healing():
    """Make sure healing is applied."""
    ivysaur = Pokemon(name="ivysaur", moves=["synthesis"])
    floatzel = Pokemon(name="floatzel", moves=["watergun"])

    ivysaur.current_hp = 1
    floatzel.current_hp = 1

    synthesis = HealingMove(**MOVE_DATA["synthesis"])
    heal_pulse = HealingMove(**MOVE_DATA["healpulse"])

    # Ivysaur uses Synthesis
    synthesis.apply_healing(ivysaur, floatzel)
    assert ivysaur.current_hp == 1 + int(ivysaur.max_hp / 2)
    assert floatzel.current_hp == 1

    # Ivysaur uses Heal Pulse on Floatzel
    heal_pulse.apply_healing(ivysaur, floatzel)
    assert ivysaur.current_hp == 1 + int(ivysaur.max_hp / 2)
    assert floatzel.current_hp == 1 + int(ivysaur.max_hp / 2)

    # No Overheal
    synthesis.apply_healing(ivysaur, floatzel)
    assert ivysaur.current_hp == ivysaur.max_hp