Skip to content

Conversation

@davidje13
Copy link
Owner

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:

  • An ant moves
  • If the ant lands on food, it picks it up
  • If the ant is a queen:
    • Look for enemy ants nearby. Each enemy gets to steal 1 food.
    • After all enemy ants have been checked, now look for own-team worker ants. Each worker gets to provide 1 food (since this check happens after all enemy checks, food will never go from a friendly worker to an unfriendly worker in a single step)
  • If the ant is not a queen:
    • Look for any queen ants nearby of either team. Either provide or steal food as appropriate.

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
Copy link
Contributor

dzaima commented Aug 19, 2018

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
Copy link
Owner Author

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
Copy link
Contributor

dzaima commented Aug 21, 2018

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.

@davidje13 davidje13 force-pushed the formic-reference-implementation branch from a1b4949 to 818c430 Compare August 27, 2018 22:22
@davidje13 davidje13 force-pushed the formic-reference-implementation branch from 818c430 to d5fb388 Compare September 8, 2018 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants