Game Engine Life Cycle - non-player-games/contest-framework GitHub Wiki

Introduction

Game engine life cycle message flow from tournament manager.

Message flow:

  1. Send onCreate to bots and game engine with list of players (player id and name)
  • Game player clients and game engine will respond with ack
  1. Send onStart to game engine
  • Decide purpose later
  1. Send getState to game engine with single player id (maybe with game player client id one by one)
  • Game engine responds with current game state for certain game player client
  1. Proxy this game state to each game player client via turnStart
  • Game client responds back with their move
  1. Proxy moves to game engine via processMoves (with all player moves)
  2. Game engine may respond with turnStart (go back to step 3) or gameFinish with game outcome

To game engine

{
  "action": "onCreate | onStart | getState | processMoves",
  "payload": {
    // whatever
  }
}

More Detail

1. onCreate

  gameEngine <- manager
  {
    type: 'onCreate'
  }

  manager <- gameEngine
  {
    gid: 0
  }

2. onStart

noop

3. getState

  gameEngine <- manager
  {
    type: 'getState',
    payload: {
      gid: 0,
      pid: 0
    }
  }

  manager <- gameEngine
  {
    // state for player
  }

4. turnStart

  botClient <- manager
  {
    type: 'turnStart',
    payload: {
      // state from game engine
    }
  }

  manager <- botClient
  {
    // move 
  }

5. processMove

  gameEngine <- manager
  {
    type: 'processMove',
    payload: {
      gid: 0,
      moves: [
        {
          // move from bot 1
          pid: 0,
          move: { }
        },
        {
          // move from bot 2
          pid: 0,
          move: { }
        },
        // ...
      ]
    }
  }

  manager <- gameEngine
  {
    type: 'turnStart',
    payload: {
      gid: 0,
      players: [
        {
          pid: 0,
          health: 'okay'
        },
        {
          pid: 1,
          health: 'killed | dead',
          reason?: 'bad move'
        }
      ]
    }
  }
  {
    type: 'gameFinish',
    // turn start goes back to step 4,
    // game finish with payload as outcome
    payload: {
        gid: 0,
        scores: [
        // outcome if game is finished
        {
          pid: 1,
          score: 100
        },
        {
          pid: 2,
          score: 94
        },
        // ... with score to indicate win or lose
      ]
    }
  }