Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
en:dydaktyka:ggp:gdl [2019/01/03 22:48]
msl [Fluents]
en:dydaktyka:ggp:gdl [2021/01/12 01:05] (current)
msl [Fluents]
Line 27: Line 27:
 Let's start with players "​nought"​ and "​cross"​. There is a special fact ''​role''​ just to do that: Let's start with players "​nought"​ and "​cross"​. There is a special fact ''​role''​ just to do that:
  
-<​code ​prolog>+<​code>​
 role(nought) role(nought)
 role(cross) role(cross)
Line 56: Line 56:
 </​code>​ </​code>​
  
-Here '':​-'' ​reprenst ​implication ''<​-''​. ''&''​ is a logical and. In natural language the first line means: "if M and N represent cells' indexes, then there is a fluent for cell with (M, N) coordinates,​ telling there is a cross in it". If we didn't use rules, we could write all the fluents by hand:+Here '':​-'' ​represents an implication ''<​-''​. ''&''​ is a logical ​"and". In natural language the first line means: "if M and N represent cells' indexes, then there is a fluent for cell with (M, N) coordinates,​ telling there is a cross in it". If we didn't use rules, we could write all the fluents by hand:
  
-<​code ​prolog>+<​code>​
 base(cell(1,​1,​x)) ​   base(cell(1,​1,​o)) ​   base(cell(1,​1,​b)) base(cell(1,​1,​x)) ​   base(cell(1,​1,​o)) ​   base(cell(1,​1,​b))
 base(cell(1,​2,​x)) ​   base(cell(1,​2,​o)) ​   base(cell(1,​2,​b)) base(cell(1,​2,​x)) ​   base(cell(1,​2,​o)) ​   base(cell(1,​2,​b))
Line 73: Line 73:
  
  
-Rules in GDL have one special feature: they can recurse, but they can't loop forever. ​ [[http://​www.inf.tu-dresden.de/​content/​institutes/​ki/​cl/​study/​winter09/​ggp/​kapitel2.pdf|More details here]].+Rules in GDL have one special feature: they can recurse, but they can't loop forever. ​ [[http://​www.inf.tu-dresden.de/​content/​institutes/​ki/​cl/​study/​winter09/​ggp/​kapitel2.pdf|More details here]].
  
 ==== Available Actions ==== ==== Available Actions ====
Line 87: Line 87:
 In order to define an action we use the ''​input''​ predicate: In order to define an action we use the ''​input''​ predicate:
  
-<​code ​prolog>+<​code>​
 input(R, mark(M,N)) :- role(R) & index(M) & index(N) input(R, mark(M,N)) :- role(R) & index(M) & index(N)
 input(R, noop) :- role(R) input(R, noop) :- role(R)
Line 116: Line 116:
 Now we have to define the initial state of the game (draw the empty board). The ''​init''​ predicate serves this purpose. For the tic-tac-toe every cell should be empty, and the ''​nought''​ player should play first. Now we have to define the initial state of the game (draw the empty board). The ''​init''​ predicate serves this purpose. For the tic-tac-toe every cell should be empty, and the ''​nought''​ player should play first.
  
-<​code ​prolog>+<​code>​
 init(cell(M,​N,​b)) :- index(M) & index(N) init(cell(M,​N,​b)) :- index(M) & index(N)
 init(control(nought)) init(control(nought))
Line 126: Line 126:
 To define the state evolution we use the ''​next''​ predicate, defining the fluent state in the next turn. The '​does'​ predicate check what actions were made by the players during the current turn. To define the state evolution we use the ''​next''​ predicate, defining the fluent state in the next turn. The '​does'​ predicate check what actions were made by the players during the current turn.
  
-<​code ​prolog>+<​code>​
 next(cell(M,​N,​x)) :- next(cell(M,​N,​x)) :-
   does(cross,​mark(M,​N)) &   does(cross,​mark(M,​N)) &
Line 169: Line 169:
 Every player knows that there are two ways to finish the game: make a line or fill all the available cells. Now we will check if there was a line made by the player. Every player knows that there are two ways to finish the game: make a line or fill all the available cells. Now we will check if there was a line made by the player.
  
-<​code ​prolog>+<​code>​
 line(Z) :- row(M,Z) line(Z) :- row(M,Z)
 line(Z) :- column(M,Z) line(Z) :- column(M,Z)
Line 199: Line 199:
 Now we can define the ending conditions with the ''​terminal''​ predicate: Now we can define the ending conditions with the ''​terminal''​ predicate:
  
-<​code ​prolog>+<​code>​
 terminal :- line(x) terminal :- line(x)
 terminal :- line(o) terminal :- line(o)
Line 219: Line 219:
 Bots don't have feelings but we still should give them prize for the good game. And we do this with the ''​goal''​ predicate: Bots don't have feelings but we still should give them prize for the good game. And we do this with the ''​goal''​ predicate:
  
-<​code ​prolog>+<​code>​
 goal(cross,​100) :- line(x) & ~line(o) goal(cross,​100) :- line(x) & ~line(o)
 goal(cross,​50) :- ~line(x) & ~line(o) goal(cross,​50) :- ~line(x) & ~line(o)
Line 243: Line 243:
 Let's take an even simpler game: Let's take an even simpler game:
  
-<​code ​prolog>+<​code>​
  
 role(white) role(white)
Line 299: Line 299:
  
 {{ :​pl:​dydaktyka:​ggp:​rock-paper-spock.jpg?​300|}} {{ :​pl:​dydaktyka:​ggp:​rock-paper-spock.jpg?​300|}}
-Please model the "Rock Paper Scissors Lizard Spock" game. You can learn the rules from this [[https://​www.youtube.com/​watch?​v=iapcKVn7DdY|video]]. The image on the right is also a good reference. You can practice it with a colleague or like a modern man: [[http://www.playmycode.com/​play/​game/​cainy393/​rock-paper-scissors-lizard-spock|online...]].+Please model the "Rock Paper Scissors Lizard Spock" game. You can learn the rules from this [[https://​www.youtube.com/​watch?​v=iapcKVn7DdY|video]]. The image on the right is also a good reference. You can practice it with a colleague or like a modern man: [[https://rpsls.net|online...]].
  
 ===== - Knowledge Interchange Format ===== ===== - Knowledge Interchange Format =====
Line 305: Line 305:
 Everything we learned so far is true, but the GDL has an alternative syntax used to store and transfer the games: the Knowledge Interchange Format. It's based on a lisp and uses a prefix notation. Moreover '':​-''​ operator is replaced with ''<​='',​ ''&''​ with ''​and'',​ negation ''​~''​ with ''​not''​. The variables start with the ''?''​. Below you can see an example of translation between Prolog: Everything we learned so far is true, but the GDL has an alternative syntax used to store and transfer the games: the Knowledge Interchange Format. It's based on a lisp and uses a prefix notation. Moreover '':​-''​ operator is replaced with ''<​='',​ ''&''​ with ''​and'',​ negation ''​~''​ with ''​not''​. The variables start with the ''?''​. Below you can see an example of translation between Prolog:
  
-<​code ​prolog>+<​code>​
 p(a,​Y) ​                 ​ p(a,​Y) ​                 ​
 ~p(a,​Y) ​                 ~p(a,​Y) ​                
Line 315: Line 315:
 and KIF: and KIF:
  
-<​code ​lisp>+<​code ​scheme>
 (p a ?y) (p a ?y)
 (not (p a ?y)) (not (p a ?y))
Line 327: Line 327:
 For every example below, tell if the KIF version is a faithful translation of the Prolog one. For every example below, tell if the KIF version is a faithful translation of the Prolog one.
  
-<​code ​lisp>+<​code ​scheme>
 r(a,b) :- p(a) & q(b) r(a,b) :- p(a) & q(b)
 (<= (r a b) (and (p a) (q b))) (<= (r a b) (and (p a) (q b)))
 </​code>​ </​code>​
-<​code ​lisp+<​code ​scheme
 r(a,b) :- p(a) & q(b) r(a,b) :- p(a) & q(b)
 (<= (r a b) (p a) (q b)) (<= (r a b) (p a) (q b))
 </​code>​ </​code>​
-<​code ​lisp>+<​code ​scheme>
 r(x,y) :- p(x) & q(y) r(x,y) :- p(x) & q(y)
 (<= (r ?x ?y) (p ?x) (q ?y)) (<= (r ?x ?y) (p ?x) (q ?y))
 </​code>​ </​code>​
-<​code ​lisp+<​code ​scheme
 r(X,Y) :- p(X) & q(Y) r(X,Y) :- p(X) & q(Y)
 (<= (r ?x ?y) (p ?x) (q ?y)) (<= (r ?x ?y) (p ?x) (q ?y))
en/dydaktyka/ggp/gdl.1546552090.txt.gz · Last modified: 2019/06/27 16:00 (external edit)
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0