Difference between revisions of "Tic-Tac-Toe"
(Created page with "= A behavioral program for the game of Tic-Tac-Toe = * Download the example from LINK == b-Threads == === Rules of the game === * SquareTaken: block further marking of a ...") |
|||
Line 1: | Line 1: | ||
− | = A behavioral program for the game of Tic-Tac-Toe = | + | = A behavioral program for the game of Tic-Tac-Toe = |
− | * Download the example from | + | * Download the example from |
− | == b-Threads == | + | == 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:[[File:Example.jpg]] | ||
+ | |||
+ | |||
+ | == b-Threads == | ||
=== Rules of the game === | === Rules of the game === | ||
* SquareTaken: block further marking of a square already marked by X or O. | * SquareTaken: block further marking of a square already marked by X or O. |
Revision as of 07:42, 7 April 2014
Contents
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.