SlideShare una empresa de 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.

Más contenido relacionado

La actualidad más candente

Making a Game Design Document
Making a Game Design DocumentMaking a Game Design Document
Making a Game Design DocumentEqual Experts
 
Game engines and Their Influence in Game Design
Game engines and Their Influence in Game DesignGame engines and Their Influence in Game Design
Game engines and Their Influence in Game DesignPrashant Warrier
 
Gameplay and game mechanic design
Gameplay and game mechanic designGameplay and game mechanic design
Gameplay and game mechanic designmissstevenson01
 
06. Game Architecture
06. Game Architecture06. Game Architecture
06. Game ArchitectureAmin Babadi
 
Game Development Step by Step
Game Development Step by StepGame Development Step by Step
Game Development Step by StepBayu Sembada
 
Introduction to Game Development
Introduction to Game DevelopmentIntroduction to Game Development
Introduction to Game DevelopmentShaan Alam
 
Intro to Game Design
Intro to Game DesignIntro to Game Design
Intro to Game DesignGraeme Smith
 
Game genres
Game genresGame genres
Game genresaealey
 
20 Game Ideas You Should Steal
20 Game Ideas You Should Steal20 Game Ideas You Should Steal
20 Game Ideas You Should StealStuart Dredge
 
Introduction to Game Development
Introduction to Game DevelopmentIntroduction to Game Development
Introduction to Game DevelopmentiTawy Community
 
Introduction to Game Development and the Game Industry
Introduction to Game Development and the Game IndustryIntroduction to Game Development and the Game Industry
Introduction to Game Development and the Game IndustryNataly Eliyahu
 
Mobile Game Development in Unity
Mobile Game Development in UnityMobile Game Development in Unity
Mobile Game Development in UnityHakan Saglam
 
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
 
What Is A Game Engine
What Is A Game EngineWhat Is A Game Engine
What Is A Game EngineSeth Sivak
 
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
 
Game AI 101 - NPCs and Agents and Algorithms... Oh My!
Game AI 101 - NPCs and Agents and Algorithms... Oh My!Game AI 101 - NPCs and Agents and Algorithms... Oh My!
Game AI 101 - NPCs and Agents and Algorithms... Oh My!Luke Dicken
 
バンダイナムコスタジオにおけるゲームAIの歴史とこれから
バンダイナムコスタジオにおけるゲームAIの歴史とこれからバンダイナムコスタジオにおけるゲームAIの歴史とこれから
バンダイナムコスタジオにおけるゲームAIの歴史とこれからBANDAI NAMCO Studios Inc.
 

La actualidad más candente (20)

Making a Game Design Document
Making a Game Design DocumentMaking a Game Design Document
Making a Game Design Document
 
Game engines and Their Influence in Game Design
Game engines and Their Influence in Game DesignGame engines and Their Influence in Game Design
Game engines and Their Influence in Game Design
 
Gameplay and game mechanic design
Gameplay and game mechanic designGameplay and game mechanic design
Gameplay and game mechanic design
 
06. Game Architecture
06. Game Architecture06. Game Architecture
06. Game Architecture
 
Game Development Step by Step
Game Development Step by StepGame Development Step by Step
Game Development Step by Step
 
Introduction to Game Development
Introduction to Game DevelopmentIntroduction to Game Development
Introduction to Game Development
 
Street runner final
Street runner finalStreet runner final
Street runner final
 
Intro to Game Design
Intro to Game DesignIntro to Game Design
Intro to Game Design
 
Game genres
Game genresGame genres
Game genres
 
20 Game Ideas You Should Steal
20 Game Ideas You Should Steal20 Game Ideas You Should Steal
20 Game Ideas You Should Steal
 
Introduction to Game Development
Introduction to Game DevelopmentIntroduction to Game Development
Introduction to Game Development
 
Introduction to Game Development and the Game Industry
Introduction to Game Development and the Game IndustryIntroduction to Game Development and the Game Industry
Introduction to Game Development and the Game Industry
 
Mobile Game Development in Unity
Mobile Game Development in UnityMobile Game Development in Unity
Mobile Game Development in Unity
 
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
 
What is game development
What is game developmentWhat is game development
What is game development
 
What Is A Game Engine
What Is A Game EngineWhat Is A Game Engine
What Is A Game Engine
 
Game Design fundamentals
Game Design fundamentalsGame Design fundamentals
Game Design fundamentals
 
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
 
Game AI 101 - NPCs and Agents and Algorithms... Oh My!
Game AI 101 - NPCs and Agents and Algorithms... Oh My!Game AI 101 - NPCs and Agents and Algorithms... Oh My!
Game AI 101 - NPCs and Agents and Algorithms... Oh My!
 
バンダイナムコスタジオにおけるゲームAIの歴史とこれから
バンダイナムコスタジオにおけるゲームAIの歴史とこれからバンダイナムコスタジオにおけるゲームAIの歴史とこれから
バンダイナムコスタジオにおけるゲームAIの歴史とこれから
 

Similar 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
 

Similar 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

Call Girls in Barasat | 7001035870 At Low Cost Cash Payment Booking
Call Girls in Barasat | 7001035870 At Low Cost Cash Payment BookingCall Girls in Barasat | 7001035870 At Low Cost Cash Payment Booking
Call Girls in Barasat | 7001035870 At Low Cost Cash Payment Bookingnoor ahmed
 
Beautiful 😋 Call girls in Lahore 03210033448
Beautiful 😋 Call girls in Lahore 03210033448Beautiful 😋 Call girls in Lahore 03210033448
Beautiful 😋 Call girls in Lahore 03210033448ont65320
 
Sonagachi ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Rea...
Sonagachi ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Rea...Sonagachi ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Rea...
Sonagachi ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Rea...rahim quresi
 
↑Top Model (Kolkata) Call Girls Howrah ⟟ 8250192130 ⟟ High Class Call Girl In...
↑Top Model (Kolkata) Call Girls Howrah ⟟ 8250192130 ⟟ High Class Call Girl In...↑Top Model (Kolkata) Call Girls Howrah ⟟ 8250192130 ⟟ High Class Call Girl In...
↑Top Model (Kolkata) Call Girls Howrah ⟟ 8250192130 ⟟ High Class Call Girl In...noor ahmed
 
Kanpur call girls 📞 8617697112 At Low Cost Cash Payment Booking
Kanpur call girls 📞 8617697112 At Low Cost Cash Payment BookingKanpur call girls 📞 8617697112 At Low Cost Cash Payment Booking
Kanpur call girls 📞 8617697112 At Low Cost Cash Payment BookingNitya salvi
 
Independent Hatiara Escorts ✔ 9332606886✔ Full Night With Room Online Booking...
Independent Hatiara Escorts ✔ 9332606886✔ Full Night With Room Online Booking...Independent Hatiara Escorts ✔ 9332606886✔ Full Night With Room Online Booking...
Independent Hatiara Escorts ✔ 9332606886✔ Full Night With Room Online Booking...Riya Pathan
 
Science City Kolkata ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sex...
Science City Kolkata ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sex...Science City Kolkata ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sex...
Science City Kolkata ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sex...rahim quresi
 
Hotel And Home Service Available Kolkata Call Girls South End Park ✔ 62971435...
Hotel And Home Service Available Kolkata Call Girls South End Park ✔ 62971435...Hotel And Home Service Available Kolkata Call Girls South End Park ✔ 62971435...
Hotel And Home Service Available Kolkata Call Girls South End Park ✔ 62971435...ritikasharma
 
Call Girls Agency In Goa 💚 9316020077 💚 Call Girl Goa By Russian Call Girl ...
Call Girls  Agency In Goa  💚 9316020077 💚 Call Girl Goa By Russian Call Girl ...Call Girls  Agency In Goa  💚 9316020077 💚 Call Girl Goa By Russian Call Girl ...
Call Girls Agency In Goa 💚 9316020077 💚 Call Girl Goa By Russian Call Girl ...russian goa call girl and escorts service
 
Book Paid Sonagachi Call Girls Kolkata 𖠋 8250192130 𖠋Low Budget Full Independ...
Book Paid Sonagachi Call Girls Kolkata 𖠋 8250192130 𖠋Low Budget Full Independ...Book Paid Sonagachi Call Girls Kolkata 𖠋 8250192130 𖠋Low Budget Full Independ...
Book Paid Sonagachi Call Girls Kolkata 𖠋 8250192130 𖠋Low Budget Full Independ...noor ahmed
 
Verified Trusted Call Girls Tambaram Chennai ✔✔7427069034 Independent Chenna...
Verified Trusted Call Girls Tambaram Chennai ✔✔7427069034  Independent Chenna...Verified Trusted Call Girls Tambaram Chennai ✔✔7427069034  Independent Chenna...
Verified Trusted Call Girls Tambaram Chennai ✔✔7427069034 Independent Chenna... Shivani Pandey
 
VIP Model Call Girls Koregaon Park ( Pune ) Call ON 8005736733 Starting From ...
VIP Model Call Girls Koregaon Park ( Pune ) Call ON 8005736733 Starting From ...VIP Model Call Girls Koregaon Park ( Pune ) Call ON 8005736733 Starting From ...
VIP Model Call Girls Koregaon Park ( Pune ) Call ON 8005736733 Starting From ...SUHANI PANDEY
 
VIP Model Call Girls Budhwar Peth ( Pune ) Call ON 8005736733 Starting From 5...
VIP Model Call Girls Budhwar Peth ( Pune ) Call ON 8005736733 Starting From 5...VIP Model Call Girls Budhwar Peth ( Pune ) Call ON 8005736733 Starting From 5...
VIP Model Call Girls Budhwar Peth ( Pune ) Call ON 8005736733 Starting From 5...SUHANI PANDEY
 
Model Call Girls In Ariyalur WhatsApp Booking 7427069034 call girl service 24...
Model Call Girls In Ariyalur WhatsApp Booking 7427069034 call girl service 24...Model Call Girls In Ariyalur WhatsApp Booking 7427069034 call girl service 24...
Model Call Girls In Ariyalur WhatsApp Booking 7427069034 call girl service 24... Shivani Pandey
 
Independent Sonagachi Escorts ✔ 9332606886✔ Full Night With Room Online Booki...
Independent Sonagachi Escorts ✔ 9332606886✔ Full Night With Room Online Booki...Independent Sonagachi Escorts ✔ 9332606886✔ Full Night With Room Online Booki...
Independent Sonagachi Escorts ✔ 9332606886✔ Full Night With Room Online Booki...Riya Pathan
 
Bhimtal ❤CALL GIRL 8617697112 ❤CALL GIRLS IN Bhimtal ESCORT SERVICE❤CALL GIRL
Bhimtal ❤CALL GIRL 8617697112 ❤CALL GIRLS IN Bhimtal ESCORT SERVICE❤CALL GIRLBhimtal ❤CALL GIRL 8617697112 ❤CALL GIRLS IN Bhimtal ESCORT SERVICE❤CALL GIRL
Bhimtal ❤CALL GIRL 8617697112 ❤CALL GIRLS IN Bhimtal ESCORT SERVICE❤CALL GIRLNitya salvi
 
Top Rated Pune Call Girls Pimpri Chinchwad ⟟ 6297143586 ⟟ Call Me For Genuin...
Top Rated  Pune Call Girls Pimpri Chinchwad ⟟ 6297143586 ⟟ Call Me For Genuin...Top Rated  Pune Call Girls Pimpri Chinchwad ⟟ 6297143586 ⟟ Call Me For Genuin...
Top Rated Pune Call Girls Pimpri Chinchwad ⟟ 6297143586 ⟟ Call Me For Genuin...Call Girls in Nagpur High Profile
 
↑Top Model (Kolkata) Call Girls Behala ⟟ 8250192130 ⟟ High Class Call Girl In...
↑Top Model (Kolkata) Call Girls Behala ⟟ 8250192130 ⟟ High Class Call Girl In...↑Top Model (Kolkata) Call Girls Behala ⟟ 8250192130 ⟟ High Class Call Girl In...
↑Top Model (Kolkata) Call Girls Behala ⟟ 8250192130 ⟟ High Class Call Girl In...noor ahmed
 
📞 Contact Number 8617697112 VIP Ganderbal Call Girls
📞 Contact Number 8617697112 VIP Ganderbal Call Girls📞 Contact Number 8617697112 VIP Ganderbal Call Girls
📞 Contact Number 8617697112 VIP Ganderbal Call GirlsNitya salvi
 

Último (20)

Call Girls in Barasat | 7001035870 At Low Cost Cash Payment Booking
Call Girls in Barasat | 7001035870 At Low Cost Cash Payment BookingCall Girls in Barasat | 7001035870 At Low Cost Cash Payment Booking
Call Girls in Barasat | 7001035870 At Low Cost Cash Payment Booking
 
Beautiful 😋 Call girls in Lahore 03210033448
Beautiful 😋 Call girls in Lahore 03210033448Beautiful 😋 Call girls in Lahore 03210033448
Beautiful 😋 Call girls in Lahore 03210033448
 
Sonagachi ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Rea...
Sonagachi ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Rea...Sonagachi ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Rea...
Sonagachi ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Rea...
 
↑Top Model (Kolkata) Call Girls Howrah ⟟ 8250192130 ⟟ High Class Call Girl In...
↑Top Model (Kolkata) Call Girls Howrah ⟟ 8250192130 ⟟ High Class Call Girl In...↑Top Model (Kolkata) Call Girls Howrah ⟟ 8250192130 ⟟ High Class Call Girl In...
↑Top Model (Kolkata) Call Girls Howrah ⟟ 8250192130 ⟟ High Class Call Girl In...
 
Kanpur call girls 📞 8617697112 At Low Cost Cash Payment Booking
Kanpur call girls 📞 8617697112 At Low Cost Cash Payment BookingKanpur call girls 📞 8617697112 At Low Cost Cash Payment Booking
Kanpur call girls 📞 8617697112 At Low Cost Cash Payment Booking
 
Independent Hatiara Escorts ✔ 9332606886✔ Full Night With Room Online Booking...
Independent Hatiara Escorts ✔ 9332606886✔ Full Night With Room Online Booking...Independent Hatiara Escorts ✔ 9332606886✔ Full Night With Room Online Booking...
Independent Hatiara Escorts ✔ 9332606886✔ Full Night With Room Online Booking...
 
Science City Kolkata ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sex...
Science City Kolkata ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sex...Science City Kolkata ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sex...
Science City Kolkata ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sex...
 
Hotel And Home Service Available Kolkata Call Girls South End Park ✔ 62971435...
Hotel And Home Service Available Kolkata Call Girls South End Park ✔ 62971435...Hotel And Home Service Available Kolkata Call Girls South End Park ✔ 62971435...
Hotel And Home Service Available Kolkata Call Girls South End Park ✔ 62971435...
 
Call Girls Agency In Goa 💚 9316020077 💚 Call Girl Goa By Russian Call Girl ...
Call Girls  Agency In Goa  💚 9316020077 💚 Call Girl Goa By Russian Call Girl ...Call Girls  Agency In Goa  💚 9316020077 💚 Call Girl Goa By Russian Call Girl ...
Call Girls Agency In Goa 💚 9316020077 💚 Call Girl Goa By Russian Call Girl ...
 
Book Paid Sonagachi Call Girls Kolkata 𖠋 8250192130 𖠋Low Budget Full Independ...
Book Paid Sonagachi Call Girls Kolkata 𖠋 8250192130 𖠋Low Budget Full Independ...Book Paid Sonagachi Call Girls Kolkata 𖠋 8250192130 𖠋Low Budget Full Independ...
Book Paid Sonagachi Call Girls Kolkata 𖠋 8250192130 𖠋Low Budget Full Independ...
 
Verified Trusted Call Girls Tambaram Chennai ✔✔7427069034 Independent Chenna...
Verified Trusted Call Girls Tambaram Chennai ✔✔7427069034  Independent Chenna...Verified Trusted Call Girls Tambaram Chennai ✔✔7427069034  Independent Chenna...
Verified Trusted Call Girls Tambaram Chennai ✔✔7427069034 Independent Chenna...
 
VIP Model Call Girls Koregaon Park ( Pune ) Call ON 8005736733 Starting From ...
VIP Model Call Girls Koregaon Park ( Pune ) Call ON 8005736733 Starting From ...VIP Model Call Girls Koregaon Park ( Pune ) Call ON 8005736733 Starting From ...
VIP Model Call Girls Koregaon Park ( Pune ) Call ON 8005736733 Starting From ...
 
VIP Model Call Girls Budhwar Peth ( Pune ) Call ON 8005736733 Starting From 5...
VIP Model Call Girls Budhwar Peth ( Pune ) Call ON 8005736733 Starting From 5...VIP Model Call Girls Budhwar Peth ( Pune ) Call ON 8005736733 Starting From 5...
VIP Model Call Girls Budhwar Peth ( Pune ) Call ON 8005736733 Starting From 5...
 
Model Call Girls In Ariyalur WhatsApp Booking 7427069034 call girl service 24...
Model Call Girls In Ariyalur WhatsApp Booking 7427069034 call girl service 24...Model Call Girls In Ariyalur WhatsApp Booking 7427069034 call girl service 24...
Model Call Girls In Ariyalur WhatsApp Booking 7427069034 call girl service 24...
 
Independent Sonagachi Escorts ✔ 9332606886✔ Full Night With Room Online Booki...
Independent Sonagachi Escorts ✔ 9332606886✔ Full Night With Room Online Booki...Independent Sonagachi Escorts ✔ 9332606886✔ Full Night With Room Online Booki...
Independent Sonagachi Escorts ✔ 9332606886✔ Full Night With Room Online Booki...
 
Desi Bhabhi Call Girls In Goa 💃 730 02 72 001💃desi Bhabhi Escort Goa
Desi Bhabhi Call Girls  In Goa  💃 730 02 72 001💃desi Bhabhi Escort GoaDesi Bhabhi Call Girls  In Goa  💃 730 02 72 001💃desi Bhabhi Escort Goa
Desi Bhabhi Call Girls In Goa 💃 730 02 72 001💃desi Bhabhi Escort Goa
 
Bhimtal ❤CALL GIRL 8617697112 ❤CALL GIRLS IN Bhimtal ESCORT SERVICE❤CALL GIRL
Bhimtal ❤CALL GIRL 8617697112 ❤CALL GIRLS IN Bhimtal ESCORT SERVICE❤CALL GIRLBhimtal ❤CALL GIRL 8617697112 ❤CALL GIRLS IN Bhimtal ESCORT SERVICE❤CALL GIRL
Bhimtal ❤CALL GIRL 8617697112 ❤CALL GIRLS IN Bhimtal ESCORT SERVICE❤CALL GIRL
 
Top Rated Pune Call Girls Pimpri Chinchwad ⟟ 6297143586 ⟟ Call Me For Genuin...
Top Rated  Pune Call Girls Pimpri Chinchwad ⟟ 6297143586 ⟟ Call Me For Genuin...Top Rated  Pune Call Girls Pimpri Chinchwad ⟟ 6297143586 ⟟ Call Me For Genuin...
Top Rated Pune Call Girls Pimpri Chinchwad ⟟ 6297143586 ⟟ Call Me For Genuin...
 
↑Top Model (Kolkata) Call Girls Behala ⟟ 8250192130 ⟟ High Class Call Girl In...
↑Top Model (Kolkata) Call Girls Behala ⟟ 8250192130 ⟟ High Class Call Girl In...↑Top Model (Kolkata) Call Girls Behala ⟟ 8250192130 ⟟ High Class Call Girl In...
↑Top Model (Kolkata) Call Girls Behala ⟟ 8250192130 ⟟ High Class Call Girl In...
 
📞 Contact Number 8617697112 VIP Ganderbal Call Girls
📞 Contact Number 8617697112 VIP Ganderbal Call Girls📞 Contact Number 8617697112 VIP Ganderbal Call Girls
📞 Contact Number 8617697112 VIP Ganderbal Call Girls
 

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.