boardgame.io: Curious Flow: Second phase's onTurnBegin() is not calling

Hello, I’d like to use your impressive framework, but I met a strange situation.

Here’s my simplified code: https://github.com/ybbarng/boardgame-io-test/blob/master/src/App.js

In phase1, each turn is automatically ended because endTurn() is called in onTurnBegin(). Because the phase1’s TurnOrder is ONCE, the phase will be moved to next phase2. At this time, onTurnBegin() of phase2 is not calling. I hope someone figure out my mistake or explain why this happens.

Context when it stuck,

The log of console:

phase1 onPhaseBegin
phase1 onTurnBegin 0
phase1 onTurnEnd 0
phase1 onTurnBegin 1
phase1 onTurnEnd 1
phase1 onPhaseEnd
phase2 onPhaseBegin

The debug pannel:

G: {}
ctx: {
  "numPlayers": 2,
  "turn": 2,
  "currentPlayer": "0",
  "actionPlayers": [
    "0"
  ],
  "currentPlayerMoves": 0,
  "playOrder": [
    "0",
    "1"
  ],
  "playOrderPos": 0,
  "stats": {
    "turn": {
      "numMoves": {},
      "allPlayed": false
    },
    "phase": {
      "numMoves": {},
      "allPlayed": false
    }
  },
  "allPlayed": false,
  "phase": "phase2",
  "prevPhase": "phase1",
  "allowedMoves": null
}

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 19 (11 by maintainers)

Most upvoted comments

If you ever want to subdivide a turn into multiple “phases”, you should use stages. phases are for general game phases inside which multiple turns are played. stages are different parts of a single turn.

import { ActivePlayers } from 'boardgame.io/core'

const game = {
  turn: {
    activePlayers: {
      currentPlayer: 'A',  // put the player in Stage A at the beginning of the turn
    },

    stages: {
      A: {
        moves: {
          moveA: (G, ctx) => {
            ...

            // move the player to Stage B.
            ctx.events.setActivePlayers({ currentPlayer: 'B' });
          },
        },
      },

      B: {
        moves: { ... },
      },
    }
  }
}

npm run prepack was what I was missing, thanks.

FWIW here is the error I was seeing trying to reference the git branch directly. This was after installing cross-env globally:

> cross-env BABEL_ENV=rollup rollup --config rollup.npm.js

events.js:186
      throw er; // Unhandled 'error' event
      ^

Error: spawn rollup ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:264:19)
    at onErrorNT (internal/child_process.js:456:16)
    at processTicksAndRejections (internal/process/task_queues.js:77:11)
Emitted 'error' event on ChildProcess instance at:
    at Process.ChildProcess._handle.onexit (internal/child_process.js:270:12)
    at onErrorNT (internal/child_process.js:456:16)
    at processTicksAndRejections (internal/process/task_queues.js:77:11) {
  errno: 'ENOENT',
  code: 'ENOENT',
  syscall: 'spawn rollup',
  path: 'rollup',
  spawnargs: [ '--config', 'rollup.npm.js' ]
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! boardgame.io@0.32.1 build: `cross-env BABEL_ENV=rollup rollup --config rollup.npm.js`
npm ERR! Exit status 1

@delucis You can use moveLimit: 1 for the “main” phase to make the code more idiomatic:

import { ActivePlayers } from 'boardgame.io/core'

const game = {
  phases: {
    setup: {
      start: true,                              // the game should start in this phase
      next: 'main',                             // move to “main" after this phase

      turn: {
        activePlayers: ActivePlayers.ALL_ONCE   // all players can play once
      },

      moves: {
        setupMove: (G, ctx) => {},
        pass: G => G
      },

      endIf: (G, ctx) => ctx.activePlayersDone, // end phase when all players have played

    },

    main: {
      turn: {
        moveLimit: 1    // end turn after one move
      },

      moves: {
        // ...
      },
    },
  },
}

@gadamgrey What errors are you seeing when you run npm -i git://..?

@delucis that snippet is very helpful. I don’t have code to share at the moment but if I still get stuck I will prepare an example. Thank you!

I’m working on this presently, so it should be fixed in the next couple of weeks or so.

This is a bug that will be fixed as part of the Phases overhaul described here.