DESCRIPTION OF THE GDL-II LANGUAGE

Basic Functions

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.

Role

The role step determines the various roles in the game. This includes players and the special role “Random”

  • Random denotes a player that is controlled by the game controller itself that performs game actions such as dealing cards, rolling dice, shuffling, and other non-player events/actions.

Each Player needs its own role, for example in Tic-Tac-Toe there is an X player and an O player.

INIT

The init step is used to set up the initial state of the game

NEXT

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

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:

  1. This move is legal if the player has control (it's the player's turn).
  2. The player has money, but because variables were entered, there is no comparison that can be made, so the current value of the statement gets applied to the variable. For example, if the player1 had 5 silver, the current game state would include (money player1 5), so 5 would be assigned to the variable x. This variable is then used in a comparison that makes sure the x(5) is greater than or equal to the price of the card.
  3. the last is similar to the one above. The games current state get assigned to the empty variable y. This checks to make sure that there are cards to buy by making sure in the next line that the value of y is not 0.

Ideas for Generality

These are ideas that would make generating games easier for genetic algorithms.

  • Be verbose in explaining base propositions for the game, even if they can be condensed into fewer.
  • For turn-based games, have a unique action/legal move for ending turn. This way no matter how many actions the player may be able to make in their turn, the turn will not change until the player decides to or they run out of legal actions.

Piece Examples

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))))
       

EXAMPLE GAME TIC-TAC-TOE

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; 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))

mind/newdeck/gdl-ii.txt · Last modified: 2017/02/18 16:26 by mdebuse
Back to top
CC Attribution-Share Alike 4.0 International
chimeric.de = chi`s home Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0