SlideShare a Scribd company logo
1 of 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.

More Related Content

What's hot

Game Balance 1: What is Game Balance
Game Balance 1: What is Game BalanceGame Balance 1: What is Game Balance
Game Balance 1: What is Game BalanceMarc Miquel
 
4 lecture (mda frame work) 25 1-2021
4 lecture (mda frame work) 25 1-20214 lecture (mda frame work) 25 1-2021
4 lecture (mda frame work) 25 1-2021Durgesh Pandey
 
The Principles of Game Design
The Principles of Game DesignThe Principles of Game Design
The Principles of Game DesignInstantTechInfo
 
Killer Design Patterns for F2P Mobile/Tablet Games
Killer Design Patterns for F2P Mobile/Tablet GamesKiller Design Patterns for F2P Mobile/Tablet Games
Killer Design Patterns for F2P Mobile/Tablet GamesHenric Suuronen
 
Introduction to Unity3D Game Engine
Introduction to Unity3D Game EngineIntroduction to Unity3D Game Engine
Introduction to Unity3D Game EngineMohsen Mirhoseini
 
2-Game Design (Game Design and Development)
2-Game Design (Game Design and Development)2-Game Design (Game Design and Development)
2-Game Design (Game Design and Development)Hafiz Ammar Siddiqui
 
Introduction to game development
Introduction to game developmentIntroduction to game development
Introduction to game developmentGaetano Bonofiglio
 
LAFS Game Design 6 - Conceptualization
LAFS Game Design 6 - ConceptualizationLAFS Game Design 6 - Conceptualization
LAFS Game Design 6 - ConceptualizationDavid Mullich
 
Intro to Game Design
Intro to Game DesignIntro to Game Design
Intro to Game DesignGraeme Smith
 
Game genres
Game genresGame genres
Game genresaealey
 
Game Design Fundamentals
Game Design FundamentalsGame Design Fundamentals
Game Design FundamentalsIntelligent_ly
 
Understanding casual games
Understanding casual gamesUnderstanding casual games
Understanding casual gamesDori Adar
 
LAFS Game Design 7 - Prototyping
LAFS Game Design 7 - PrototypingLAFS Game Design 7 - Prototyping
LAFS Game Design 7 - PrototypingDavid Mullich
 
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
 
Making a Game Design Document
Making a Game Design DocumentMaking a Game Design Document
Making a Game Design DocumentEqual Experts
 

What's hot (20)

Level Design
Level DesignLevel Design
Level Design
 
Game Balance 1: What is Game Balance
Game Balance 1: What is Game BalanceGame Balance 1: What is Game Balance
Game Balance 1: What is Game Balance
 
Game Design as Career
Game Design as CareerGame Design as Career
Game Design as Career
 
4 lecture (mda frame work) 25 1-2021
4 lecture (mda frame work) 25 1-20214 lecture (mda frame work) 25 1-2021
4 lecture (mda frame work) 25 1-2021
 
The Principles of Game Design
The Principles of Game DesignThe Principles of Game Design
The Principles of Game Design
 
Killer Design Patterns for F2P Mobile/Tablet Games
Killer Design Patterns for F2P Mobile/Tablet GamesKiller Design Patterns for F2P Mobile/Tablet Games
Killer Design Patterns for F2P Mobile/Tablet Games
 
Introduction to Unity3D Game Engine
Introduction to Unity3D Game EngineIntroduction to Unity3D Game Engine
Introduction to Unity3D Game Engine
 
2-Game Design (Game Design and Development)
2-Game Design (Game Design and Development)2-Game Design (Game Design and Development)
2-Game Design (Game Design and Development)
 
Game design doc template
Game design doc   templateGame design doc   template
Game design doc template
 
Introduction to game development
Introduction to game developmentIntroduction to game development
Introduction to game development
 
Various Topics on Game Design
Various Topics on Game DesignVarious Topics on Game Design
Various Topics on Game Design
 
LAFS Game Design 6 - Conceptualization
LAFS Game Design 6 - ConceptualizationLAFS Game Design 6 - Conceptualization
LAFS Game Design 6 - Conceptualization
 
Intro to Game Design
Intro to Game DesignIntro to Game Design
Intro to Game Design
 
Phases of game development
Phases of game developmentPhases of game development
Phases of game development
 
Game genres
Game genresGame genres
Game genres
 
Game Design Fundamentals
Game Design FundamentalsGame Design Fundamentals
Game Design Fundamentals
 
Understanding casual games
Understanding casual gamesUnderstanding casual games
Understanding casual games
 
LAFS Game Design 7 - Prototyping
LAFS Game Design 7 - PrototypingLAFS Game Design 7 - Prototyping
LAFS Game Design 7 - Prototyping
 
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
 
Making a Game Design Document
Making a Game Design DocumentMaking a Game Design Document
Making a Game Design Document
 

Similar to 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
 

Similar to 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
 

Recently uploaded

Hire 💕 8617370543 Mirzapur Call Girls Service Call Girls Agency
Hire 💕 8617370543 Mirzapur Call Girls Service Call Girls AgencyHire 💕 8617370543 Mirzapur Call Girls Service Call Girls Agency
Hire 💕 8617370543 Mirzapur Call Girls Service Call Girls AgencyNitya salvi
 
Hire 💕 8617370543 Lunawada Call Girls Service Call Girls Agency
Hire 💕 8617370543 Lunawada Call Girls Service Call Girls AgencyHire 💕 8617370543 Lunawada Call Girls Service Call Girls Agency
Hire 💕 8617370543 Lunawada Call Girls Service Call Girls AgencyNitya salvi
 
Top IPTV Subscription Service to Stream Your Favorite Shows in 2024.pdf
Top IPTV Subscription Service to Stream Your Favorite Shows in 2024.pdfTop IPTV Subscription Service to Stream Your Favorite Shows in 2024.pdf
Top IPTV Subscription Service to Stream Your Favorite Shows in 2024.pdfXtreame HDTV
 
Call Girls Bhubaneswar 9777949614 call me Independent Escort Service Bhubaneswar
Call Girls Bhubaneswar 9777949614 call me Independent Escort Service BhubaneswarCall Girls Bhubaneswar 9777949614 call me Independent Escort Service Bhubaneswar
Call Girls Bhubaneswar 9777949614 call me Independent Escort Service BhubaneswarCall Girls Mumbai
 
Call girls Service Bellary - 9332606886 Rs 3000 Free Pickup & Drop Services 2...
Call girls Service Bellary - 9332606886 Rs 3000 Free Pickup & Drop Services 2...Call girls Service Bellary - 9332606886 Rs 3000 Free Pickup & Drop Services 2...
Call girls Service Bellary - 9332606886 Rs 3000 Free Pickup & Drop Services 2...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
 
Dahod Call Girl 📞 8617370543 Low Price Genuine Service
Dahod Call Girl 📞 8617370543 Low Price Genuine ServiceDahod Call Girl 📞 8617370543 Low Price Genuine Service
Dahod Call Girl 📞 8617370543 Low Price Genuine ServiceNitya salvi
 
Banda call girls 📞 8617370543At Low Cost Cash Payment Booking
Banda call girls 📞 8617370543At Low Cost Cash Payment BookingBanda call girls 📞 8617370543At Low Cost Cash Payment Booking
Banda call girls 📞 8617370543At Low Cost Cash Payment BookingNitya salvi
 
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
 
📞 Contact Number 8617370543VIP diu Call Girls
📞 Contact Number 8617370543VIP diu Call Girls📞 Contact Number 8617370543VIP diu Call Girls
📞 Contact Number 8617370543VIP diu Call GirlsNitya salvi
 
Call Girls Surat Just Call 8617370543 Top Class Call Girl Service Available
Call Girls Surat Just Call 8617370543 Top Class Call Girl Service AvailableCall Girls Surat Just Call 8617370543 Top Class Call Girl Service Available
Call Girls Surat Just Call 8617370543 Top Class Call Girl Service AvailableNitya salvi
 
Exclusive Ahmedabad Call Girls 💯Call Us 🔝 6378878445 🔝 💃 Top Class Call Girl...
Exclusive  Ahmedabad Call Girls 💯Call Us 🔝 6378878445 🔝 💃 Top Class Call Girl...Exclusive  Ahmedabad Call Girls 💯Call Us 🔝 6378878445 🔝 💃 Top Class Call Girl...
Exclusive Ahmedabad Call Girls 💯Call Us 🔝 6378878445 🔝 💃 Top Class Call Girl...vershagrag
 
Pakistani Call girls in Deira 0567006274 Deira Call girls
Pakistani Call girls in Deira 0567006274 Deira Call girlsPakistani Call girls in Deira 0567006274 Deira Call girls
Pakistani Call girls in Deira 0567006274 Deira Call girlsMonica Sydney
 
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
 
Bhubaneswar🌹Call Girls Rasulgada ❤Komal 9777949614 💟 Full Trusted CALL GIRLS ...
Bhubaneswar🌹Call Girls Rasulgada ❤Komal 9777949614 💟 Full Trusted CALL GIRLS ...Bhubaneswar🌹Call Girls Rasulgada ❤Komal 9777949614 💟 Full Trusted CALL GIRLS ...
Bhubaneswar🌹Call Girls Rasulgada ❤Komal 9777949614 💟 Full Trusted CALL GIRLS ...Call Girls Mumbai
 
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
 
Call Girls Belonia Just Call 📞 8617370543 Top Class Call Girl Service Available
Call Girls Belonia Just Call 📞 8617370543 Top Class Call Girl Service AvailableCall Girls Belonia Just Call 📞 8617370543 Top Class Call Girl Service Available
Call Girls Belonia Just Call 📞 8617370543 Top Class Call Girl Service AvailableNitya salvi
 
Call girls Service Pondicherry ( 9332606886 ) Cheap rates call girls | Get lo...
Call girls Service Pondicherry ( 9332606886 ) Cheap rates call girls | Get lo...Call girls Service Pondicherry ( 9332606886 ) Cheap rates call girls | Get lo...
Call girls Service Pondicherry ( 9332606886 ) Cheap rates call girls | Get lo...DipikaDelhi
 
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
 

Recently uploaded (20)

Hire 💕 8617370543 Mirzapur Call Girls Service Call Girls Agency
Hire 💕 8617370543 Mirzapur Call Girls Service Call Girls AgencyHire 💕 8617370543 Mirzapur Call Girls Service Call Girls Agency
Hire 💕 8617370543 Mirzapur Call Girls Service Call Girls Agency
 
Hire 💕 8617370543 Lunawada Call Girls Service Call Girls Agency
Hire 💕 8617370543 Lunawada Call Girls Service Call Girls AgencyHire 💕 8617370543 Lunawada Call Girls Service Call Girls Agency
Hire 💕 8617370543 Lunawada Call Girls Service Call Girls Agency
 
Top IPTV Subscription Service to Stream Your Favorite Shows in 2024.pdf
Top IPTV Subscription Service to Stream Your Favorite Shows in 2024.pdfTop IPTV Subscription Service to Stream Your Favorite Shows in 2024.pdf
Top IPTV Subscription Service to Stream Your Favorite Shows in 2024.pdf
 
Call Girls Bhubaneswar 9777949614 call me Independent Escort Service Bhubaneswar
Call Girls Bhubaneswar 9777949614 call me Independent Escort Service BhubaneswarCall Girls Bhubaneswar 9777949614 call me Independent Escort Service Bhubaneswar
Call Girls Bhubaneswar 9777949614 call me Independent Escort Service Bhubaneswar
 
Call girls Service Bellary - 9332606886 Rs 3000 Free Pickup & Drop Services 2...
Call girls Service Bellary - 9332606886 Rs 3000 Free Pickup & Drop Services 2...Call girls Service Bellary - 9332606886 Rs 3000 Free Pickup & Drop Services 2...
Call girls Service Bellary - 9332606886 Rs 3000 Free Pickup & Drop Services 2...
 
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
 
Dahod Call Girl 📞 8617370543 Low Price Genuine Service
Dahod Call Girl 📞 8617370543 Low Price Genuine ServiceDahod Call Girl 📞 8617370543 Low Price Genuine Service
Dahod Call Girl 📞 8617370543 Low Price Genuine Service
 
Banda call girls 📞 8617370543At Low Cost Cash Payment Booking
Banda call girls 📞 8617370543At Low Cost Cash Payment BookingBanda call girls 📞 8617370543At Low Cost Cash Payment Booking
Banda call girls 📞 8617370543At Low Cost Cash Payment Booking
 
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
 
📞 Contact Number 8617370543VIP diu Call Girls
📞 Contact Number 8617370543VIP diu Call Girls📞 Contact Number 8617370543VIP diu Call Girls
📞 Contact Number 8617370543VIP diu Call Girls
 
Call Girls Surat Just Call 8617370543 Top Class Call Girl Service Available
Call Girls Surat Just Call 8617370543 Top Class Call Girl Service AvailableCall Girls Surat Just Call 8617370543 Top Class Call Girl Service Available
Call Girls Surat Just Call 8617370543 Top Class Call Girl Service Available
 
Exclusive Ahmedabad Call Girls 💯Call Us 🔝 6378878445 🔝 💃 Top Class Call Girl...
Exclusive  Ahmedabad Call Girls 💯Call Us 🔝 6378878445 🔝 💃 Top Class Call Girl...Exclusive  Ahmedabad Call Girls 💯Call Us 🔝 6378878445 🔝 💃 Top Class Call Girl...
Exclusive Ahmedabad Call Girls 💯Call Us 🔝 6378878445 🔝 💃 Top Class Call Girl...
 
Pakistani Call girls in Deira 0567006274 Deira Call girls
Pakistani Call girls in Deira 0567006274 Deira Call girlsPakistani Call girls in Deira 0567006274 Deira Call girls
Pakistani Call girls in Deira 0567006274 Deira Call girls
 
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...
 
Bhubaneswar🌹Call Girls Rasulgada ❤Komal 9777949614 💟 Full Trusted CALL GIRLS ...
Bhubaneswar🌹Call Girls Rasulgada ❤Komal 9777949614 💟 Full Trusted CALL GIRLS ...Bhubaneswar🌹Call Girls Rasulgada ❤Komal 9777949614 💟 Full Trusted CALL GIRLS ...
Bhubaneswar🌹Call Girls Rasulgada ❤Komal 9777949614 💟 Full Trusted CALL GIRLS ...
 
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
 
Call Girls Belonia Just Call 📞 8617370543 Top Class Call Girl Service Available
Call Girls Belonia Just Call 📞 8617370543 Top Class Call Girl Service AvailableCall Girls Belonia Just Call 📞 8617370543 Top Class Call Girl Service Available
Call Girls Belonia Just Call 📞 8617370543 Top Class Call Girl Service Available
 
Call girls Service Pondicherry ( 9332606886 ) Cheap rates call girls | Get lo...
Call girls Service Pondicherry ( 9332606886 ) Cheap rates call girls | Get lo...Call girls Service Pondicherry ( 9332606886 ) Cheap rates call girls | Get lo...
Call girls Service Pondicherry ( 9332606886 ) Cheap rates call girls | Get lo...
 
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 ...
 

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.