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

Game state should track Gist owner for forking/editing logic #26

Closed
7 tasks done
LearningNerd opened this issue Jun 29, 2017 · 0 comments
Closed
7 tasks done

Game state should track Gist owner for forking/editing logic #26

LearningNerd opened this issue Jun 29, 2017 · 0 comments

Comments

@LearningNerd
Copy link
Member

LearningNerd commented Jun 29, 2017

Background:

Previously, I had opened issue #20, PR #25, and then issue #24, all because of an incorrect assumption: I thought that the Gist forking/editing logic depended on the state of the turn system (the previous and current player), but it's only indirectly related. The real condition to check is simply whether the current player owns the Gist or not!

Scenario illustrating the bug if multiple players disconnect on their turns:

  1. Three players are in the game, and Player 1 completes their turn. (Gist owner: Player 1)

  2. Player 2 disconnects before their turn ends. (Gist owner: Player 1)

  3. Player 3 also disconnects before their turn ends. (Gist owner: Player 1)

  4. Player 1 begins their turn, and they should not fork the Gist since they own it! But the game state looks like this: previous player is Player 3, current player is Player 1, and since they don't match, Player 1 should fork and edit the Gist. And that leads to an error from GitHub, because a user can't fork their own Gist!

Instead of starting from first principles and looking at the root of the other actions in this system, I got caught up in the tangled mess of secondary effects, treating the symptoms instead of the cause! I think the situation can be summed up well this way: instead of thinking of my app as one complicated state machine, it's actually more like two or three smaller state machines that communicate with each other. My code should reflect that!

Ultimate solution:

The best solution would be to close issue #21 ("Server should fork/edit Gists on behalf of disconnected users"), so that not only is this bug resolved, but there would also be the extra benefit of accurately giving each player credit for their work even if they're disconnected. (A pure client-side solution still can't solve that issue!)

Tasks for this issue (intermediary solution):

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

No branches or pull requests

1 participant