<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">
% risk -game probabilities
% Martti Meri , 15.11.2004


defe([D1,D2]) :-
    member(D1,[1,2,3,4,5,6]),
    member(D2,[1,2,3,4,5,6]).

atta([A1,A2,A3]) :-
    member(A1,[1,2,3,4,5,6]),
    member(A2,[1,2,3,4,5,6]),
    member(A3,[1,2,3,4,5,6]).

play([A1,A2,_],[D1,D2],2,0) :-
    A1 &gt; D1,
    A2 &gt; D2.
play([A1,A2,_],[D1,D2],1,1) :-
    A1 &gt; D1,
    A2 =&lt; D2.
play([A1,A2,_],[D1,D2],1,1) :-
    A1 =&lt; D1,
    A2 &gt; D2.
play([A1,A2,_],[D1,D2],0,2) :-
    A1 =&lt; D1,
    A2 =&lt; D2.

report(2,0) :-
    result(Count,AW1,Tie,DW1),
    retract(result(_,_,_,_)),
    AW2 is AW1 + 1,
    Count2 is Count + 1,
    assert(result(Count2,AW2,Tie,DW1)).

report(1,1) :-
    result(Count,AW1,Tie,DW1),
    retract(result(_,_,_,_)),
    Tie2 is Tie + 1,
    Count2 is Count + 1,
    assert(result(Count2,AW1,Tie2,DW1)).

report(0,2) :-
    result(Count,AW1,Tie,DW1),
    retract(result(_,_,_,_)),
    DW2 is DW1 + 1,
    Count2 is Count + 1,
    assert(result(Count2,AW1,Tie,DW2)).

go :-
    atta(A),
    defe(D),
    msort(A,AR),
    msort(D,DR),
    reverse(AR,AH),
    reverse(DR,DH),
    play(AH,DH,AW,DW),
    report(AW,DW),
    A = [7,7,7].

show_res :-
    result(Count,AW,Tie,DW),
    format("Games: ~d Awin ~d Tie ~d Dwin ~d \n",[Count,AW,Tie,DW]),
    AP is AW / Count,
    DP is DW / Count,
    TP is Tie / Count,
    Tot is AP + DP + TP,
    format("Probs: A  ~f Tie ~f D ~f , sum of these ~f\n",[AP,TP,DP,Tot]),
    E is 2.0 * DP + 1.0 * TP,
    format("A loss expectation ~f \n",[E]).

main :-
    retractall(result(_,_,_,_)),
    assert(result(0,0,0,0)),
    go.
main :-
    show_res.
    
�S„
</pre></body></html>