manny405 / sapai

Super auto pets engine built with reinforment learning training in mind
MIT License
67 stars 21 forks source link

Bug in `buy_food_trigger` #10

Closed alexdriedger closed 2 years ago

alexdriedger commented 2 years ago

https://github.com/manny405/sapai/blob/6e7ef0ab272b6cb3348711e20537514c599363e6/sapai/pets.py#L268

There appears to be a bug in buy_food_trigger when purchasing food. I'm not sure how these triggers work, so I'm not sure how to fix it, but the line above is where the exception is raised. Here is a minimal test to reproduce it. I tested it with rabbit and worm, and apple and honey and all of those combinations threw exceptions.

from sapai import Shop, Player
from sapai.shop import ShopSlot

shop_slots = list()
shop_slots.append(ShopSlot("rabbit"))
shop_slots.append(ShopSlot("honey"))

shop = Shop(shop_slots=shop_slots)
player = Player(shop=shop)
player.buy_pet(0)
player.buy_food(0, 0)

As a side note, I found this by writing an agent to take random actions. I've also ran into some other bugs as well and will try to create reproducible tests for them as well.

manny405 commented 2 years ago

Thanks for the find! Took me a while to get to this. I successfully defended my PhD on Friday.

I've corrected the issue in the most recent commit.

Any other issues/bugs you have encountered would be great to see! I'll try to fix them as quickly as I can. I think the library here is starting to become fairly robust/reliable.

alexdriedger commented 2 years ago

Congrats on the defense! I ran the test again and it passed with the latest update 👍