-
Notifications
You must be signed in to change notification settings - Fork 1
Home
Kevin Damm edited this page Oct 26, 2023
·
5 revisions
GGDL is a language and runtime semantics for describing games and generating client and server implementations for any game describable by the language, ranging from combinatorial games like Tic Tac Toe and Go, to games of indeterminacy with dice and cards, and even games of epistemology like quizzes and crosswords.
GGDL is an extension of GDL. If you are unfamiliar with that topic, the Stanford book on General Game Playing is an excellent resource.
An example of a small game, Janken a.k.a. Rock-Paper-Scissors or Roshambo:
// Roles are similar to GDL for defining players, GGDL adds the ability to
// provide data typing for properties that can be accessed at runtime.
role left, right {
name: string
skintone: string | undefined
match_history: []boolean
playing: Hand
}
// Finite sets can be defined as constant types.
data Hand = ROCK | PAPER | SCISSORS
// Most keywords are adopted directly from GDL to make translation easier.
// `terminal` is a special boolean that ends the game when it is true.
terminal :- wins(?p, ?o)
wins(?p, ?o) :- role(?p) and role(?o) and
(covers(?p, ?o) or crushes(?p, ?o) or cuts(?p, ?o)
// Some keywords are inherently binary operations and have been replaced
// with symbols and syntactical structure that are more intuitive than
// the magic functions that would be created from a direct mapping of GDL.
// "does" is represented by `->`
// "legal" is implicit when does is in the head of an inference `:-`
// "next" is represented by `==>` (also found in some infix-formatted GDL)
// The order of `:-` and `==>` are unimportant but the `->` must be bound
// directly to a role, it always comes before the other two.
// A player may choose any Hand option.
?p -> choice(?hand)
:- role(?p) and Hand(?hand)
==> ?p.playing = ?hand
goal ?p = 100 :- wins(?p, ?o)
goal ?p = 0 :- wins(?o, ?p)
// Views are defined declaratively not procedurally, similar to GDL. This allows
// the client and server to implement KB updates and belief propagation in a way
// that is most suitable to the context.
covers(?p, ?o) :- ?p.playing == PAPER and ?o.playing == ROCK
crushes(?p, ?o) :- ?p.playing == ROCK and ?o.playing == SCISSORS
cuts(?p, ?o) :- ?p.playing == SCISSORS and ?o.playing == PAPER