Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
20
Task/Nim-game/Prolog/nim-game.pro
Normal file
20
Task/Nim-game/Prolog/nim-game.pro
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
nim :- next_turn(12), !.
|
||||
|
||||
next_turn(N) :-
|
||||
% Player Turn
|
||||
format('How many dots would you like to take? '),
|
||||
read_line_to_codes(user_input, Line),
|
||||
number_codes(PlayerGuess, Line),
|
||||
member(PlayerGuess,[1,2,3]),
|
||||
N1 is N - PlayerGuess,
|
||||
format('You take ~d dots~n~d dots remaining.~n~n', [PlayerGuess, N1]),
|
||||
|
||||
% Computer Turn
|
||||
CompGuess is 4 - PlayerGuess,
|
||||
N2 is N1 - CompGuess,
|
||||
format('Computer takes ~d dots~n~d dots remaining.~n~n', [CompGuess, N2]),
|
||||
(
|
||||
N2 = 0
|
||||
-> format('Computer wins!')
|
||||
; next_turn(N2)
|
||||
).
|
||||
Loading…
Add table
Add a link
Reference in a new issue