Beispiel #1
0
    def test_trainerlistsimresults(self):
        bs = []
        cs = []
        ss = []
        for i in range(6):
            bs.append(
                Pokemon("Bulbasaur", "Grass", "Poison", 45, 49, 49, 65, 65,
                        45))
            cs.append(Pokemon("Charmander", "Fire", "", 39, 52, 43, 60, 50,
                              65))
            ss.append(Pokemon('Squirtle', 'Water', '', 44, 48, 65, 50, 64, 43))
        btrainer = Trainer(bs)
        ctrainer = Trainer(cs)
        strainer = Trainer(ss)
        trainers = [btrainer, ctrainer, strainer]

        pds = TrainerListPokeDataSim(trainers, 'trainerlisttest')
        pds.run_simulation()

        self.assertEqual(pds.results[0]['Winner']['pokemon'][0]['name'],
                         'Charmander')
        self.assertEqual(pds.results[1]['Winner']['pokemon'][0]['name'],
                         'Bulbasaur')
        self.assertEqual(pds.results[2]['Winner']['pokemon'][0]['name'],
                         'Squirtle')
Beispiel #2
0
    def test_constructor(self):
        b = Pokemon("Bulbasaur", "Grass", "Poison", 45, 49, 49, 65, 65, 45)
        c = Pokemon("Charmander", "Fire", "", 39, 52, 43, 60, 50, 65)
        s = Pokemon('Squirtle', 'Water', '', 44, 48, 65, 50, 64, 43)
        t = Trainer([b, c, s])

        self.assertIsInstance(t.pokemon, list)
        self.assertIsInstance(t.pokemon[0], Pokemon)
Beispiel #3
0
 def test_dict_operations(self):
     name = "Bulbasaur"
     type1 = "Grass"
     type2 = "Poison"
     hp = 45  # should become 123
     attack = 49  # should become 72
     defense = 49  # should become 72
     spatk = 65  # should become 88
     spdef = 65  # should become 88
     speed = 45  # should become 68
     bulba = Pokemon(name, type1, type2, hp, attack, defense, spatk, spdef,
                     speed)
     newbulba = Pokemon.from_dict(bulba.to_dict(), calcstat=False)
     self.assertTrue(bulba.compare(newbulba))
Beispiel #4
0
 def test_dict_operations(self):
     bs = []
     for i in range(6):
         bs.append(
             Pokemon("Bulbasaur", "Grass", "Poison", 45, 49, 49, 65, 65,
                     45))
     btrainer = Trainer(bs)
     copytrainer = Trainer.from_dict(btrainer.to_dict(),
                                     calculate_stat=False)
     self.assertTrue(btrainer.compare(copytrainer))
Beispiel #5
0
    def __init__(self, pokemon_indices, simname="", n_pokemon_team=1):
        experiment = BigFullFactorial([len(pokemon_indices)] * n_pokemon_team *
                                      2)
        super().__init__(experiment.idxrange, simname)

        self.pokemon_indices = pokemon_indices
        self.index_lookup = pd.DataFrame(self.pokemon_indices,
                                         columns=["PokemonIdx"])
        self.experiment = experiment
        self.idxrange = self.experiment.idxrange
        self.n_pokemon_team = n_pokemon_team
        self.pokegen = Pokemon.create_pokemon_generator(load_pokemon())
Beispiel #6
0
    def test_battlemechanics(self):
        bs = []
        cs = []
        ss = []
        for i in range(6):
            bs.append(
                Pokemon("Bulbasaur", "Grass", "Poison", 45, 49, 49, 65, 65,
                        45))
            cs.append(Pokemon("Charmander", "Fire", "", 39, 52, 43, 60, 50,
                              65))
            ss.append(Pokemon('Squirtle', 'Water', '', 44, 48, 65, 50, 64, 43))
        btrainer = Trainer(bs)
        ctrainer = Trainer(cs)
        strainer = Trainer(ss)

        # test correct order, whoever has higher speed will attack first and KO opponent
        ctrainer.active_pokemon().hp = 1
        btrainer.active_pokemon().hp = 1
        ctrainer.take_turn(btrainer)
        self.assertEqual(btrainer.active_pokemon_idx, 1)
        self.assertEqual(ctrainer.active_pokemon_idx, 0)

        # test type effectiveness (sanity check)
        self.dbg('Resetting charmander and bulbasaur trainers')
        ctrainer.reset()
        btrainer.reset()
        self.dbg('Bulbasaur trainer fights squirtle trainer')
        self.assertTrue(btrainer.fight(strainer))
        self.dbg('Resetting squirtle and bulbasaur trainers')
        btrainer.reset()
        strainer.reset()
        self.dbg('charmander trainer fights bulbasaur trainer')
        self.assertTrue(ctrainer.fight(btrainer))
        self.dbg('Resetting charmander and bulbasaur trainers')
        btrainer.reset()
        ctrainer.reset()
        self.dbg('squirtle trainer fights charmander trainer')
        self.assertTrue(strainer.fight(ctrainer))
Beispiel #7
0
    def test_dynamic_creation(self):
        # setup test variables
        poketable = load_pokemon()
        pikachuindex = 30  # pikachu
        vcb_indices = [2, 6, 11]  # Venusaur, Charizard, Blastoise
        checklist = ['Venusaur', 'Charizard', 'Blastoise']
        fullpokegen = Pokemon.create_pokemon_generator(poketable)
        cutpokegen = Pokemon.create_pokemon_generator(
            poketable.iloc[vcb_indices + [pikachuindex]])

        # test single row creation from Data frame
        pikachu = Pokemon.from_data_frame(poketable.iloc[pikachuindex])
        self.checkPokemon(pikachu, "Pikachu")

        # test multi row creation from data frame
        vcb = Pokemon.from_data_frame(poketable.iloc[vcb_indices])
        self.assertIsInstance(vcb, list)
        self.checkPokemon(vcb, checklist)

        # test single row pokegen with full df
        pikachufullgen = fullpokegen(pikachuindex)
        self.checkPokemon(pikachufullgen, "Pikachu")

        # test multi row pokegen with full df
        vcbfullgen = fullpokegen(vcb_indices)
        self.assertIsInstance(vcbfullgen, list)
        self.checkPokemon(vcbfullgen, checklist)

        # test single row pokegen with cut df
        pikachucutgen = cutpokegen(pikachuindex)
        self.checkPokemon(pikachucutgen, "Pikachu")

        # test multi row pokegen with cut df
        vcbcutgen = cutpokegen(vcb_indices)
        self.assertIsInstance(vcbcutgen, list)
        self.checkPokemon(vcbcutgen, checklist)
Beispiel #8
0
    def test_selectionmechanics(self):
        b = Pokemon("Bulbasaur", "Grass", "Poison", 45, 49, 49, 65, 65, 45)
        c = Pokemon("Charmander", "Fire", "", 39, 52, 43, 60, 50, 65)
        s = Pokemon('Squirtle', 'Water', '', 44, 48, 65, 50, 64, 43)

        # test select next conscious pokemon
        t = Trainer([b, c, s])
        t.pokemon[0].hp = 0  # knock out first pokemon
        t.choose_next_pokemon()
        self.assertEqual(t.active_pokemon_idx, 1)

        # test active_pokemon
        self.assertEqual(t.active_pokemon().name, "Charmander")

        # test that -1 is returned if all pokemon are KOed
        for p in t.pokemon:
            p.hp = 0
        t.choose_next_pokemon()
        self.assertEqual(t.active_pokemon_idx, -1)

        # test reset
        t.reset()
        self.assertEqual(t.active_pokemon_idx, 0)
        self.assertEqual(t.active_pokemon().hp, t.active_pokemon().maxhp)
Beispiel #9
0
 def test_constructor(self):
     name = "Bulbasaur"
     type1 = "Grass"
     type2 = "Poison"
     hp = 45  # should become 123
     attack = 49  # should become 72
     defense = 49  # should become 72
     spatk = 65  # should become 88
     spdef = 65  # should become 88
     speed = 45  # should become 68
     bulba = Pokemon(name, type1, type2, hp, attack, defense, spatk, spdef,
                     speed)
     self.checkPokemon(bulba, "Bulbasaur")
     self.assertEqual(bulba.type, ["Grass", "Poison"])
     self.assertEqual(bulba.hp, 123)
     self.assertEqual(bulba.attack, 72)
     self.assertEqual(bulba.defense, 72)
     self.assertEqual(bulba.spatk, 88)
     self.assertEqual(bulba.spdef, 88)
     self.assertEqual(bulba.speed, 68)
Beispiel #10
0
                     (s) or strsearchfcngen('Trainer list')(s)):
        attrs = {'align': 'center'}
        tables = soup.find_all('table', attrs=attrs)
        for tab in tables:
            rows = tab.find_all('tr')
            rows = rows[1:(len(rows) - 1)]
            trainername = ''
            for r in rows:
                candidatetrainer = list(r.children)[1]
                if candidatetrainer.has_attr('rowspan'):
                    trainername = candidatetrainer.get_text()
                    trainername = trainername[:(len(trainername) - 1)]
                    while trainername[0] == ' ':
                        trainername = trainername[1:len(trainername)]
                pokemon = r.find_all('td', align='center')
                pokelist = []
                for p in pokemon:
                    link = p.find('a')
                    if link:
                        pokenamestr = link['href']
                        pokenamestr = pokenamestr[6:pokenamestr.index('_')]
                        try:
                            level = int(p.get_text()[4:])
                        except ValueError:
                            level = 50
                        pokelist += Pokemon.from_data_frame(
                            poketable.loc[poketable.name == pokenamestr],
                            level=level)
                print(trainername)
                tdb_trainers.insert(Trainer(pokelist, trainername).to_dict())
Beispiel #11
0
    def test_battlemechanics(self):
        b = Pokemon("Bulbasaur", "Grass", "Poison", 45, 49, 49, 65, 65, 45)
        inferiorb = Pokemon("Bulbasaur", "Grass", "Poison", 44, 48, 48, 64, 64,
                            44)
        c = Pokemon("Charmander", "Fire", "", 39, 52, 43, 60, 50, 65)
        s = Pokemon('Squirtle', 'Water', '', 44, 48, 65, 50, 64, 43)

        # test damage
        orighp = b.hp
        damage = 15
        b.take_damage(damage)
        self.assertEqual(b.hp, orighp - damage)

        # test is_ko
        b.take_damage(b.hp)
        self.assertTrue(b.is_ko())

        # test recover
        b.recover()
        self.assertEqual(b.hp, b.maxhp)

        # test inferior
        self.assertTrue(inferiorb.deterministically_inferior_to(b))

        # test damage (numbers from azure heights lab battle damage calculator
        # bulbasaur attacks charmander 22
        self.assertEqual(b.do_attack(c), 22)
        # bulbasaur attacks squirtle 41
        self.assertEqual(b.do_attack(s), 41)
        # charmander attacks bulbasaur 38
        self.assertEqual(c.do_attack(b), 38)

        b.recover()
        s.recover()
        c.recover()

        # charmander attacks squirtle 12
        self.assertEqual(c.do_attack(s), 12)
        # squirtle attacks bulbasaur 13
        self.assertEqual(s.do_attack(b), 13)
        # squirtle attacks charmander 41
        self.assertEqual(s.do_attack(c), 41)
Beispiel #12
0
 def from_dict(cls, d, calculate_stat):
     pokemon = []
     for d in d['pokemon']:
         pokemon.append(Pokemon.from_dict(d, calcstat=calculate_stat))
     return cls(pokemon, name=d['name'])