Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- house(5,4).
- wall(v,2,3,4).
- wall(v,3,0,1).
- wall(v,4,0,1). %wall(v,x,y,y2)
- wall(h,2,3,5). %wall(h,y,x,x2)
- color(1,1,green).
- color(1,2,red).
- color(3,1,red).
- color(4,0,blue).
- % Unifies Wall with a wall in the given part.
- % Fail when no walls are found and doesn't include wall
- % that lie on the edge of the given part.
- % Unspecified behaviour when Wall is already unified when calling this clause
- wall_in_part(part(XCo1,YCo1,XCo2,YCo2),Wall) :-
- wall(Orient,Ca,Cb,S),
- (Orient = v ->
- %Ca = x; Cb = y; S = y2
- % x moet strikt binnen Part liggen
- Ca > XCo1, %wall mag niet tegen de rand liggen
- Ca < XCo2,
- % onderste y moet strikt onder de bovenkant beginnen
- % eind-y moet strik boven de onderkant liggen
- S > YCo1,
- Cb < YCo2
- ; %assumes only v and h will be used as orientation for walls.
- %Ca = y; Cb = x; S = x2
- Cb < XCo2, %mag niet beginnen aan rechter kant
- S > XCo1,
- % y moet strikt binnen Part liggen
- Ca > YCo1, %mag niet op rand liggen
- Ca < YCo2
- ),
- Wall = wall(Orient,Ca,Cb,S).
- color_in_part(part(XCo1,YCo1,XCo2,YCo2),Color) :-
- color(X,Y,Color),
- X >= XCo1, %colors CAN touch the left-bottom
- Y >= YCo1,
- X < XCo2, %but not the right-top since then they would go outside the part
- Y < YCo2.
- %Color = Col. %directly get Color when fetching one.
- single_color_present(Part) :-
- findall(Color,
- color_in_part(Part,Color),
- DColors),
- sort(DColors,Colors), % to remove doubles, there's also a build-in that only removes doubles and doesn't sort, but can't remember it now, I should use that one when I remember it
- length(Colors,ColorCount),
- ColorCount =< 1.
- part_has_wall(Part) :-
- findall(Wall,
- wall_in_part(Part,Wall),
- Walls),
- length(Walls,WallCount),
- WallCount >= 1.
- cut_plan(CuttingPlan,Parts) :-
- house(Top,Right),
- cut_part(part(0,0,Top,Right), CuttingPlan, UParts),
- sort(UParts,Parts).
- cut_part(Part, [], Parts) :- %no cutting so cuttingplan is empty.
- \+ wall_in_part(Part,_),
- % no more walls in this part so it can't be cut further
- % check if there is only one color in this part
- single_color_present(Part),
- %if so it's a good part so we should add it to parts.
- Parts = [Part].
- cut_part(Part, CuttingPlan, Parts) :-
- wall_in_part(Part,wall(WOr,WOa,_,_)), %kies wall om op te knippen
- part(XCo1,YCo1,XCo2,YCo2) = Part, %get info of this part
- % generate cut based on wall and current part
- ( WOr = v ->
- Cut = cut(v,WOa,YCo1,YCo2),
- % make two new parts
- Part1 = part(XCo1,YCo1,WOa,YCo2), % links eerst, dan rechts
- Part2 = part(WOa,YCo1,XCo2,YCo2)
- ; %again assumes only orientations are 'v' and 'h'
- %similar to a vertical cut
- Cut = cut(h,WOa,XCo1,XCo2),
- % make two new parts
- % onderste eerst, dan bovenste
- Part1 = part(XCo1,YCo1,XCo2,WOa),
- Part2 = part(XCo1,WOa,XCo2,YCo2)
- ),
- % cut the new parts
- cut_part(Part1,CuttingPlan1,Parts1),
- cut_part(Part2,CuttingPlan2,Parts2),
- % add everything together.
- append(CuttingPlan1,CuttingPlan2,CuttingPlanTemp),
- CuttingPlan = [Cut|CuttingPlanTemp],
- append(Parts1,Parts2,Parts).
Advertisement
Add Comment
Please, Sign In to add comment