Skip to content

Commit

Permalink
Fixed tier 1 for newest patch
Browse files Browse the repository at this point in the history
  • Loading branch information
manny405 committed Aug 26, 2022
1 parent 413cb58 commit ec22d83
Show file tree
Hide file tree
Showing 8 changed files with 285 additions and 152 deletions.
166 changes: 83 additions & 83 deletions sapai/data.py

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions sapai/effects.py
Original file line number Diff line number Diff line change
Expand Up @@ -1074,9 +1074,9 @@ def TransferStats(apet, apet_idx, teams, te=None, te_idx=[], fixed_targets=[]):
### that have this ability
temp_from = temp_from[0][0]
if copy_attack:
apet._attack = temp_from.attack
apet._attack = int(temp_from.attack * percentage)
if copy_health:
apet._health = temp_from.health
apet._health = int(temp_from.health * percentage)

return target, possible

Expand Down
2 changes: 1 addition & 1 deletion sapai/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def apply_coconut_shield(value):

def apply_bone_attack(value):
if value > 0:
return value + 5
return value + 4
else:
return 0

Expand Down
44 changes: 22 additions & 22 deletions sapai/teams.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def __init__(
super().__init__(slots, 5, slot_class=TeamSlot)
self._battle = battle
self.seed_state = seed_state
self.team = [TeamSlot(seed_state=self.seed_state) for x in range(self.nslots)]
self.slots = [TeamSlot(seed_state=self.seed_state) for x in range(self.nslots)]
for iter_idx, obj in enumerate(slots):
self[iter_idx] = obj
self[iter_idx]._pet.team = self
Expand Down Expand Up @@ -121,40 +121,40 @@ def move_backward(self):

def remove(self, obj):
if type(obj) == int:
self.team[obj] = TeamSlot(seed_state=self.seed_state)
self.slots[obj] = TeamSlot(seed_state=self.seed_state)
elif type(obj).__name__ == "TeamSlot":
found = False
for iter_idx, temp_slot in enumerate(self.team):
for iter_idx, temp_slot in enumerate(self.slots):
if temp_slot == obj:
found_idx = iter_idx
found = True
if not found:
raise Exception("Remove {} not found".format(obj))
self.team[found_idx] = TeamSlot(seed_state=self.seed_state)
self.slots[found_idx] = TeamSlot(seed_state=self.seed_state)
elif type(obj).__name__ == "Pet":
found = False
for iter_idx, temp_slot in enumerate(self.team):
for iter_idx, temp_slot in enumerate(self.slots):
temp_pet = temp_slot.pet
if temp_pet == obj:
found_idx = iter_idx
found = True
if not found:
raise Exception("Remove {} not found".format(obj))
self.team[found_idx] = TeamSlot(seed_state=self.seed_state)
self.slots[found_idx] = TeamSlot(seed_state=self.seed_state)
else:
raise Exception("Object of type {} not recognized".format(type(obj)))

def check_friend(self, obj):
if type(obj).__name__ == "TeamSlot":
found = False
for iter_idx, temp_slot in enumerate(self.team):
for iter_idx, temp_slot in enumerate(self.slots):
if temp_slot == obj:
found_idx = iter_idx
found = True
return found
elif type(obj).__name__ == "Pet":
found = False
for iter_idx, temp_slot in enumerate(self.team):
for iter_idx, temp_slot in enumerate(self.slots):
temp_pet = temp_slot.pet
if temp_pet == obj:
found_idx = iter_idx
Expand All @@ -166,7 +166,7 @@ def check_friend(self, obj):
def get_idx(self, obj):
if type(obj).__name__ == "TeamSlot":
found = False
for iter_idx, temp_slot in enumerate(self.team):
for iter_idx, temp_slot in enumerate(self.slots):
if temp_slot == obj:
found_idx = iter_idx
found = True
Expand All @@ -175,7 +175,7 @@ def get_idx(self, obj):
return found_idx
elif type(obj).__name__ == "Pet":
found = False
for iter_idx, temp_slot in enumerate(self.team):
for iter_idx, temp_slot in enumerate(self.slots):
temp_pet = temp_slot.pet
if temp_pet == obj:
found_idx = iter_idx
Expand Down Expand Up @@ -233,7 +233,7 @@ def get_behind(self, obj, n=1):
chosen = []
for temp_idx in fidx:
if temp_idx > pet_idx:
chosen.append(self.team[temp_idx])
chosen.append(self.slots[temp_idx])
return chosen[0:n]

def get_empty(self):
Expand All @@ -246,15 +246,15 @@ def get_empty(self):
def append(self, obj):
obj = TeamSlot(obj, seed_state=self.seed_state)
n = len(self)
if n == len(self.team):
if n == len(self.slots):
raise Exception("Attempted to append to a full team")
empty_idx = self.get_empty()
if len(empty_idx) == 0:
raise Exception("This should not be possible")
self.team[empty_idx[0]] = obj
self.slots[empty_idx[0]] = obj

def check_lvl3(self):
for slot in self.team:
for slot in self.slots:
if slot.empty:
continue
if slot.pet.level == 3:
Expand All @@ -266,33 +266,33 @@ def battle(self):
return self._battle

def __iter__(self):
yield from self.team
yield from self.slots

def __len__(self):
count = 0
for temp_slot in self.team:
for temp_slot in self.slots:
if not temp_slot.empty:
count += 1
return count

def __getitem__(self, idx):
return self.team[idx]
return self.slots[idx]

def __setitem__(self, idx, obj):
if type(obj).__name__ == "Pet":
self.team[idx] = TeamSlot(obj, seed_state=self.seed_state)
self.slots[idx] = TeamSlot(obj, seed_state=self.seed_state)
elif type(obj).__name__ == "TeamSlot":
self.team[idx] = obj
self.slots[idx] = obj
elif type(obj) == str or type(obj) == numpy.str_:
self.team[idx] = TeamSlot(obj, seed_state=self.seed_state)
self.slots[idx] = TeamSlot(obj, seed_state=self.seed_state)
else:
raise Exception(
"Tried setting a team slot with type {}".format(type(obj).__name__)
)

def __repr__(self):
repr_str = ""
for iter_idx, slot in enumerate(self.team):
for iter_idx, slot in enumerate(self.slots):
repr_str += "{}: {} \n ".format(iter_idx, slot)
return repr_str

Expand All @@ -311,7 +311,7 @@ def state(self):
state_dict = {
"type": "Team",
"battle": self.battle,
"team": [x.state for x in self.team],
"team": [x.state for x in self.slots],
"pack": self.pack,
}
return state_dict
Expand Down
14 changes: 13 additions & 1 deletion tests/test_battles.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from sapai import *
from sapai.battle import Battle
from sapai.graph import graph_battle
from sapai.compress import *


class TestBattles(unittest.TestCase):
Expand Down Expand Up @@ -144,7 +145,8 @@ def test_horse_in_battle(self):

test_battle = Battle(team1, team2)
result = test_battle.battle()
self.assertEqual(result, 2)
self.assertEqual(test_battle.t0.empty, [0, 1, 2, 3, 4])
self.assertEqual(test_battle.t1[0].health, 1)

def test_horse_with_bee_in_battle(self):
cricket = Pet("cricket")
Expand Down Expand Up @@ -387,5 +389,15 @@ def test_rat_summons_at_front(self):
result = test_battle.battle()
self.assertEqual(result, 0)

def test_peacock(self):
### Check that peacock attack is correct after battle

### Check peacock attack after elephant for all three levels

### Check peacock after headgehog on both teams

### Implement later with others
pass


# %%
11 changes: 0 additions & 11 deletions tests/test_effects.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,17 +184,6 @@ def test_weak(self):
attack_phase = get_attack(fish, t3[0].pet)
self.assertEqual(attack_phase[1], 9) # 6/8 + 3

def test_peacock(self):
peacock = Pet("peacock")
peacock._hurt = True
t = Team([peacock])
peacock.hurt_trigger(Team())
self.assertEqual(peacock.attack, 3)
# same turn, therefore should not activate again:
peacock._hurt = True
peacock.hurt_trigger(Team())
self.assertEqual(peacock.attack, 3)

def test_hatching_chick_level_3(self):
hc = Pet("hatching-chick")
hc.level = 3
Expand Down
Loading

0 comments on commit ec22d83

Please sign in to comment.