Re:Go Concurrency Patterns: Pipelines and cancellation
by AYBABTME on Thursday March 13, 2014 @07:12PM
(#7395797)
I've cleanly used that in a lil' game I'm working on.
Players send their move to the game on a channel they expose through Move(). They
receive regular updates of the game state on a channel they expose through Update().
type Player interface {
Name() string
Move() <-chan Move
Update() chan<- State
}
Players send their move to the game on a channel they expose through Move(). They receive regular updates of the game state on a channel they expose through Update().
> https://github.com/aybabtme/bomberman/blob/master/player/pla...The game reads the player moves, if moves are available[1]:
> https://github.com/aybabtme/bomberman/blob/master/bomberman....The game sends each turn's update to players that are ready to listen for it:
> https://github.com/aybabtme/bomberman/blob/master/bomberman....This leans to surprisingly clean implementations:
Note that the rest of the game (`bomberman.go`) is a hairy ball that needs refactoring.[1]: this, to prevent an unresponsive player from hanging the game, or an AI player from unfairly computing longer than it's opponent
[2]: https://github.com/aybabtme/bomberweb/blob/master/player/pla...
[3]: https://github.com/aybabtme/bomberman/blob/master/player/inp...
[4]: https://github.com/aybabtme/bomberman/blob/master/player/ai/...