FizzerWL / WarLight.AI

AI used for the game Warzone, located at https://www.warzone.com. See how to use this project at the WarLight blog at https://www.warlight.net/blog/index.php/2016/02/the-warlight-ai-goes-open-source/
20 stars 13 forks source link

Production Bot.armiesToTake() has issues in no-luck straight round with some offensive kill rates. #7

Open NewCompte opened 7 years ago

NewCompte commented 7 years ago

https://github.com/FizzerWL/WarLight.AI/blob/master/Prod/BotMain.cs#L142 makes mistakes in no-luck straight round with some offensive kill rates.

With a 35% offensive kill rate, the function tels the bot that 11 armies are needed to kill 4 armies when 10 are enough. See https://www.warlight.net/MultiPlayer?GameID=12488449 for an AI (grey) attacking 4s with 11.

Couldn't that function just use the formula used to display: image

I think that would be something like rounding up (defenseArmies.DefensePower - 0.5) / Settings.OffenseKillRate so var ret = SharedUtility.Ceiling((defenseArmies.DefensePower - 0.5) / Settings.OffenseKillRate);

Sadly, this would make the logic for weighted-random not work well below 50% kill rate. https://github.com/FizzerWL/WarLight.AI/blob/master/Prod/BotMain.cs#L148 means it would at most attack with one more than in straight round, which isn't right.

For instance with a 10% offensive kill rate, 5 troops kill 1 army in straight round. Current Algorithm tells the bot that it should attack with 10 troops in straight round, and 10 or 11 in weighted random. In weighted random, 10 would kill 1 army 100% of the time, which is great. With my correction, it would tell the bot that it should attack with 5 in straight round and 5 or 6 in weighted random. In weighted random, 5 would kill 1 army 50% of the time, 6 would kill 1 army 60% of the time.

FizzerWL commented 7 years ago

Due to the nature of the way computers do floating point math, there will always be edge cases where a slightly wrong value is calculated. The best solution to this is to simply use a higher precision floating point or more accurate number system. But honestly, I think it's already close enough. If it's really a problem for you, I suggest modifying the luck level to eliminate the edge cases you care about most.

On Wed, Dec 14, 2016 at 12:53 PM, NewCompte notifications@github.com wrote:

https://github.com/FizzerWL/WarLight.AI/blob/master/Prod/BotMain.cs#L142 makes mistakes in no-luck straight round with some offensive kill rates.

With a 35% offensive kill rate, the function tels the bot that 11 armies are needed to kill 4 armies when 10 are enough. See https://www.warlight.net/MultiPlayer?GameID=12488449 for an AI (grey) attacking 4s with 11.

Couldn't that function just use the formula used to display: [image: image] https://cloud.githubusercontent.com/assets/6410917/21199417/bc2e64b8-c243-11e6-91ac-97cb9677c88a.png

I think that would be something like rounding up (defenseArmies.DefensePower

  • 0.5) / Settings.OffenseKillRate so var ret = SharedUtility.Ceiling((defenseArmies.DefensePower - 0.5) / Settings.OffenseKillRate);

Sadly, this would make the logic for weighted-random not work well below 50% kill rate. https://github.com/FizzerWL/WarLight.AI/blob/master/Prod/BotMain.cs#L148 means it would at most attack with one more than in straight round, which isn't right.

For instance with a 10% offensive kill rate, 5 troops kill 1 army in straight round. Current Algorithm tells the bot that it should attack with 10 troops in straight round, and 10 or 11 in weighted random. In weighted random, 10 would kill 1 army 100% of the time, which is great. With my correction, it would tell the bot that it should attack with 5 in straight round and 5 or 6 in weighted random. 5 would kill 1 army 50% of the time, 6 would kill 1 army 60% of the time.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/FizzerWL/WarLight.AI/issues/7, or mute the thread https://github.com/notifications/unsubscribe-auth/ACckw6ZyZLIheZIamKQoNO2bQFguwbxtks5rIFdVgaJpZM4LNZrK .

NewCompte commented 7 years ago

This is not a problem with floating point math, this is just a wrong formula. For instance, as I have already said, with 1 defending army at 10% kill rate, the current formula tells the AI that 10 armies are needed to kill, when 5 are enough.

https://www.warlight.net/Forum/223502-bug-90troop-attack-35-killrate is a floating point math problem.