Wuerfeln

-- ThiemoGries -- 23 Feb 2010

dice(Z,V) :- 
   dice(Z,[0,0,0,0,0,0],V).

dice(0,V,V).
dice(Z,V,VN) :-
   Z > 0,
   ZN is Z - 1,
   roll_dice(V,V2),
   dice(ZN,V2,VN).

roll_dice(V,VN) :-
   Z is random(6),
   inc(V,Z,VN).

inc([E|R],0,[EN|R]) :-
   EN is E + 1.

inc([E|R],Z,[E|RN]) :-
   Z > 0,
   ZN is Z - 1,
   inc(R,ZN,RN).
 
This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Foswiki? Send feedback