-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCover.pl
34 lines (29 loc) · 1.8 KB
/
Cover.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
%*****************%
%******Cover******%
%*****************%
:-["Bag.pl"].
%initializeCover / 1
%initializeCover (Cover)
%Generates a cover (Cover) for the start of the game with 0 tiles of each color.
initializeCover ([[blue, 0], [yellow, 0], [white, 0], [black, 0], [red, 0]]).
%initializeCover / 4
%initializeCover (Bag, Cover, BagR, CoverR, NeedBool)
%Puts all tiles from the cover (Cover) into the Bag, if needed.
initializeCover (Bag, Cover, Bag, Cover, 0): - !.
initializeCover (Bag, [[blue, 0], [yellow, 0], [white, 0], [black, 0], [red, 0]], Bag, [[blue, 0], [yellow, 0] , [white, 0], [black, 0], [red, 0]], 1): - !.
initializeCover (Bag, [[Color, CantColor] | CoverList], BagR, [[Color, 0] | CoverListR], 1): - putNColorsBag (Bag, Color, CantColor, BagT), initializeCover (BagT, CoverList, BagR, CoverListR ).
%putNColorCover / 4
%putNColorCover (Cover, Color, Quantity, CoverR)
%Puts N Blue Eyes Color on the Cover (Cover).
putNColorCover ([[Color, CantColor] | CoverL], Color, Cant, [[Color, CantColorR] | CoverLR]): - CantColorR is CantColor + Cant,!.
putNColorCover ([[OtherColor, CantOtherColor] | CoverL], Color, Cant, [[OtherColor, CantOtherColor] | CoverLR]): - putNColorCover (CoverL, Color, Cant, CoverLR).
%putNColorsCover / 3
%putNColorsCover (Cover, ListColorCant, CoverR)
%Put a list of colors (with their respective Quantityes) in the Cover.
putNColorsCover (Cover, [], Cover): - !.
putNColorsCover (Cover, [[Color, Qty], L], CoverR): - putNColorCover (Cover, Color, Qty, CoverT), putNColorsCover (CoverT, L, CoverR).
%putFloorCover / 3
%putFloorCover (Cover, ListColor, CoverR)
%Puts a list of colors (without quantity) on the Cover.
putFloorCover (Cover, [], Cover): -!
putFloorCover (Cover, [Color | ListColor], CoverR): - putNColorCover (Cover, Color, 1, CoverT), putFloorCover (CoverT, ListColor, CoverR).