SlideShare uma empresa Scribd logo
1 de 23
Focus on : BGA Game state machin
Why a game state
                                           machine?


Because game states will make your life easier.
In all board games, you have to play actions in a specific order : do this is phase 1, then do this
in phase 2, then in phase 3 you can do actions A, B or C, ...

With BGA Studio framework you specify a finite-state machine for your game. This state
machine allows you to structure and to implement the rules of a game very efficiently.

Understanding game states is essential to develop a game on Board Game Arena platform.
What is a game state
                                        machine?

                                                      gameSetup

A simple game state machine diagram with 4
different game states is displayed on the right.

This machine correspond for example to chess          playerTurn
game, or reversi (BGA Studio example) game :
_ the game start.
_ a player plays one move.
_ we jump to the next player (opponent's of the
previous player).                                     nextPlayer
_ … we loop until one player can't play, then it is
the end of the game


                                                      gameEnd
Game state & BGA



Game states is a central piece in the BGA framework.

Depending on which game state a specific game is right now, the BGA platform is going to :
● Decide which text is to be displayed in the status bar.

● Allow some player actions (and forbid some others).

● Determine which players are « active » (ie : it is their turn).

● Trigger some automatic game actions on server (ex : apply some automatic card effect).

● Trigger some game interface adaptations on client side (in Javascript).

● … and of course, determine what are the next possible game states.
Define your game state
                                     machine
You can define the game state machine of your game in your states.inc.php file.

Your game state machine is basically a PHP associative array. Each entry correspond to a game
state of your game, and each entry key correspond to the game state id.

Two game states are particular (and shouldn't be edited) :
● GameSetup (id = 1) is the game state active when your game is starting.

● GameEnd (id=99) is the game state you have to active when the game is over.
Game state types

There are 4 different game state types :

● Activeplayer
● Multipleactiveplayer

● Game

● Manager




When the current game state's type is activeplayer, only 1 player is active (it is the turn of only
one player, and it is the only one allowed to do some player action).

When the current game state's type is multipleactiveplayer, several players are active at the
same time, and can perform some player actions simultaneously.

When the current game state's type is game, no player is active. This game state is used to
perform some automatic action on server side (ex : jump to next player). This is an unstable
state : you have to jump to another game state automatically when executing the code
associated with this type of state.

You don't have to care about « Manager » game state type : only « gameSetup » and
« gameEnd » state are using this type.
Game state types

                                                   GameSetup
                                                (type = manager)



                                                    PlayerTurn
                                               (type = activeplayer)
Here is the previous example with game state
types :

                                                    NextPlayer
                                                  (type = game)



                                                    GameEnd
                                                (type = manager)
Focus on : Active player
In a board game, most of the time, everyone plays when it's his turn
to play. This is why we have in BGA framework the concept of
active player.

Basically, the active player is the player whose turn it is.

When a player is active, and when the current game state's type is
« activeplayer », the following things happened :

● Active player's icon in his game panel is changed into a hourglass
icon.
● Active player's time to think starts decreasing.

● If the active player wasn't active before, the « it's your turn »

sound is played.


Pay attention : active player != current player

In BGA framework, the current player is the player who played the current player action (=
player who made the AJAX request). Most of the time, the current player is also the active player,
but in some context this could be wrong.
Game state functions

Now, let's have a look at all you
can do with game states, with
one of our game example
« Reversi ».
Game state machine
                                                               example : Reversi
At first, here's the « states.inc.php » file for Reversi, that correspond to
the diagram on the right. We're going to explain it now.
 1 => array(
    "name" => "gameSetup",
    "description" => clienttranslate("Game setup"),
    "type" => "manager",
    "action" => "stGameSetup",                                                      GameSetup
    "transitions" => array( "" => 10 )
 ),

 10 => array(
    "name" => "playerTurn",
    "description" => clienttranslate('${actplayer} must play a disc'),
    "descriptionmyturn" => clienttranslate('${you} must play a disc'),
    "type" => "activeplayer",
                                                                                    playerTurn
    "args" => "argPlayerTurn",
    "possibleactions" => array( 'playDisc' ),
    "transitions" => array( "playDisc" => 11, "zombiePass" => 11 )
 ),

 11 => array(
    "name" => "nextPlayer",                                                         nextPlayer
    "type" => "game",
    "action" => "stNextPlayer",
    "updateGameProgression" => true,
    "transitions" => array( "nextTurn" => 10, "cantPlay" => 11, "endGame" => 99 )
 ),

 99 => array(                                                                       gameEnd
   "name" => "gameEnd",
   "description" => clienttranslate("End of game"),
   "type" => "manager",
   "action" => "stGameEnd",
   "args" => "argGameEnd"
 )
Game state function 1/6 :
                                                   transitions
« Transition » argument specify « paths » between game states, ie how you can jump from one
game state to another.

Example with «nextPlayer» state is Reversi :
  11 => array(
    "name" => "nextPlayer",
    "type" => "game",
    "action" => "stNextPlayer",
    "updateGameProgression" => true,
       "transitions" => array( "nextTurn" => 10, "cantPlay" => 11, "endGame" => 99 )
  ),

In the example above, if the current game state is « nextPlayer », the next game state could be
one of the following : 10 (playerTurn), 11 (nextPlayer, again), or 99 (gameEnd).

The strings used as keys for the transitions argument defines the name of the transitions. The
transition name is used when you are jumping from one game state to another in your PHP.

Example : if current game state is « nextPlayer » and if you do the following in your PHP :
$this->gamestate->nextState( 'nextTurn' );

… you are going to use transition « nextTurn », and then jump to game state 10 (=playerTurn)
according to the game state definition above.
Game state function 1/6 :
                                    transitions

                                                                   gameSetup
You can see on the right the transitions displayed on
the diagram.

If you design your game states and game state                      playerTurn
transitions carefully, you are going to save a lot of
time programming your game.                                         playDisc
                                                        nextTurn
Once a good state machine is defined for a game,
you can start to concentrate yourself on each of the               nextPlayer   cantPlay
specific state of the game, and let BGA Framework
take care of navigation between game states.                       endGame


                                                                   gameEnd
Game state function 2/6 :
                                                           description
When you specify a « description » argument in your game state, this description is displayed in
the status bar.

Example with « playerTurn » state is Reversi :
 10 => array(
   "name" => "playerTurn",
        "description" => clienttranslate('${actplayer} must play a disc'),
      "descriptionmyturn" => clienttranslate('${you} must play a disc'),
      "type" => "activeplayer",
      "args" => "argPlayerTurn",
      "possibleactions" => array( 'playDisc' ),
      "transitions" => array( "playDisc" => 11, "zombiePass" => 11 )
 ),
Game state function 2/6 :
                                                       descriptionmyturn
When you specify a « descriptionmyturn » argument in your game state, this description takes
over the « description » argument in the status bar when the current player is active.

Example with « playerTurn » state is Reversi :
 10 => array(
   "name" => "playerTurn",
   "description" => clienttranslate('${actplayer} must play a disc'),
        "descriptionmyturn" => clienttranslate('${you} must play a disc'),
      "type" => "activeplayer",
      "args" => "argPlayerTurn",
      "possibleactions" => array( 'playDisc' ),
      "transitions" => array( "playDisc" => 11, "zombiePass" => 11 )
 ),
Game state function 3/6 :
                          game interface adaptations
Game states are especially useful on server side to implement the rules of the game, but they
are also useful on client side (game interface) too.

3 Javascript methods are directly linked with gamestate :
● « onEnteringState » is called when we jump into a game state.

● « onLeavingState » is called when we are leaving a game state.

● « onUpdateActionButtons » allows you to add some player action button in the status bar

depending on current game state.



Example 1 : you can show some <div> element (with dojo.style method) when entering into a
game state, and hide it when leaving.

Example 2 : in Reversi, we are displaying possible move when entering into « playerTurn » game
state (we'll tell you more about this example later).

Example 3 : in Dominion, we add a « Buy nothing » button on the status bar when we are in the
« buyCard » game state.
Game state function 4/6 :
                                                           possibleactions
« possibleactions » defines what game actions are possible for the active(s) player(s) during
the current game state. Obviously, « possibleactions » argument is specified for activeplayer and
multipleactiveplayer game states.

Example with « playerTurn » state is Reversi :
 10 => array(
   "name" => "playerTurn",
   "description" => clienttranslate('${actplayer} must play a disc'),
   "descriptionmyturn" => clienttranslate('${you} must play a disc'),
   "type" => "activeplayer",
   "args" => "argPlayerTurn",
      "possibleactions" => array( 'playDisc' ),
      "transitions" => array( "playDisc" => 11, "zombiePass" => 11 )
 ),




Once you define an action as « possible », it's very easy to check that a player is authorized to
do some game action, which is essential to ensure your players can't cheat :

From your PHP code :
 function playDisc( $x, $y )
 {
    // Check that this player is active and that this action is possible at this moment
      self::checkAction( 'playDisc' );



From your Javacript code :
        if( this.checkAction( 'playDisc' ) )   // Check that this action is possible at this moment
        {
Game state function 4/6 :
                                                            action
«action» defines a PHP method to call each time the game state become the current game
state. With this method, you can do some automatic actions.

In the following example with the « nextPlayer » state in Reversi, we jump to the next player :
 11 => array(
   "name" => "nextPlayer",
   "type" => "game",
        "action" => "stNextPlayer",
      "updateGameProgression" => true,
      "transitions" => array( "nextTurn" => 10, "cantPlay" => 11, "endGame" => 99 )
 ),

In reversi.game.php :
 function stNextPlayer()
 {
    // Active next player
    $player_id = self::activeNextPlayer();
    …

A method called with a « action » argument is called « game state reaction method ». By
convention, game state reaction method are prefixed with « st ».
Game state function 4/6 :
                                                          action
In Reversi example, the stNextPlayer method :
● Active the next player

● Check if there is some free space on the board. If there is not, it jumps to the gameEnd state.

● Check if some player has no more disc on the board (=> instant victory => gameEnd).

● Check that the current player can play, otherwise change active player and loop on this

gamestate (« cantPlay » transition).
● If none of the previous things happened, give extra time to think to active player and go to the

« playerTurn » state (« nextTurn » transition).

 function stNextPlayer()
 {
    // Active next player
    $player_id = self::activeNextPlayer();

   // Check if both player has at least 1 discs, and if there are free squares to play
   $player_to_discs = self::getCollectionFromDb( "SELECT board_player, COUNT( board_x )
                                  FROM board
                                  GROUP BY board_player", true );

   if( ! isset( $player_to_discs[ null ] ) )
   {
       // Index 0 has not been set => there's no more free place on the board !
       // => end of the game
       $this->gamestate->nextState( 'endGame' );
       return ;
   }
   else if( ! isset( $player_to_discs[ $player_id ] ) )
   {
       // Active player has no more disc on the board => he looses immediately
       $this->gamestate->nextState( 'endGame' );
       return ;
Game state function 5/6 :
                                       args
From time to time, it happens that you need some information on the client side (ie : for your
game interface) only for a specific game state.

Example 1 : for Reversi, the list of possible moves during playerTurn state.
Example 2 : in Caylus, the number of remaining king's favor to choose in the state where the
player is choosing a favor.
Example 3 : in Can't stop, the list of possible die combination to be displayed to the active player
in order he can choose among them.




In such a situation, you can specify a method name as the « args » argument for your game
state. This method must get some piece of information about the game (ex : for Reversi, the
possible moves) and return them.

Thus, this data can be transmitted to the clients and used by the clients to display it.

Let's see a complete example using args with « Reversi » game :
Game state function 5/6 :
                                                                args
In states.inc.php, we specify some « args » argument for gamestate « playerTurn » :
 10 => array(
   "name" => "placeWorkers",
   "description" => clienttranslate('${actplayer} must place some workers'),
   "descriptionmyturn" => clienttranslate('${you} must place some workers'),
   "type" => "activeplayer",
        "args" => "argPlaceWorkers",
      "possibleactions" => array( "placeWorkers" ),
      "transitions" => array( "nextPlayer" => 11, "nextPhase" => 12, "zombiePass" => 11 )
 ),



It corresponds to a « argPlaceWorkers » method in our PHP code (reversi.game.php):
 function argPlayerTurn()
 {
    return array(
       'possibleMoves' => self::getPossibleMoves()
    );
 }



Then, when we enter into « playerTurn » game state on the client side, we can highlight the
possible moves on the board using information returned by argPlayerTurn :
      onEnteringState: function( stateName, args )
      {
        console.log( 'Entering state: '+stateName );

        switch( stateName )
        {
        case 'playerTurn':
          this.updatePossibleMoves( args.args.possibleMoves );
          break;
        }
Game state function 6/6 :
                                                    updateGameProgression
When you specify « updateGameProgression » in a game state, you are telling the BGA
framework that the « game progression » indicator must be updated each time we jump into this
game state.

Consequently, your « getGameProgression » method will be called each time we jump into this
game state.


Example with «nextPlayer» state is Reversi :
 11 => array(
   "name" => "nextPlayer",
   "type" => "game",
   "action" => "stNextPlayer",
        "updateGameProgression" => true,
      "transitions" => array( "nextTurn" => 10, "cantPlay" => 11, "endGame" => 99 )
 ),
Game states tips

Specifying a good state machine for your game is essential while working with BGA Framework.
Once you've designed your state machine and after you've added corresponding « st », « arg »
and « player action » methods on your code, your source code on server side is well organized
and you are ready to concentrate yourself on more detailled part of the game.

Usually, it's better to start designing a state machine on paper, in order to visualize all the
transitions. A good pratice is to read the game rules while writing on a paper all possible different
player actions and all automatic actions to perform during a game, then to check if it correspond
to the state machine.

Defining a new game state is very simple to do : it's just configuration! Consequently, don't
hesitate to add as many game states as you need. In some situation, add one or two additional
game states can simplfy the code of your game and make it more reliable. For example, if there
are a lot of operations to be done at the end of a turn with a lot of conditions and branches, it is
probably better to split these operations among several « game » type's game state in order to
make your source code more clear.
Summary



●   You know how to design and how to specify a game state machine for your game.

●You know how to use game states to structure and organize your source code, in
order you can concentrate yourself on each part.

●You know how to use all game states built-in functionnalities to manage active
players, status bar and game progression.

Mais conteúdo relacionado

Mais procurados

10 page pitch for game design
10 page pitch for game design10 page pitch for game design
10 page pitch for game designTom Carter
 
Game monetization: Overview of monetization methods for free-to-play games
Game monetization: Overview of monetization methods for free-to-play gamesGame monetization: Overview of monetization methods for free-to-play games
Game monetization: Overview of monetization methods for free-to-play gamesAndrew Dotsenko
 
Game Design Document - Step by Step Guide
Game Design Document - Step by Step GuideGame Design Document - Step by Step Guide
Game Design Document - Step by Step GuideDevBatch Inc.
 
Introduction to game development
Introduction to game developmentIntroduction to game development
Introduction to game developmentGaetano Bonofiglio
 
Game Development Step by Step
Game Development Step by StepGame Development Step by Step
Game Development Step by StepBayu Sembada
 
The History of Game Consoles
The History of Game ConsolesThe History of Game Consoles
The History of Game Consolescr4sh0ver
 
Game project Final presentation
Game project Final presentationGame project Final presentation
Game project Final presentationgemmalunney
 
[PandoraCube] 게임 기획자 면접 시 가장 많이 하는 질문들과 나의 답
[PandoraCube] 게임 기획자 면접 시 가장 많이 하는 질문들과 나의 답[PandoraCube] 게임 기획자 면접 시 가장 많이 하는 질문들과 나의 답
[PandoraCube] 게임 기획자 면접 시 가장 많이 하는 질문들과 나의 답PandoraCube , Sejong University
 
The Principles of Game Design
The Principles of Game DesignThe Principles of Game Design
The Principles of Game DesignInstantTechInfo
 
게임 기획 튜토리얼 (2015 개정판)
게임 기획 튜토리얼 (2015 개정판)게임 기획 튜토리얼 (2015 개정판)
게임 기획 튜토리얼 (2015 개정판)Lee Sangkyoon (Kay)
 
Proposal of 3d GAME Final Year Project
Proposal of  3d GAME Final Year ProjectProposal of  3d GAME Final Year Project
Proposal of 3d GAME Final Year Projectfahim shahzad
 
Gaming console technology 2017 ppt
Gaming console technology 2017 ppt Gaming console technology 2017 ppt
Gaming console technology 2017 ppt keshav kumar
 
Game development life cycle
Game development life cycleGame development life cycle
Game development life cycleSarah Alazab
 
Game development Pre-Production
Game development Pre-ProductionGame development Pre-Production
Game development Pre-ProductionKevin Duggan
 
Introduction to the Theory of Game Elements
Introduction to the Theory of Game ElementsIntroduction to the Theory of Game Elements
Introduction to the Theory of Game ElementsAki Järvinen
 
LAFS Game Mechanics - The Core Mechanic
LAFS Game Mechanics - The Core MechanicLAFS Game Mechanics - The Core Mechanic
LAFS Game Mechanics - The Core MechanicDavid Mullich
 

Mais procurados (20)

10 page pitch for game design
10 page pitch for game design10 page pitch for game design
10 page pitch for game design
 
Game design doc template
Game design doc   templateGame design doc   template
Game design doc template
 
Video game proposal
Video game proposalVideo game proposal
Video game proposal
 
Game monetization: Overview of monetization methods for free-to-play games
Game monetization: Overview of monetization methods for free-to-play gamesGame monetization: Overview of monetization methods for free-to-play games
Game monetization: Overview of monetization methods for free-to-play games
 
Game Design Document - Step by Step Guide
Game Design Document - Step by Step GuideGame Design Document - Step by Step Guide
Game Design Document - Step by Step Guide
 
Introduction to game development
Introduction to game developmentIntroduction to game development
Introduction to game development
 
Game Development Step by Step
Game Development Step by StepGame Development Step by Step
Game Development Step by Step
 
The History of Game Consoles
The History of Game ConsolesThe History of Game Consoles
The History of Game Consoles
 
Game project Final presentation
Game project Final presentationGame project Final presentation
Game project Final presentation
 
[PandoraCube] 게임 기획자 면접 시 가장 많이 하는 질문들과 나의 답
[PandoraCube] 게임 기획자 면접 시 가장 많이 하는 질문들과 나의 답[PandoraCube] 게임 기획자 면접 시 가장 많이 하는 질문들과 나의 답
[PandoraCube] 게임 기획자 면접 시 가장 많이 하는 질문들과 나의 답
 
Introduction to Game Design
Introduction to Game DesignIntroduction to Game Design
Introduction to Game Design
 
The Principles of Game Design
The Principles of Game DesignThe Principles of Game Design
The Principles of Game Design
 
게임 기획 튜토리얼 (2015 개정판)
게임 기획 튜토리얼 (2015 개정판)게임 기획 튜토리얼 (2015 개정판)
게임 기획 튜토리얼 (2015 개정판)
 
Proposal of 3d GAME Final Year Project
Proposal of  3d GAME Final Year ProjectProposal of  3d GAME Final Year Project
Proposal of 3d GAME Final Year Project
 
Game design document
Game design document Game design document
Game design document
 
Gaming console technology 2017 ppt
Gaming console technology 2017 ppt Gaming console technology 2017 ppt
Gaming console technology 2017 ppt
 
Game development life cycle
Game development life cycleGame development life cycle
Game development life cycle
 
Game development Pre-Production
Game development Pre-ProductionGame development Pre-Production
Game development Pre-Production
 
Introduction to the Theory of Game Elements
Introduction to the Theory of Game ElementsIntroduction to the Theory of Game Elements
Introduction to the Theory of Game Elements
 
LAFS Game Mechanics - The Core Mechanic
LAFS Game Mechanics - The Core MechanicLAFS Game Mechanics - The Core Mechanic
LAFS Game Mechanics - The Core Mechanic
 

Semelhante a BGA Studio - Focus on BGA Game state machine

Adversarial Search
Adversarial SearchAdversarial Search
Adversarial SearchMegha Sharma
 
Tic tac toe c++ programing
Tic tac toe c++ programingTic tac toe c++ programing
Tic tac toe c++ programingKrishna Agarwal
 
Game Tree ( Oyun Ağaçları )
Game Tree ( Oyun Ağaçları )Game Tree ( Oyun Ağaçları )
Game Tree ( Oyun Ağaçları )Alp Çoker
 
New Tools for a More Functional C++
New Tools for a More Functional C++New Tools for a More Functional C++
New Tools for a More Functional C++Sumant Tambe
 
The Ring programming language version 1.5 book - Part 9 of 31
The Ring programming language version 1.5 book - Part 9 of 31The Ring programming language version 1.5 book - Part 9 of 31
The Ring programming language version 1.5 book - Part 9 of 31Mahmoud Samir Fayed
 
The Ring programming language version 1.9 book - Part 80 of 210
The Ring programming language version 1.9 book - Part 80 of 210The Ring programming language version 1.9 book - Part 80 of 210
The Ring programming language version 1.9 book - Part 80 of 210Mahmoud Samir Fayed
 
The Ring programming language version 1.4.1 book - Part 15 of 31
The Ring programming language version 1.4.1 book - Part 15 of 31The Ring programming language version 1.4.1 book - Part 15 of 31
The Ring programming language version 1.4.1 book - Part 15 of 31Mahmoud Samir Fayed
 
The Ring programming language version 1.5.3 book - Part 79 of 184
The Ring programming language version 1.5.3 book - Part 79 of 184The Ring programming language version 1.5.3 book - Part 79 of 184
The Ring programming language version 1.5.3 book - Part 79 of 184Mahmoud Samir Fayed
 
Please help with this. program must be written in C# .. All of the g.pdf
Please help with this. program must be written in C# .. All of the g.pdfPlease help with this. program must be written in C# .. All of the g.pdf
Please help with this. program must be written in C# .. All of the g.pdfmanjan6
 
The main class of the tictoe game looks like.public class Main {.pdf
The main class of the tictoe game looks like.public class Main {.pdfThe main class of the tictoe game looks like.public class Main {.pdf
The main class of the tictoe game looks like.public class Main {.pdfasif1401
 
Silverlight as a Gaming Platform
Silverlight as a Gaming PlatformSilverlight as a Gaming Platform
Silverlight as a Gaming Platformgoodfriday
 
The Ring programming language version 1.10 book - Part 71 of 212
The Ring programming language version 1.10 book - Part 71 of 212The Ring programming language version 1.10 book - Part 71 of 212
The Ring programming language version 1.10 book - Part 71 of 212Mahmoud Samir Fayed
 
Game Theory Repeated Games at HelpWithAssignment.com
Game Theory Repeated Games at HelpWithAssignment.comGame Theory Repeated Games at HelpWithAssignment.com
Game Theory Repeated Games at HelpWithAssignment.comHelpWithAssignment.com
 
C++You will design a program to play a simplified version of war, .pdf
C++You will design a program to play a simplified version of war, .pdfC++You will design a program to play a simplified version of war, .pdf
C++You will design a program to play a simplified version of war, .pdfezzi97
 
package com.tictactoe; public class Main {public void play() {.pdf
package com.tictactoe; public class Main {public void play() {.pdfpackage com.tictactoe; public class Main {public void play() {.pdf
package com.tictactoe; public class Main {public void play() {.pdfinfo430661
 

Semelhante a BGA Studio - Focus on BGA Game state machine (20)

Flappy bird
Flappy birdFlappy bird
Flappy bird
 
Adversarial Search
Adversarial SearchAdversarial Search
Adversarial Search
 
AI Lesson 07
AI Lesson 07AI Lesson 07
AI Lesson 07
 
Tic tac toe c++ programing
Tic tac toe c++ programingTic tac toe c++ programing
Tic tac toe c++ programing
 
Game Tree ( Oyun Ağaçları )
Game Tree ( Oyun Ağaçları )Game Tree ( Oyun Ağaçları )
Game Tree ( Oyun Ağaçları )
 
New Tools for a More Functional C++
New Tools for a More Functional C++New Tools for a More Functional C++
New Tools for a More Functional C++
 
The Ring programming language version 1.5 book - Part 9 of 31
The Ring programming language version 1.5 book - Part 9 of 31The Ring programming language version 1.5 book - Part 9 of 31
The Ring programming language version 1.5 book - Part 9 of 31
 
Ddn
DdnDdn
Ddn
 
The Ring programming language version 1.9 book - Part 80 of 210
The Ring programming language version 1.9 book - Part 80 of 210The Ring programming language version 1.9 book - Part 80 of 210
The Ring programming language version 1.9 book - Part 80 of 210
 
The Ring programming language version 1.4.1 book - Part 15 of 31
The Ring programming language version 1.4.1 book - Part 15 of 31The Ring programming language version 1.4.1 book - Part 15 of 31
The Ring programming language version 1.4.1 book - Part 15 of 31
 
The Ring programming language version 1.5.3 book - Part 79 of 184
The Ring programming language version 1.5.3 book - Part 79 of 184The Ring programming language version 1.5.3 book - Part 79 of 184
The Ring programming language version 1.5.3 book - Part 79 of 184
 
Please help with this. program must be written in C# .. All of the g.pdf
Please help with this. program must be written in C# .. All of the g.pdfPlease help with this. program must be written in C# .. All of the g.pdf
Please help with this. program must be written in C# .. All of the g.pdf
 
The main class of the tictoe game looks like.public class Main {.pdf
The main class of the tictoe game looks like.public class Main {.pdfThe main class of the tictoe game looks like.public class Main {.pdf
The main class of the tictoe game looks like.public class Main {.pdf
 
Module_3_1.pptx
Module_3_1.pptxModule_3_1.pptx
Module_3_1.pptx
 
Silverlight as a Gaming Platform
Silverlight as a Gaming PlatformSilverlight as a Gaming Platform
Silverlight as a Gaming Platform
 
The Ring programming language version 1.10 book - Part 71 of 212
The Ring programming language version 1.10 book - Part 71 of 212The Ring programming language version 1.10 book - Part 71 of 212
The Ring programming language version 1.10 book - Part 71 of 212
 
Adversarial search
Adversarial search Adversarial search
Adversarial search
 
Game Theory Repeated Games at HelpWithAssignment.com
Game Theory Repeated Games at HelpWithAssignment.comGame Theory Repeated Games at HelpWithAssignment.com
Game Theory Repeated Games at HelpWithAssignment.com
 
C++You will design a program to play a simplified version of war, .pdf
C++You will design a program to play a simplified version of war, .pdfC++You will design a program to play a simplified version of war, .pdf
C++You will design a program to play a simplified version of war, .pdf
 
package com.tictactoe; public class Main {public void play() {.pdf
package com.tictactoe; public class Main {public void play() {.pdfpackage com.tictactoe; public class Main {public void play() {.pdf
package com.tictactoe; public class Main {public void play() {.pdf
 

Último

📞 Contact Number 8617370543VIP Fatehgarh Call Girls
📞 Contact Number 8617370543VIP Fatehgarh Call Girls📞 Contact Number 8617370543VIP Fatehgarh Call Girls
📞 Contact Number 8617370543VIP Fatehgarh Call GirlsNitya salvi
 
Call Girls South Tripura Just Call 8617370543 Top Class Call Girl Service Ava...
Call Girls South Tripura Just Call 8617370543 Top Class Call Girl Service Ava...Call Girls South Tripura Just Call 8617370543 Top Class Call Girl Service Ava...
Call Girls South Tripura Just Call 8617370543 Top Class Call Girl Service Ava...Nitya salvi
 
Call Girls In Gandhinagar 📞 8617370543 At Low Cost Cash Payment Booking
Call Girls In Gandhinagar 📞 8617370543  At Low Cost Cash Payment BookingCall Girls In Gandhinagar 📞 8617370543  At Low Cost Cash Payment Booking
Call Girls In Gandhinagar 📞 8617370543 At Low Cost Cash Payment BookingNitya salvi
 
Ghansoli Escorts Services 09167354423 Ghansoli Call Girls,Call Girls In Ghan...
Ghansoli Escorts Services 09167354423  Ghansoli Call Girls,Call Girls In Ghan...Ghansoli Escorts Services 09167354423  Ghansoli Call Girls,Call Girls In Ghan...
Ghansoli Escorts Services 09167354423 Ghansoli Call Girls,Call Girls In Ghan...Priya Reddy
 
Unnao 💋 Call Girl 8617370543 Call Girls in unnao Escort service book now
Unnao 💋 Call Girl 8617370543 Call Girls in unnao Escort service book nowUnnao 💋 Call Girl 8617370543 Call Girls in unnao Escort service book now
Unnao 💋 Call Girl 8617370543 Call Girls in unnao Escort service book nowNitya salvi
 
Himmatnagar 💋 Call Girl (Love) 8617370543 Call Girls in Himmatnagar Escort Se...
Himmatnagar 💋 Call Girl (Love) 8617370543 Call Girls in Himmatnagar Escort Se...Himmatnagar 💋 Call Girl (Love) 8617370543 Call Girls in Himmatnagar Escort Se...
Himmatnagar 💋 Call Girl (Love) 8617370543 Call Girls in Himmatnagar Escort Se...Nitya salvi
 
Hire 💕 8617370543 Dhalai Call Girls Service Call Girls Agency
Hire 💕 8617370543 Dhalai Call Girls Service Call Girls AgencyHire 💕 8617370543 Dhalai Call Girls Service Call Girls Agency
Hire 💕 8617370543 Dhalai Call Girls Service Call Girls AgencyNitya salvi
 
Call Girls in Perumbavoor / 9332606886 Genuine Call girls with real Photos an...
Call Girls in Perumbavoor / 9332606886 Genuine Call girls with real Photos an...Call Girls in Perumbavoor / 9332606886 Genuine Call girls with real Photos an...
Call Girls in Perumbavoor / 9332606886 Genuine Call girls with real Photos an...call girls kolkata
 
Bhubaneswar🌹Call Girls Patia ❤Komal 9777949614 💟 Full Trusted CALL GIRLS IN b...
Bhubaneswar🌹Call Girls Patia ❤Komal 9777949614 💟 Full Trusted CALL GIRLS IN b...Bhubaneswar🌹Call Girls Patia ❤Komal 9777949614 💟 Full Trusted CALL GIRLS IN b...
Bhubaneswar🌹Call Girls Patia ❤Komal 9777949614 💟 Full Trusted CALL GIRLS IN b...Call Girls Mumbai
 
Call Girls in Ernakulam - 9332606886 Our call girls are sure to provide you w...
Call Girls in Ernakulam - 9332606886 Our call girls are sure to provide you w...Call Girls in Ernakulam - 9332606886 Our call girls are sure to provide you w...
Call Girls in Ernakulam - 9332606886 Our call girls are sure to provide you w...call girls kolkata
 
🌹Bhubaneswar🌹Ravi Tailkes ❤CALL GIRL 9777949614 ❤CALL GIRLS IN bhubaneswar E...
🌹Bhubaneswar🌹Ravi Tailkes  ❤CALL GIRL 9777949614 ❤CALL GIRLS IN bhubaneswar E...🌹Bhubaneswar🌹Ravi Tailkes  ❤CALL GIRL 9777949614 ❤CALL GIRLS IN bhubaneswar E...
🌹Bhubaneswar🌹Ravi Tailkes ❤CALL GIRL 9777949614 ❤CALL GIRLS IN bhubaneswar E...Call Girls Mumbai
 
Call Girls In Amreli Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service Enjoy...
Call Girls In Amreli Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service Enjoy...Call Girls In Amreli Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service Enjoy...
Call Girls In Amreli Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service Enjoy...Nitya salvi
 
Call girls Service in Deira 0507330913 Deira Call girls
Call girls Service in Deira 0507330913 Deira Call girlsCall girls Service in Deira 0507330913 Deira Call girls
Call girls Service in Deira 0507330913 Deira Call girlsMonica Sydney
 
Badshah Nagar ] Call Girls Service Lucknow | Starting ₹,5K To @25k with A/C 9...
Badshah Nagar ] Call Girls Service Lucknow | Starting ₹,5K To @25k with A/C 9...Badshah Nagar ] Call Girls Service Lucknow | Starting ₹,5K To @25k with A/C 9...
Badshah Nagar ] Call Girls Service Lucknow | Starting ₹,5K To @25k with A/C 9...HyderabadDolls
 
Call Girls Moradabad Just Call 8617370543 Top Class Call Girl Service Available
Call Girls Moradabad Just Call 8617370543 Top Class Call Girl Service AvailableCall Girls Moradabad Just Call 8617370543 Top Class Call Girl Service Available
Call Girls Moradabad Just Call 8617370543 Top Class Call Girl Service AvailableNitya salvi
 
Call Girls In Gorakhpur Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service En...
Call Girls In Gorakhpur Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service En...Call Girls In Gorakhpur Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service En...
Call Girls In Gorakhpur Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service En...Nitya salvi
 
Call girls Service Berhampur - 9332606886 Our call girls are sure to provide ...
Call girls Service Berhampur - 9332606886 Our call girls are sure to provide ...Call girls Service Berhampur - 9332606886 Our call girls are sure to provide ...
Call girls Service Berhampur - 9332606886 Our call girls are sure to provide ...DipikaDelhi
 
Tapi Escorts | 8617370543 call girls service for all Users
Tapi Escorts | 8617370543 call girls service for all UsersTapi Escorts | 8617370543 call girls service for all Users
Tapi Escorts | 8617370543 call girls service for all UsersNitya salvi
 
Dubai Call girls Service 0524076003 Call girls in Dubai
Dubai Call girls Service 0524076003 Call girls in DubaiDubai Call girls Service 0524076003 Call girls in Dubai
Dubai Call girls Service 0524076003 Call girls in DubaiMonica Sydney
 
Dubai Call girls Service 0524076003 Call girls services in Dubai
Dubai Call girls Service 0524076003 Call girls services in DubaiDubai Call girls Service 0524076003 Call girls services in Dubai
Dubai Call girls Service 0524076003 Call girls services in DubaiMonica Sydney
 

Último (20)

📞 Contact Number 8617370543VIP Fatehgarh Call Girls
📞 Contact Number 8617370543VIP Fatehgarh Call Girls📞 Contact Number 8617370543VIP Fatehgarh Call Girls
📞 Contact Number 8617370543VIP Fatehgarh Call Girls
 
Call Girls South Tripura Just Call 8617370543 Top Class Call Girl Service Ava...
Call Girls South Tripura Just Call 8617370543 Top Class Call Girl Service Ava...Call Girls South Tripura Just Call 8617370543 Top Class Call Girl Service Ava...
Call Girls South Tripura Just Call 8617370543 Top Class Call Girl Service Ava...
 
Call Girls In Gandhinagar 📞 8617370543 At Low Cost Cash Payment Booking
Call Girls In Gandhinagar 📞 8617370543  At Low Cost Cash Payment BookingCall Girls In Gandhinagar 📞 8617370543  At Low Cost Cash Payment Booking
Call Girls In Gandhinagar 📞 8617370543 At Low Cost Cash Payment Booking
 
Ghansoli Escorts Services 09167354423 Ghansoli Call Girls,Call Girls In Ghan...
Ghansoli Escorts Services 09167354423  Ghansoli Call Girls,Call Girls In Ghan...Ghansoli Escorts Services 09167354423  Ghansoli Call Girls,Call Girls In Ghan...
Ghansoli Escorts Services 09167354423 Ghansoli Call Girls,Call Girls In Ghan...
 
Unnao 💋 Call Girl 8617370543 Call Girls in unnao Escort service book now
Unnao 💋 Call Girl 8617370543 Call Girls in unnao Escort service book nowUnnao 💋 Call Girl 8617370543 Call Girls in unnao Escort service book now
Unnao 💋 Call Girl 8617370543 Call Girls in unnao Escort service book now
 
Himmatnagar 💋 Call Girl (Love) 8617370543 Call Girls in Himmatnagar Escort Se...
Himmatnagar 💋 Call Girl (Love) 8617370543 Call Girls in Himmatnagar Escort Se...Himmatnagar 💋 Call Girl (Love) 8617370543 Call Girls in Himmatnagar Escort Se...
Himmatnagar 💋 Call Girl (Love) 8617370543 Call Girls in Himmatnagar Escort Se...
 
Hire 💕 8617370543 Dhalai Call Girls Service Call Girls Agency
Hire 💕 8617370543 Dhalai Call Girls Service Call Girls AgencyHire 💕 8617370543 Dhalai Call Girls Service Call Girls Agency
Hire 💕 8617370543 Dhalai Call Girls Service Call Girls Agency
 
Call Girls in Perumbavoor / 9332606886 Genuine Call girls with real Photos an...
Call Girls in Perumbavoor / 9332606886 Genuine Call girls with real Photos an...Call Girls in Perumbavoor / 9332606886 Genuine Call girls with real Photos an...
Call Girls in Perumbavoor / 9332606886 Genuine Call girls with real Photos an...
 
Bhubaneswar🌹Call Girls Patia ❤Komal 9777949614 💟 Full Trusted CALL GIRLS IN b...
Bhubaneswar🌹Call Girls Patia ❤Komal 9777949614 💟 Full Trusted CALL GIRLS IN b...Bhubaneswar🌹Call Girls Patia ❤Komal 9777949614 💟 Full Trusted CALL GIRLS IN b...
Bhubaneswar🌹Call Girls Patia ❤Komal 9777949614 💟 Full Trusted CALL GIRLS IN b...
 
Call Girls in Ernakulam - 9332606886 Our call girls are sure to provide you w...
Call Girls in Ernakulam - 9332606886 Our call girls are sure to provide you w...Call Girls in Ernakulam - 9332606886 Our call girls are sure to provide you w...
Call Girls in Ernakulam - 9332606886 Our call girls are sure to provide you w...
 
🌹Bhubaneswar🌹Ravi Tailkes ❤CALL GIRL 9777949614 ❤CALL GIRLS IN bhubaneswar E...
🌹Bhubaneswar🌹Ravi Tailkes  ❤CALL GIRL 9777949614 ❤CALL GIRLS IN bhubaneswar E...🌹Bhubaneswar🌹Ravi Tailkes  ❤CALL GIRL 9777949614 ❤CALL GIRLS IN bhubaneswar E...
🌹Bhubaneswar🌹Ravi Tailkes ❤CALL GIRL 9777949614 ❤CALL GIRLS IN bhubaneswar E...
 
Call Girls In Amreli Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service Enjoy...
Call Girls In Amreli Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service Enjoy...Call Girls In Amreli Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service Enjoy...
Call Girls In Amreli Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service Enjoy...
 
Call girls Service in Deira 0507330913 Deira Call girls
Call girls Service in Deira 0507330913 Deira Call girlsCall girls Service in Deira 0507330913 Deira Call girls
Call girls Service in Deira 0507330913 Deira Call girls
 
Badshah Nagar ] Call Girls Service Lucknow | Starting ₹,5K To @25k with A/C 9...
Badshah Nagar ] Call Girls Service Lucknow | Starting ₹,5K To @25k with A/C 9...Badshah Nagar ] Call Girls Service Lucknow | Starting ₹,5K To @25k with A/C 9...
Badshah Nagar ] Call Girls Service Lucknow | Starting ₹,5K To @25k with A/C 9...
 
Call Girls Moradabad Just Call 8617370543 Top Class Call Girl Service Available
Call Girls Moradabad Just Call 8617370543 Top Class Call Girl Service AvailableCall Girls Moradabad Just Call 8617370543 Top Class Call Girl Service Available
Call Girls Moradabad Just Call 8617370543 Top Class Call Girl Service Available
 
Call Girls In Gorakhpur Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service En...
Call Girls In Gorakhpur Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service En...Call Girls In Gorakhpur Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service En...
Call Girls In Gorakhpur Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service En...
 
Call girls Service Berhampur - 9332606886 Our call girls are sure to provide ...
Call girls Service Berhampur - 9332606886 Our call girls are sure to provide ...Call girls Service Berhampur - 9332606886 Our call girls are sure to provide ...
Call girls Service Berhampur - 9332606886 Our call girls are sure to provide ...
 
Tapi Escorts | 8617370543 call girls service for all Users
Tapi Escorts | 8617370543 call girls service for all UsersTapi Escorts | 8617370543 call girls service for all Users
Tapi Escorts | 8617370543 call girls service for all Users
 
Dubai Call girls Service 0524076003 Call girls in Dubai
Dubai Call girls Service 0524076003 Call girls in DubaiDubai Call girls Service 0524076003 Call girls in Dubai
Dubai Call girls Service 0524076003 Call girls in Dubai
 
Dubai Call girls Service 0524076003 Call girls services in Dubai
Dubai Call girls Service 0524076003 Call girls services in DubaiDubai Call girls Service 0524076003 Call girls services in Dubai
Dubai Call girls Service 0524076003 Call girls services in Dubai
 

BGA Studio - Focus on BGA Game state machine

  • 1. Focus on : BGA Game state machin
  • 2. Why a game state machine? Because game states will make your life easier. In all board games, you have to play actions in a specific order : do this is phase 1, then do this in phase 2, then in phase 3 you can do actions A, B or C, ... With BGA Studio framework you specify a finite-state machine for your game. This state machine allows you to structure and to implement the rules of a game very efficiently. Understanding game states is essential to develop a game on Board Game Arena platform.
  • 3. What is a game state machine? gameSetup A simple game state machine diagram with 4 different game states is displayed on the right. This machine correspond for example to chess playerTurn game, or reversi (BGA Studio example) game : _ the game start. _ a player plays one move. _ we jump to the next player (opponent's of the previous player). nextPlayer _ … we loop until one player can't play, then it is the end of the game gameEnd
  • 4. Game state & BGA Game states is a central piece in the BGA framework. Depending on which game state a specific game is right now, the BGA platform is going to : ● Decide which text is to be displayed in the status bar. ● Allow some player actions (and forbid some others). ● Determine which players are « active » (ie : it is their turn). ● Trigger some automatic game actions on server (ex : apply some automatic card effect). ● Trigger some game interface adaptations on client side (in Javascript). ● … and of course, determine what are the next possible game states.
  • 5. Define your game state machine You can define the game state machine of your game in your states.inc.php file. Your game state machine is basically a PHP associative array. Each entry correspond to a game state of your game, and each entry key correspond to the game state id. Two game states are particular (and shouldn't be edited) : ● GameSetup (id = 1) is the game state active when your game is starting. ● GameEnd (id=99) is the game state you have to active when the game is over.
  • 6. Game state types There are 4 different game state types : ● Activeplayer ● Multipleactiveplayer ● Game ● Manager When the current game state's type is activeplayer, only 1 player is active (it is the turn of only one player, and it is the only one allowed to do some player action). When the current game state's type is multipleactiveplayer, several players are active at the same time, and can perform some player actions simultaneously. When the current game state's type is game, no player is active. This game state is used to perform some automatic action on server side (ex : jump to next player). This is an unstable state : you have to jump to another game state automatically when executing the code associated with this type of state. You don't have to care about « Manager » game state type : only « gameSetup » and « gameEnd » state are using this type.
  • 7. Game state types GameSetup (type = manager) PlayerTurn (type = activeplayer) Here is the previous example with game state types : NextPlayer (type = game) GameEnd (type = manager)
  • 8. Focus on : Active player In a board game, most of the time, everyone plays when it's his turn to play. This is why we have in BGA framework the concept of active player. Basically, the active player is the player whose turn it is. When a player is active, and when the current game state's type is « activeplayer », the following things happened : ● Active player's icon in his game panel is changed into a hourglass icon. ● Active player's time to think starts decreasing. ● If the active player wasn't active before, the « it's your turn » sound is played. Pay attention : active player != current player In BGA framework, the current player is the player who played the current player action (= player who made the AJAX request). Most of the time, the current player is also the active player, but in some context this could be wrong.
  • 9. Game state functions Now, let's have a look at all you can do with game states, with one of our game example « Reversi ».
  • 10. Game state machine example : Reversi At first, here's the « states.inc.php » file for Reversi, that correspond to the diagram on the right. We're going to explain it now. 1 => array( "name" => "gameSetup", "description" => clienttranslate("Game setup"), "type" => "manager", "action" => "stGameSetup", GameSetup "transitions" => array( "" => 10 ) ), 10 => array( "name" => "playerTurn", "description" => clienttranslate('${actplayer} must play a disc'), "descriptionmyturn" => clienttranslate('${you} must play a disc'), "type" => "activeplayer", playerTurn "args" => "argPlayerTurn", "possibleactions" => array( 'playDisc' ), "transitions" => array( "playDisc" => 11, "zombiePass" => 11 ) ), 11 => array( "name" => "nextPlayer", nextPlayer "type" => "game", "action" => "stNextPlayer", "updateGameProgression" => true, "transitions" => array( "nextTurn" => 10, "cantPlay" => 11, "endGame" => 99 ) ), 99 => array( gameEnd "name" => "gameEnd", "description" => clienttranslate("End of game"), "type" => "manager", "action" => "stGameEnd", "args" => "argGameEnd" )
  • 11. Game state function 1/6 : transitions « Transition » argument specify « paths » between game states, ie how you can jump from one game state to another. Example with «nextPlayer» state is Reversi : 11 => array( "name" => "nextPlayer", "type" => "game", "action" => "stNextPlayer", "updateGameProgression" => true, "transitions" => array( "nextTurn" => 10, "cantPlay" => 11, "endGame" => 99 ) ), In the example above, if the current game state is « nextPlayer », the next game state could be one of the following : 10 (playerTurn), 11 (nextPlayer, again), or 99 (gameEnd). The strings used as keys for the transitions argument defines the name of the transitions. The transition name is used when you are jumping from one game state to another in your PHP. Example : if current game state is « nextPlayer » and if you do the following in your PHP : $this->gamestate->nextState( 'nextTurn' ); … you are going to use transition « nextTurn », and then jump to game state 10 (=playerTurn) according to the game state definition above.
  • 12. Game state function 1/6 : transitions gameSetup You can see on the right the transitions displayed on the diagram. If you design your game states and game state playerTurn transitions carefully, you are going to save a lot of time programming your game. playDisc nextTurn Once a good state machine is defined for a game, you can start to concentrate yourself on each of the nextPlayer cantPlay specific state of the game, and let BGA Framework take care of navigation between game states. endGame gameEnd
  • 13. Game state function 2/6 : description When you specify a « description » argument in your game state, this description is displayed in the status bar. Example with « playerTurn » state is Reversi : 10 => array( "name" => "playerTurn", "description" => clienttranslate('${actplayer} must play a disc'), "descriptionmyturn" => clienttranslate('${you} must play a disc'), "type" => "activeplayer", "args" => "argPlayerTurn", "possibleactions" => array( 'playDisc' ), "transitions" => array( "playDisc" => 11, "zombiePass" => 11 ) ),
  • 14. Game state function 2/6 : descriptionmyturn When you specify a « descriptionmyturn » argument in your game state, this description takes over the « description » argument in the status bar when the current player is active. Example with « playerTurn » state is Reversi : 10 => array( "name" => "playerTurn", "description" => clienttranslate('${actplayer} must play a disc'), "descriptionmyturn" => clienttranslate('${you} must play a disc'), "type" => "activeplayer", "args" => "argPlayerTurn", "possibleactions" => array( 'playDisc' ), "transitions" => array( "playDisc" => 11, "zombiePass" => 11 ) ),
  • 15. Game state function 3/6 : game interface adaptations Game states are especially useful on server side to implement the rules of the game, but they are also useful on client side (game interface) too. 3 Javascript methods are directly linked with gamestate : ● « onEnteringState » is called when we jump into a game state. ● « onLeavingState » is called when we are leaving a game state. ● « onUpdateActionButtons » allows you to add some player action button in the status bar depending on current game state. Example 1 : you can show some <div> element (with dojo.style method) when entering into a game state, and hide it when leaving. Example 2 : in Reversi, we are displaying possible move when entering into « playerTurn » game state (we'll tell you more about this example later). Example 3 : in Dominion, we add a « Buy nothing » button on the status bar when we are in the « buyCard » game state.
  • 16. Game state function 4/6 : possibleactions « possibleactions » defines what game actions are possible for the active(s) player(s) during the current game state. Obviously, « possibleactions » argument is specified for activeplayer and multipleactiveplayer game states. Example with « playerTurn » state is Reversi : 10 => array( "name" => "playerTurn", "description" => clienttranslate('${actplayer} must play a disc'), "descriptionmyturn" => clienttranslate('${you} must play a disc'), "type" => "activeplayer", "args" => "argPlayerTurn", "possibleactions" => array( 'playDisc' ), "transitions" => array( "playDisc" => 11, "zombiePass" => 11 ) ), Once you define an action as « possible », it's very easy to check that a player is authorized to do some game action, which is essential to ensure your players can't cheat : From your PHP code : function playDisc( $x, $y ) { // Check that this player is active and that this action is possible at this moment self::checkAction( 'playDisc' ); From your Javacript code : if( this.checkAction( 'playDisc' ) ) // Check that this action is possible at this moment {
  • 17. Game state function 4/6 : action «action» defines a PHP method to call each time the game state become the current game state. With this method, you can do some automatic actions. In the following example with the « nextPlayer » state in Reversi, we jump to the next player : 11 => array( "name" => "nextPlayer", "type" => "game", "action" => "stNextPlayer", "updateGameProgression" => true, "transitions" => array( "nextTurn" => 10, "cantPlay" => 11, "endGame" => 99 ) ), In reversi.game.php : function stNextPlayer() { // Active next player $player_id = self::activeNextPlayer(); … A method called with a « action » argument is called « game state reaction method ». By convention, game state reaction method are prefixed with « st ».
  • 18. Game state function 4/6 : action In Reversi example, the stNextPlayer method : ● Active the next player ● Check if there is some free space on the board. If there is not, it jumps to the gameEnd state. ● Check if some player has no more disc on the board (=> instant victory => gameEnd). ● Check that the current player can play, otherwise change active player and loop on this gamestate (« cantPlay » transition). ● If none of the previous things happened, give extra time to think to active player and go to the « playerTurn » state (« nextTurn » transition). function stNextPlayer() { // Active next player $player_id = self::activeNextPlayer(); // Check if both player has at least 1 discs, and if there are free squares to play $player_to_discs = self::getCollectionFromDb( "SELECT board_player, COUNT( board_x ) FROM board GROUP BY board_player", true ); if( ! isset( $player_to_discs[ null ] ) ) { // Index 0 has not been set => there's no more free place on the board ! // => end of the game $this->gamestate->nextState( 'endGame' ); return ; } else if( ! isset( $player_to_discs[ $player_id ] ) ) { // Active player has no more disc on the board => he looses immediately $this->gamestate->nextState( 'endGame' ); return ;
  • 19. Game state function 5/6 : args From time to time, it happens that you need some information on the client side (ie : for your game interface) only for a specific game state. Example 1 : for Reversi, the list of possible moves during playerTurn state. Example 2 : in Caylus, the number of remaining king's favor to choose in the state where the player is choosing a favor. Example 3 : in Can't stop, the list of possible die combination to be displayed to the active player in order he can choose among them. In such a situation, you can specify a method name as the « args » argument for your game state. This method must get some piece of information about the game (ex : for Reversi, the possible moves) and return them. Thus, this data can be transmitted to the clients and used by the clients to display it. Let's see a complete example using args with « Reversi » game :
  • 20. Game state function 5/6 : args In states.inc.php, we specify some « args » argument for gamestate « playerTurn » : 10 => array( "name" => "placeWorkers", "description" => clienttranslate('${actplayer} must place some workers'), "descriptionmyturn" => clienttranslate('${you} must place some workers'), "type" => "activeplayer", "args" => "argPlaceWorkers", "possibleactions" => array( "placeWorkers" ), "transitions" => array( "nextPlayer" => 11, "nextPhase" => 12, "zombiePass" => 11 ) ), It corresponds to a « argPlaceWorkers » method in our PHP code (reversi.game.php): function argPlayerTurn() { return array( 'possibleMoves' => self::getPossibleMoves() ); } Then, when we enter into « playerTurn » game state on the client side, we can highlight the possible moves on the board using information returned by argPlayerTurn : onEnteringState: function( stateName, args ) { console.log( 'Entering state: '+stateName ); switch( stateName ) { case 'playerTurn': this.updatePossibleMoves( args.args.possibleMoves ); break; }
  • 21. Game state function 6/6 : updateGameProgression When you specify « updateGameProgression » in a game state, you are telling the BGA framework that the « game progression » indicator must be updated each time we jump into this game state. Consequently, your « getGameProgression » method will be called each time we jump into this game state. Example with «nextPlayer» state is Reversi : 11 => array( "name" => "nextPlayer", "type" => "game", "action" => "stNextPlayer", "updateGameProgression" => true, "transitions" => array( "nextTurn" => 10, "cantPlay" => 11, "endGame" => 99 ) ),
  • 22. Game states tips Specifying a good state machine for your game is essential while working with BGA Framework. Once you've designed your state machine and after you've added corresponding « st », « arg » and « player action » methods on your code, your source code on server side is well organized and you are ready to concentrate yourself on more detailled part of the game. Usually, it's better to start designing a state machine on paper, in order to visualize all the transitions. A good pratice is to read the game rules while writing on a paper all possible different player actions and all automatic actions to perform during a game, then to check if it correspond to the state machine. Defining a new game state is very simple to do : it's just configuration! Consequently, don't hesitate to add as many game states as you need. In some situation, add one or two additional game states can simplfy the code of your game and make it more reliable. For example, if there are a lot of operations to be done at the end of a turn with a lot of conditions and branches, it is probably better to split these operations among several « game » type's game state in order to make your source code more clear.
  • 23. Summary ● You know how to design and how to specify a game state machine for your game. ●You know how to use game states to structure and organize your source code, in order you can concentrate yourself on each part. ●You know how to use all game states built-in functionnalities to manage active players, status bar and game progression.