Hi @theCrimsonViper! Welcome to the CodeCombat Discourse! This is a safe place to chat and ask for level help. Before you begin your journey, could you please go through our rules that make this discourse an awesome place? It helps us all We hope you enjoy your stay!!
Now, to answer your questions, the maxRating variable is a variable meant to keep track of the current best coin you have seen yet. It starts at 0.
bestCoin = None
maxRating = 0
coinIndex = 0
coins = hero.findItems()
Then you go a loop through all the coins currently spawned, and assign a rating it each one.
while coinIndex < len(coins):
coin = coins[coinIndex]
rating = coin.value / hero.distanceTo(coin)
If the coins rating is better than the current best rating, the current best coin will equal that coin, and the current maxRating will be that coins rating.
if rating > maxRating:
bestCoin = coin
maxRating = rating
You devide the coin.value by hero.distanceTo(coin) because I assume you are trying to find the biggest coin to your hero, while making sure that the coin is not really far away from you.
Yes the variables do reset after the if bestCoin: statement. This way, if you went and collected the best coin, you will find a new best coin again.
This piece of code could be applied to many Python projects. It’s base essence is finding the nearest thing to another thing. It could be used in game dev for pathfinding, AI League for finding the nearest enemy to you, and many other things.
Hope this helps! Feel free to @iggmaster99 me if you need anything else!