jkomoros / boardgame

An in-progress framework in golang to easily build boardgame Progressive Web Apps
Apache License 2.0
31 stars 4 forks source link

Create a Board property type #603

Open jkomoros opened 6 years ago

jkomoros commented 6 years ago

Noted while exploring #550, and in this exploration: https://github.com/jkomoros/boardgame/wiki/Representing-spaces

To represent Spaces, which may have 1 to n items in them properly, you need a GrowableStack for each logical space. Things like having a separate SizedStack for each Player are an illusion, because that only works to the extent each user has a single component that could be placed.

For a board with 5 spaces, you could image encoding 5 growable stacks manually:

type gameState struct {
  Space0 boardgame.MutableStack `stack:"Tokens"`
  Space1 boardgame.MutableStack `stack:"Tokens"`
  Space2 boardgame.MutableStack `stack:"Tokens"`
}

But that's extremely annoying.

Basically a Board is a property type that is exactly equivalent to a fixed array of GrowableStacks.

The growable stacks might have a maxlen on all of them at the same time, (e.g. if only one player may be in each one, or if only up to two tokens may be in a single space). But if you want something more complicated than that (e.g. only one token of a given color in a board space at a time, then you have to encode that in Move.Legal() logic).

jkomoros commented 6 years ago
type gameState struct {
  Spaces boardgame.MutableBoard `size:"64" stack:"Tokens,2"`
}

Do we need a separate Board and MutableBoard? And theoretically the thing you get back from them is literally a GrowableStack.

And how does a given component know which spot it's in? Conceptually each stack grows a Board reference, if it's part of a board, and also a BoardIndex. So a component can figure out which stack it's in, which then allows it to figure out what space index it's in.

jkomoros commented 6 years ago

Also note: given a ref to a component (and a State) it's actually not possible to (efficiently) determine which Stack it's in currently. That implies some kind of state-wide index that is updated.

jkomoros commented 6 years ago

Should boards be resizable, like Stacks are? Obviously the stacks to be removed would have to be empty.

Conceptually they are like a SizedStack of GrowableStacks, except that having them literally be that is unnecessary.

jkomoros commented 6 years ago
type Board struct {
  spaces []Stack
}

func NewBoard(size int, deck *Deck) *Board {
}

func (b *Board) Spaces() []Stack {
  return b.spaces
}

func (b *Board) SpaceAt(index int) Stack {
  //TODO
}
jkomoros commented 6 years ago
jkomoros commented 6 years ago

Currently in branch "board"

jkomoros commented 6 years ago

Wait, if we have board, what's the way to stamp out the templates for the tokens? Monroe does it in a kind of weird way, where each component has its own stack. I guess the answer is fixing #604