Difference between revisions of "Tic-Tac-Toe"

From BP Wiki
Jump to: navigation, search
(A behavioral program for the game of Tic-Tac-Toe)
(Game Description)
Line 10: Line 10:
  
 
A play of the game may be described as a sequence of events. E.g., the sequence
 
A play of the game may be described as a sequence of events. E.g., the sequence
X_<0,0>, O_<1,1>, X_<2,1>, O_<0,2>, X_<2,0>, O_<1,0>, X_<2,2>, XWin  describes a play in which X wins, and whose final configuration is:28. [[Image:TTT01.jpg | frame | <span style="color: rgb(0, 128, 128);"><span style="font-family: Tahoma;">Figure 1: An LSC describing the basic move of a memory game. Note the red and blue elements in the diagram, indicating hot and cold LSC messages and conditions.</span> </span>]]
+
X_<0,0>, O_<1,1>, X_<2,1>, O_<0,2>, X_<2,0>, O_<1,0>, X_<2,2>, XWin  describes a play in which X wins, and whose final configuration is:
  
 +
[[Image:TTT01.jpg | frame | <span style="color: rgb(0, 128, 128);"><span style="font-family: Tahoma;"></span> </span>]]
  
 
== b-Threads ==
 
== b-Threads ==

Revision as of 07:57, 7 April 2014

A behavioral program for the game of Tic-Tac-Toe

  • Download the example from

Game Description

Two players, X and O, alternately mark squares on a 3X3 grid whose squares are identified by <row,column> pairs: <0,0>, <0,1>, ...,<2,2>. The winner is the player who manages to form a full horizontal, vertical or diagonal line with three of his/her marks. If the entire grid becomes marked but no player has formed a line, the result is a draw.

In our example, player X should be played by a human user, and player O is played by the application. Each move (marking of a square by a player) is represented by an event, X_<row,col> or O_<row,col>. Three additional events, XWin, OWin, and draw$, represent the respective victories and a draw.

A play of the game may be described as a sequence of events. E.g., the sequence X_<0,0>, O_<1,1>, X_<2,1>, O_<0,2>, X_<2,0>, O_<1,0>, X_<2,2>, XWin describes a play in which X wins, and whose final configuration is:

b-Threads

Rules of the game

  • SquareTaken: block further marking of a square already marked by X or O.
  • EnforceTurns: alternately block O moves while waiting for X moves, and vice versa (we assume that X always plays first).
  • DetectXWin: wait for placement of three X marks in a line and request XWin.
  • DetectOWin: wait for placement of three O marks in a line and request OWin.
  • DetectDraw: wait for nine moves and request draw event.

Strategies