http://logic.stanford.edu/ggp/chapters/chapter_02.html
role(a) means that a is a role in the game.
base(p) means that p is a base proposition in the game.
input(r,a) means that a is a feasible action for role r.
init(p) means that the proposition p is true in the initial state.
true(p) means that the proposition p is true in the current state.
does(r,a) means that role r performs action a in the current state.
next(p) means that the proposition p is true in the next state.
legal(r,a) means it is legal for role r to play action a in the current state.
distinct(p,r) requires that two terms be syntactically different.
goal(r,n) means that player the current state has utility n for player r.
terminal means that the current state is a terminal state.
The role step determines the various roles in the game. This includes players and the special role “Random”
Each Player needs its own role, for example in Tic-Tac-Toe there is an X player and an O player.
The init step is used to set up the initial state of the game
Describes the change in state for each action made by a player.
There are restrictions on the formatting of rules/actions that force them to be “safe”, meaning that any variable used in the declaration must also show up in “and” chain of the body, and any variable in a negated condition must also appear in a non-negated condition in the body's “and” chain. This is a requirement for all GDL programs.
True makes sure a state of the game is true, such as a player having control or having a certain amount of points/cards/etc. It can also be used as a wildcard to introduce variable that are used in later declarations.
Ex:
(<= (legal ?player (buy ?card)) (true (control ?player)) ;player's turn (distinct ?player random) (cost ?card ?price) (true (money ?player ?x)) ;introduces a variable x for use later (greater_than_equals ?x ?price) ;variable x from true statement above used here (true (table ?y ?card)) ;introduces the variable y for use in making sure that the number of cards is not 0 (distinct ?y 0))
This is an example of being able to buy a card. The true statements are numbered from top to bottom:
These are ideas that would make generating games easier for genetic algorithms.
http://logic.stanford.edu/ggp/chapters/chapter_17.html
Deal Face Down Card:
(<= (legal random deal(?Player,?Card)) (true (role(?Player)) (true (distinct(?Player,random)) (true (indeck(?Card)))) (<= (next (holds(?Player,?Card)) (does random deal(?Player,?Card)) (sees(?Player,?Card) (does random deal(?Player,?Card))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Tictactoe ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Roles ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(role xplayer) (role oplayer)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Base & Input ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(index 1) (index 2) (index 3)
(⇐ (base (cell ?x ?y b)) (index ?x) (index ?y))
(⇐ (base (cell ?x ?y x)) (index ?x) (index ?y))
(⇐ (base (cell ?x ?y o)) (index ?x) (index ?y))
(⇐ (base (control ?p)) (role ?p))
(⇐ (input ?p (mark ?x ?y)) (index ?x) (index ?y) (role ?p))
(⇐ (input ?p noop) (role ?p))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Initial State ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(init (cell 1 1 b))
(init (cell 1 2 b))
(init (cell 1 3 b))
(init (cell 2 1 b))
(init (cell 2 2 b))
(init (cell 2 3 b))
(init (cell 3 1 b))
(init (cell 3 2 b))
(init (cell 3 3 b))
(init (control xplayer))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Dynamic Components ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Cell
(⇐ (next (cell ?m ?n x)) (does xplayer (mark ?m ?n)) (true (cell ?m ?n b)))
(⇐ (next (cell ?m ?n o)) (does oplayer (mark ?m ?n)) (true (cell ?m ?n b)))
(⇐ (next (cell ?m ?n ?w)) (true (cell ?m ?n ?w)) (distinct ?w b))
(⇐ (next (cell ?m ?n b)) (does ?w (mark ?j ?k)) (true (cell ?m ?n b)) (or (distinct ?m ?j) (distinct ?n ?k)))
(⇐ (next (control xplayer)) (true (control oplayer)))
(⇐ (next (control oplayer)) (true (control xplayer)))
(⇐ (row ?m ?x) (true (cell ?m 1 ?x)) (true (cell ?m 2 ?x)) (true (cell ?m 3 ?x)))
(⇐ (column ?n ?x) (true (cell 1 ?n ?x)) (true (cell 2 ?n ?x)) (true (cell 3 ?n ?x)))
(⇐ (diagonal ?x) (true (cell 1 1 ?x)) (true (cell 2 2 ?x)) (true (cell 3 3 ?x)))
(⇐ (diagonal ?x) (true (cell 1 3 ?x)) (true (cell 2 2 ?x)) (true (cell 3 1 ?x)))
(⇐ (line ?x) (row ?m ?x)) (⇐ (line ?x) (column ?m ?x)) (⇐ (line ?x) (diagonal ?x))
(⇐ open (true (cell ?m ?n b)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(⇐ (legal ?w (mark ?x ?y)) (true (cell ?x ?y b)) (true (control ?w)))
(⇐ (legal xplayer noop) (true (control oplayer)))
(⇐ (legal oplayer noop) (true (control xplayer)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(⇐ (goal xplayer 100) (line x))
(⇐ (goal xplayer 50) (not (line x)) (not (line o)) (not open))
(⇐ (goal xplayer 0) (line o))
(⇐ (goal oplayer 100) (line o))
(⇐ (goal oplayer 50) (not (line x)) (not (line o)) (not open))
(⇐ (goal oplayer 0) (line x))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(⇐ terminal (line x))
(⇐ terminal (line o))
(⇐ terminal (not open))