Skip to content

Commit

Permalink
comments
Browse files Browse the repository at this point in the history
  • Loading branch information
friguzzi committed Jun 18, 2016
1 parent f312553 commit 533dbad
Showing 1 changed file with 41 additions and 39 deletions.
80 changes: 41 additions & 39 deletions examples/inference/truel.pl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
hitting the target (if they are not aiming at the sky): a 1/3, b 2/3 and c 1.
The question is: what should a do to maximize his probability of living?
Aim at b, c or the sky?
Note that the best strategy for the other truelists and situations is
easy to find intuitively and corresponds to aim at the best shooter.
See https://en.wikipedia.org/wiki/Truel
Martin Shubik, Game Theory and Related Approaches to Social Behavior, 1964, page 43
Expand Down Expand Up @@ -36,36 +38,6 @@


:- begin_lpad.
/**
* survives(+List:list,+Individual:atom,Round:term).
*
* Individual survives the truel with List starting at Round
*
*/
survives([A],A,_):-!.

survives(L,A,T):-
survives_round(L,L,A,T).
/**
* survives_round(+Rest:list,+List:list,+Individual:atom,+Round:term)
*
* Individual survives the truel Round with Rest still to shoot and
* List truelist still alive
*/
survives_round(_,[A],A,_,[A]):-!.

survives_round(_,[_],_,_,_):-!,fail.

survives_round([],L,A,T):-
survives(L,A,s(T)).

survives_round([H|Rest],L0,A,T):-
best_strategy_base(H,Rest,L0,S),
shoot(H,S,Rest,L0,T,Rest1,L1),
member(A,L1),
survives_round(Rest1,L1,A,T).


/**
* best_strategy(+A:atom,+Rest:list,+L:list,-S:atom).
*
Expand Down Expand Up @@ -130,22 +102,52 @@
hit(_,c):1.

/**
* best_strategy_base(+A:atom,+Rest:list,+T:list,-S:atom).
* survives(+List:list,+Individual:atom,Round:term).
*
* Individual survives the truel with List starting at Round
*
*/
survives([A],A,_):-!.

survives(L,A,T):-
survives_round(L,L,A,T).
/**
* survives_round(+Rest:list,+List:list,+Individual:atom,+Round:term)
*
* Individual survives the truel Round with Rest still to shoot and
* List truelist still alive
*/
survives_round(_,[A],A,_,[A]):-!.

survives_round(_,[_],_,_,_):-!,fail.

survives_round([],L,A,T):-
survives(L,A,s(T)).

survives_round([H|Rest],L0,A,T):-
base_best_strategy(H,Rest,L0,S),
shoot(H,S,Rest,L0,T,Rest1,L1),
member(A,L1),
survives_round(Rest1,L1,A,T).


/**
* base_best_strategy(+A:atom,+Rest:list,+T:list,-S:atom).
*
* the best action for A when Rest follow him in the round and
* T is the list of surviving truelist, is S (with '$' for the sky)
*
* These are the strategies that are easy to find (most intuitive)
*
*/
best_strategy_base(b,[c],[b,c],c).
best_strategy_base(c,[],[b,c],b).
best_strategy_base(a,[c],[a,c],c).
best_strategy_base(c,[],[a,c],a).
best_strategy_base(a,[b],[a,b],b).
best_strategy_base(b,[],[a,b],a).
best_strategy_base(b,[c],[a,b,c],c).
best_strategy_base(c,[],[a,b,c],b).
base_best_strategy(b,[c],[b,c],c).
base_best_strategy(c,[],[b,c],b).
base_best_strategy(a,[c],[a,c],c).
base_best_strategy(c,[],[a,c],a).
base_best_strategy(a,[b],[a,b],b).
base_best_strategy(b,[],[a,b],a).
base_best_strategy(b,[c],[a,b,c],c).
base_best_strategy(c,[],[a,b,c],b).


:- end_lpad.
Expand Down

0 comments on commit 533dbad

Please sign in to comment.