question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Turn goes twice when phase is end

See original GitHub issue

Hi, I’m facing a problem. I set endTurnIf hook to always return true. When phase is end, it seems that the turn automatically goes twice.

  • ctx.turn is added by 2
  • ctx.currentPlayer goes twice

I’ve not dug deeply yet, but I found that the endTurn event is dispatched in function endPhaseEvent and endPhase event is dispatched in function endTurnEvent in src/core/flow.js . I feel the former should be removed. What do you think?

Reproduce steps

Here’s minimum code for reproducing. Prepares a project as tutorials, then rewrites src/App.js as follows:

import { Client } from 'boardgame.io/react';
import { Game, TurnOrder } from 'boardgame.io/core';

const Foo = Game({
  setup: () => {
    return {
      players: {
        '0': { },
        '1': { },
      },
    };
  },

  moves: {
    skip: (G) => G,
  },
  flow: {
    turnOrder: TurnOrder.DEFAULT,
    endTurnIf: () => true,
    phases: [
      {
        name: 'a',
        allowedMoves: ['skip'],
        endPhaseIf: (G, ctx) => ctx.turn === 2,
      },
      {
        name: 'b',
      },
    ],
  }
});

const App = Client({
  game: Foo,
});

export default App;

then run npm start, and open the web cli (localhost:3000).

then,

  • initial state => turn is 0. currentPlayer is 0.
  • do skip() => turn is 1. currentPlayer is 1.
  • do skip() => turn is 3 (expected to 2). currentPlayer is 1 (expected to 0).

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
nicolodaviscommented, May 10, 2018

Fixed now (will be available in the next release). Thanks again for the report!

1reaction
nicolodaviscommented, May 8, 2018

Thanks for the report (and especially for the steps to reproduce)! Will take a look in the next couple of days.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Turn goes twice when phase is end · Issue #193 - GitHub
Hi, I'm facing a problem. I set endTurnIf hook to always return true. When phase is end, it seems that the turn automatically...
Read more >
Ending turns and phases - MTG Wiki - Fandom
To “end the turn” as the result of an effect is to perform an expedited process that skips nearly everything else that would...
Read more >
Traffic Signal Timing Manual: Chapter 4 - Office of Operations
The most commonly used left-turn phase sequence is the "lead-lead" sequence which has both opposing left-turn phases starting at the same time.
Read more >
Phases of the cell cycle (article) | Khan Academy
The cell goes through 4 steps (prophase, metaphase, anaphase, and telophase.) The cells at the end of the process also have the same...
Read more >
Ruleshammer: Unusual Fight Phases, what units come first ...
Lastly if there's a combination of a “Fight Again at End” and “Fight Twice” abilities then those units can fight twice again, potentially...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found