davidje13 / koth-webplayer

Framework for King-of-the-Hill Javascript competitions
MIT License
7 stars 7 forks source link

Make queen food movement match reference implementation #23

Open davidje13 opened 6 years ago

davidje13 commented 6 years ago

This has been extracted from #22, squashed, and created as a new PR to allow discussion.

Before merging this, I would like to see the linter workaround removed. Should be easy to simplify this code once the meaning is clear, but right now I'm struggling to see how it's supposed to behave. Here's how I currently read it:

It seems a bit strange that it checks enemy ants then non-enemy ants for the queen case, but bundles them all together for the worker case. Is this correct behaviour? What does the reference implementation do?

dzaima commented 6 years ago

This is the code used in a port of the reference implementation that simulated seeded games perfectly. The reason the worker case isn't split up into two parts is because the cases are handled within the transferFood function, adding or subtracting food where necessary. The queen does fancy logic that I didn't try to simplify out of fear of mis-interpreting things.

davidje13 commented 6 years ago

The reason the worker case isn't split up into two parts is because the cases are handled within the transferFood function, adding or subtracting food where necessary

I see. I think with this change that function could be made dumber, and just become a take-food-from-ant-1-and-give-to-ant-2 behaviour.

Part of my confusion is the ordering though; if a queen moves we make sure all enemy ants finish stealing food before any friendly ants provide food, whereas when a worker moves the transfers simply happen in the order that the ants are found, regardless of friend/foe status (unchanged from the original behaviour in this project). I can check in the reference implementation how it was originally handled, but it seems strange that it's asymmetric.

Also I notice in your version it shuffles the order of checked squares. Is that required for a correct implementation? This PR doesn't do that.

dzaima commented 6 years ago

whereas when a worker moves the transfers simply happen in the order that the ants are found, regardless of friend/foe status

the worker will transfer only 1 food and then stop, and the direction the transfer will happen is determined by whether the worker already had food. But yeah, splitting it up would probably look better.

I can't quite remember from the tons of chat logs whether a shuffle there is necessary, but the reference does it so this should probably too.