% glogic01.pl --- logic programming model for extensive form games. % created: 22 Aug 2003. (was: glogic.pl, 10 July 2003). % modified: 14,17 Sep 2003. % References: % Bonanno-Vilks's propositional logic modeling for game tree. % Aumann(1995, GEB)'s theorem of the backward induction under common knowledge. % extensive form game theory : game tree model %------------------------------------------ terminal([c,a]). terminal([d,a]). %terminal([b]). terminal([e,b]). terminal([f,b]). % payoff (play_history,player,payoff). payoff([c,a],1,0). payoff([d,a],1,2). %payoff([b],1,1). payoff([e,b],1,4). payoff([f,b],1,1). payoff([c,a],2,3). payoff([d,a],2,2). %payoff([b],2,0). payoff([e,b],2,3). payoff([f,b],2,4). player(1). player(2). % player's information (player,name,path) players_information(1,h1,[]). players_information(2,h2,[a]). players_information(2,h3,[b]). node(terminal,Y):- terminal(Y). node(players_information(J,H),Y):- players_information(J,H,Y). % possible act at information set(name,player,act) possible_act(h1,1,a). possible_act(h1,1,b). possible_act(h2,2,c). possible_act(h2,2,d). possible_act(h3,2,e). possible_act(h3,2,f). % a game play simulator --- not always rational one %---------------------------------------------- generate_play_history([],[]). generate_play_history([J|P],[A|Y]):- length(Y,K), (K>1->!,fail;true), generate_play_history(P,Y), players_information(J,H,Y), possible_act(H,J,A). % rational play model ---- backward induction % for perfect information games. %---------------------------------------------- is_rational_play(J,A,H,Y):- players_information(J,H,Y), max(U,inductive_payoff([A|Y],J,U)). inductive_payoff(Y,J,U):- payoff(Y,J,U). inductive_payoff(Y,J,U):- % member((H,Y),[(h1,[a]),(h2,[b]),(h3,[])]), is_rational_play(_J1,A,_H,Y), inductive_payoff([A|Y],J,U). inductive_payoff_vector(Y,Js,Us):- node(_,Y), findall(J,player(J),Js), findall(U, ( player(J), inductive_payoff(Y,J,U) ), Us). % maximal solution for given goal clause : a naive solver %--------------------------------------------------------- max(X,Goal):- % X: the objective variable, % Goal: the objective function and constraints, setof((X,Goal),Goal,Z), member((X,Goal),Z), \+ ( member((Y,_),Z), Y > X ). /* game tree in fig.12.2 of Vilks(1997) */ % [0] % | a1 % |_____[1] % | | c2 % | |______[3] % | | d2 % | |______[4] % | b1 % |_____[2] example(1,[ (a1;b1), \+ (a1,b1), (a1->(c2;d2)), ((c2;d2)->a1), \+ (c2,d2), (b1->(pai(1)=1,pai(2)=0)), (c2->(pai(1)=1,pai(2)=0)), (d2->(pai(1)=0,pai(2)=1)) ]). % [0] % | a1 % |_____[1] % | | c2 % | |______[3] % | | d2 % | |______[4] % | b1 % |_____[5] % | e2 % |______[6] % | f2 % |______[7] example(2,[ (a1;b1), \+ (a1,b1), (a1->(c2;d2)), ((c2;d2)->a1), \+ (c2,d2), (b1->(e2;f2)), \+ (e2,f2), (c2->(pai(1)=0,pai(2)=4)), (d2->(pai(1)=2,pai(2)=3)), (e2->(pai(1)=3,pai(2)=2)), (f2->(pai(1)=4,pai(2)=1)) ]). % rationality(2,[ (c2;d2;e2;f2), (e2->(pai(2)=<2)), (c2->(pai(2)>=4)), 2<4 ], '|-->', [\+ e2] ). % end of program