Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Go Demo: Refactor View State #20

Open
gcentauri opened this issue Dec 9, 2020 · 0 comments
Open

Go Demo: Refactor View State #20

gcentauri opened this issue Dec 9, 2020 · 0 comments
Labels
good first issue Good for newcomers

Comments

@gcentauri
Copy link
Contributor

gcentauri commented Dec 9, 2020

View State

The View Component does not need the entire state represented in the Go::Game object. It only needs enough information to display the state of the game that is relevant in the browser. This is the position of the stones, the current player, and the captured stones.

We can represent the position of the stones as an Array of length 81 for the 9x9 board. The initial game state will have an array of nil and as stones are added to the board, the symbols :black and :white will be used to mark where to display them. The Black player goes first, and we have zero captures at the start of the game, so the inital state could look something like this:

    {
      positions: Array.new(81),
      current: :black,
      captures: { black: 0, white: 0 }
    }

For now, this is all we need to draw the display of the game, and we can use this data structure (either a hash like this or a Struct) in our View Component hooked into Motion.

As of right now, the code does not implement this. Instead it passes an entire Go::Game object to the View Component. This is due to the way updating the game state and checking legal moves is implemented. Detangling these would be a great improvement. The view component can update its state and then ask the game logic if it is a legal state before updating the "central" server state that all of the view components will use to

@gcentauri gcentauri added the good first issue Good for newcomers label Dec 9, 2020
@gcentauri gcentauri added this to the Loco-Motion 2020 milestone Dec 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant