Skip to content
This repository has been archived by the owner on Jun 7, 2022. It is now read-only.

Reconsider Snake growth logic. #33

Open
46bit opened this issue Jan 9, 2017 · 1 comment
Open

Reconsider Snake growth logic. #33

46bit opened this issue Jan 9, 2017 · 1 comment
Assignees

Comments

@46bit
Copy link
Member

46bit commented Jan 9, 2017

@Taneb has suggested that instead of storing a previous tail cell, snake growth is handled by setting a boolean flag to indicate growing the snake on the next turn.

turnN: has a snakeA controlled by playerA.
moveN: playerA moves onto a cell that contains food1.
turnN+1:

  • snakeA has moved to have the head on that food1 cell.
  • food1 has been removed and a new food spawned.

moveN: playerA chooses any move.
turnN+2:

  • snakeA's head has performed that move.

  • snakeA's previous rear segment has advanced by 1.

  • a new segment has been added to snakeA where that rear segment was.

Assess implications for collision detection. These rules need clearly encoding so AIs can be created that correctly reason about the world.

@46bit
Copy link
Member Author

46bit commented Jan 9, 2017

@Taneb maybe you could take this one on? It's entirely in the synchronous codebase so you shouldn't have to worry about Futures at all.

The field storing the previous tail cell is Snake::previous_tail https://github.com/sirpent-team/sirpent-rust/blob/master/src/snake.rs#L7-L8. Snake::grow performs the growth.

At present Game::snake_eating https://github.com/sirpent-team/sirpent-rust/blob/master/src/game.rs#L147-L157 is used to grow the snake immediately when a food is eaten. For context, snake_eating takes a TurnState that we're transitioning to. The self.turn_state during its execution is the turn being transitioned from.

Both methods and that field will want some changes, at least. The actual delayed snake growth should happen in Game::advance_turn around the same time as snake_movement. I'd suggest performing snake_movement then growing snakes then doing remove_snakes.

Hopefully this helps.

@Taneb Taneb self-assigned this Jan 9, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants