Skip to content

Commit

Permalink
Removed append and fixed some shit
Browse files Browse the repository at this point in the history
  • Loading branch information
vakeneller committed Sep 25, 2017
1 parent b5d0bf6 commit 4dbaed5
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions poker.pl
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,38 @@
color(Color),
value(Value).

% Gör detta snyggare Daniel
% Create a deck then shuffle it.
deck(L):-
createDeck(L1),
shuffle(L1, L2),
shuffle(L2, L3),
shuffle(L3, L4),
shuffle(L4, L5),
shuffle(L5, L6),
shuffle(L6, L7),
cup(L7,L).
shuffle(L1, L, 6).


% A list containing all the cards
createDeck(L):-
findall(card(X, Y), card(X, Y), L).

% Shuffle cards and finish by kupera
shuffle(L1, Result):-
% Shuffle cards X times and then end with a cup
shuffle(L, Result, 0):-
cup(L, Result).
shuffle(L1, Res, X):-
X\==0,
Y is X-1,
cut(L1, L2, L3),
merge(L2, L3, Result, 1).
merge(L2, L3, L4, 1),
shuffle(L4, Res, Y).


%Cuping the deck and then stack one half on the other
cup(L, Res):-
Res == [],
cut(L, L1, L2),
cup(L1, L2).
cup([H1|T1], [H1|T2]):-
(H1, T2 \== []),
cup(T1, T2).
cup(L, Res):-
cut(L, L1, L2),
append(L1, L2, Res). % Använd inte Append
L==[].


/* cutting the deck by a random number and putting
them together and returning a complete deck */
Expand All @@ -61,6 +69,7 @@
cut([H|T], [H|L2], L3, RanNum):-
Num is RanNum - 1, cut(T, L2, L3, Num).


% Merging of the cut list with a random element
merge([], [], [], _).
merge([], [H|T], [H|Result], _):-
Expand Down

0 comments on commit 4dbaed5

Please sign in to comment.