Example #1
0
    def test_acrobatics_noitem(self):
        b = Battle(debug=False, rng=False)
        b.join(0, [{'species': 'charmander', 'moves': ['tackle']}])
        b.join(1, [{
            'species': 'pidgey',
            'item': 'pokeball',
            'moves': ['acrobatics']
        }])

        b.choose(0, dex.Decision('move', 0))
        b.choose(1, dex.Decision('move', 0))
        b.do_turn()

        charmander = b.sides[0].pokemon[0]
        pidgey = b.sides[1].pokemon[0]

        #damage calcs were done by hand
        self.assertEqual(charmander.hp, charmander.maxhp - 39)
Example #2
0
    def test_case3(self):
        battle = Battle(debug=False, rng=False)

        battle.join(0, [{
            'species': 'mew',
            'level': 76,
            'ivs': dex.Stats(15, 0, 8, 7, 1, 31),
            'evs': dex.Stats(252, 0, 0, 4, 0, 252)
        }])
        stats = battle.sides[0].pokemon[0].stats

        #stat calcs were checked by smogon
        self.assertEqual(stats.hp, 297)
        self.assertEqual(stats.attack, 157)
        self.assertEqual(stats.defense, 163)
        self.assertEqual(stats.specialattack, 163)
        self.assertEqual(stats.specialdefense, 157)
        self.assertEqual(stats.speed, 228)
    def test_voltthunderbolt(self):
        battle = Battle(debug=False, rng=False)
        battle.join(0, [{
            'species': 'pikachuhoenn',
            'item': 'pikashuniumz',
            'moves': ['thunderbolt']
        }])
        battle.join(1, [{
            'species': 'magnemite',
            'item': 'normaliumz',
            'moves': ['tackle']
        }])

        battle.choose(0, dex.Decision('move', 0, zmove=True))
        battle.choose(1, dex.Decision('move', 0, zmove=True))
        battle.do_turn()

        pikachu = battle.sides[0].pokemon[0]
        magnemite = battle.sides[1].pokemon[0]

        #damage calcs were done by hand
        self.assertEqual(magnemite.hp, magnemite.maxhp - 61)
        self.assertEqual(pikachu.hp, pikachu.maxhp - 42)
Example #4
0
    def test_level_difference(self):
        battle = Battle(debug=False, rng=False)
        battle.join(0, [{
            'species': 'abomasnow',
            'level': 50,
            'moves': ['headbutt']
        }])
        battle.join(1, [{
            'species': 'wailord',
            'level': 100,
            'moves': ['surf']
        }])

        battle.choose(0, dex.Decision('move', 0))
        battle.choose(1, dex.Decision('move', 0))
        battle.do_turn()

        nic = battle.sides[0]
        sam = battle.sides[1]

        #damage calcs were done by hand
        self.assertEqual(nic.pokemon[0].hp, nic.pokemon[0].maxhp - 117)
        self.assertEqual(sam.pokemon[0].hp, sam.pokemon[0].maxhp - 29)
Example #5
0
    def test_tackle(self):
        battle = Battle(debug=False, rng=False)
        """tests tackle with STAB and no STAB"""
        battle.join(0, [{
            'species': 'charmander',
            'level': 5,
            'moves': ['tackle']
        }])
        battle.join(1, [{
            'species': 'magnemite',
            'level': 5,
            'moves': ['tackle']
        }])

        battle.choose(0, dex.Decision('move', 0))
        battle.choose(1, dex.Decision('move', 0))
        battle.do_turn()

        nic = battle.sides[0]
        sam = battle.sides[1]

        #damage calcs were done by hand
        self.assertEqual(nic.pokemon[0].hp, nic.pokemon[0].maxhp - 5)
        self.assertEqual(sam.pokemon[0].hp, sam.pokemon[0].maxhp - 2)
Example #6
0
    def fitness_test(self):
        team = decode_team(self.genome)

        num_battles = 75
        won = 0

        for i in range(num_battles):
            b = Battle(debug=False)

            b.join(0, team=team)
            b.join(1, team=sample_teams['johtoxalola'])

            b.run()
            if b.winner == 0:
                won += 1

        self.fitness = round(won / num_battles, 4)
        print(str(self.fitness))
Example #7
0
    def test_drain_moves(self):
        b = Battle(debug=False, rng=False)
        b.join(0, [{'species': 'charmander', 'moves': ['tackle']}])
        b.join(1, [{'species': 'bulbasaur', 'moves': ['tackle', 'absorb']}])

        b.choose(0, dex.Decision('move', 0))
        b.choose(1, dex.Decision('move', 0))
        b.do_turn()

        b.choose(0, dex.Decision('move', 0))
        b.choose(1, dex.Decision('move', 1))
        b.do_turn()

        charmander = b.sides[0].pokemon[0]
        bulbasaur = b.sides[1].pokemon[0]

        #damage calcs were done by hand
        self.assertEqual(charmander.hp, charmander.maxhp-30)
        self.assertEqual(bulbasaur.hp, bulbasaur.maxhp-36)
Example #8
0
    def test_normal(self):
        b = Battle(doubles=True, debug=False, rng=False)
        b.join(0, [{
            'species': 'pidgey',
            'moves': ['thunderbolt', 'protect']
        }, {
            'species': 'charmander',
            'moves': ['tackle']
        }])
        b.join(1, [{
            'species': 'rattata',
            'moves': ['thunderbolt', 'protect']
        }, {
            'species': 'squirtle',
            'moves': ['tackle', 'watergun']
        }])

        b.choose(
            0,
            [dex.Decision('move', 0, 'foe1'),
             dex.Decision('move', 0, 'foe1')])
        b.choose(1, [dex.Decision('move', 0), dex.Decision('move', 0)])
        b.do_turn()

        pidgey = b.sides[0].pokemon[0]
        charmander = b.sides[0].pokemon[1]
        rattata = b.sides[1].pokemon[0]
        squirtle = b.sides[1].pokemon[1]

        #damage calcs were done by hand
        self.assertEqual(rattata.hp, rattata.maxhp)
        self.assertEqual(squirtle.hp, squirtle.maxhp - 70)
Example #9
0
    def test_switch(self):
        battle = Battle(debug=False, rng=False)
        battle.join(0, [{
            'species': 'mew'
        }, {
            'species': 'mewtwo'
        }, {
            'species': 'magnezone'
        }])
        battle.join(1, [{'species': 'pidgey', 'moves': ['peck']}])

        battle.choose(0, dex.Decision('switch', 2))
        battle.choose(1, dex.Decision('move', 0))
        battle.do_turn()

        mew = battle.sides[0].pokemon[0]
        mewtwo = battle.sides[0].pokemon[1]
        magnezone = battle.sides[0].pokemon[2]

        pidgey = battle.sides[1].pokemon[0]

        self.assertEqual(battle.sides[0].active_pokemon[0].species,
                         'magnezone')
        self.assertEqual(mew.hp, mew.maxhp)
        self.assertEqual(magnezone.hp, magnezone.maxhp - 3)
Example #10
0
    def test_mewtwo_x(self):
        battle = Battle(debug=False, rng=False)
        battle.join(0, [{
            'species': 'mewtwo',
            'item': 'mewtwonitex',
            'moves': ['tackle', 'protect']
        }])
        battle.join(1, [{
            'species': 'charizard',
            'item': 'charizarditex',
            'moves': ['tackle']
        }])

        battle.choose(0, dex.Decision('move', 0, mega=True))
        battle.choose(1, dex.Decision('move', 0, mega=False))
        battle.do_turn()

        mewtwo = battle.sides[0].pokemon[0]
        charizard = battle.sides[1].pokemon[0]
        self.assertEqual(mewtwo.species, 'mewtwomegax')
        self.assertEqual(mewtwo.hp, mewtwo.maxhp - 17)
Example #11
0
from sim.battle import Battle

battle = Battle(doubles=True)
battle.run()
Example #12
0
    def test_zmove_twice(self):
        battle = Battle(debug=False, rng=False)
        """tests tackle with STAB and no STAB"""
        battle.join(0, [{
            'species': 'pikachuhoenn',
            'item': 'pikashuniumz',
            'moves': ['thunderbolt']
        }])
        battle.join(1, [{'species': 'magnemite', 'moves': ['tackle']}])

        battle.choose(0, dex.Decision('move', 0, zmove=True))
        battle.choose(1, dex.Decision('move', 0))
        battle.do_turn()

        battle.choose(0, dex.Decision('move', 0, zmove=True))
        battle.choose(1, dex.Decision('move', 0))
        battle.do_turn()

        pikachu = battle.sides[0].pokemon[0]
        magnemite = battle.sides[1].pokemon[0]

        #damage calcs were done by hand
        self.assertEqual(magnemite.hp, magnemite.maxhp - 89)
Example #13
0
    def test_fakeout(self):
        battle = Battle(debug=False, rng=False)
        battle.join(0, [{
            'species': 'charmander',
            'level': 5,
            'moves': ['fakeout']
        }])
        battle.join(1, [{
            'species': 'magnemite',
            'level': 5,
            'moves': ['tackle']
        }])

        battle.choose(0, dex.Decision('move', 0))
        battle.choose(1, dex.Decision('move', 0))
        battle.do_turn()

        battle.choose(0, dex.Decision('move', 0))
        battle.choose(1, dex.Decision('move', 0))
        battle.do_turn()

        magnemite = battle.sides[1].pokemon[0]
        charmander = battle.sides[0].pokemon[0]

        #damage calcs were done by hand
        self.assertEqual(charmander.hp, charmander.maxhp - 5)
        self.assertEqual(magnemite.hp, magnemite.maxhp - 2)
Example #14
0
    def test_protect_one_turn(self):
        battle = Battle(debug=False, rng=False)
        battle.join(0, [{
            'species': 'pidgeot',
            'moves': ['tackle', 'protect']
        }])
        battle.join(1, [{'species': 'mew', 'moves': ['tackle', 'protect']}])

        battle.choose(0, dex.Decision('move', 1))
        battle.choose(1, dex.Decision('move', 0))
        battle.do_turn()

        battle.choose(0, dex.Decision('move', 0))
        battle.choose(1, dex.Decision('move', 0))
        battle.do_turn()

        pidgeot = battle.sides[0].pokemon[0]
        self.assertEqual(pidgeot.hp, pidgeot.maxhp - 24)