-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest1.pl
99 lines (95 loc) · 2.54 KB
/
test1.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
%Base case, stops when N columns are the same as desired grid size
%Draws the numbers for the columns at the bottom of the board
draw_board(N, N, _) :-
nl,
draw_col_num(N, -1),
nl.
%Intitial case, draw the numbers for the columns
draw_board(N, -1, Route) :-
draw_col_num(N, -1),
draw_board(N, 0, Route).
%Recursive predicate that draws N rows and columns
%First time this is called N must be 0
draw_board(GridSize, X, Route) :-
draw_row(GridSize, X, -1, Route),
NextX is X + 1,
draw_board(GridSize, NextX, Route).
%Draw row numbers to the right of the board less than 10
draw_row(Y, X, Y, _) :-
NextX is Y - X,
NextX =< 9,
NextX > 0,
write(' | '), write(NextX),
nl.
%Draw row numbers to the right of the board greater than 9
draw_row(Y, X, Y, _) :-
NextX is Y - X,
NextX >= 10,
write(' | '), write(NextX),
nl.
%Draw row numbers to the left of the board that are less than 10
draw_row(GridSize, X, -1, Route) :-
NextX is GridSize - X,
NextX =< 9,
NextX > 0,
write(NextX), write(' | '),
draw_row(GridSize, X, 0, Route).
%Draw numbers numbers to the left of the board that are greater than 9
draw_row(GridSize, X, -1, Route) :-
NextX is GridSize - X,
NextX >= 10,
write(NextX), write(' | '),
draw_row(GridSize, X, 0, Route).
%Draw the non-visited and non-crevice spaces on the board
draw_row(GridSize, X, Y, Route) :-
RealX is GridSize - X,
RealX > 0,
RealY is Y + 1,
\+ boundary(RealX, RealY),
\+ route_member([RealX, RealY], Route),
NextY is Y + 1,
NextY =< GridSize,
write(' _ '),
draw_row(GridSize, X, NextY, Route).
%Draw the crevices
draw_row(GridSize, X, Y, Route) :-
RealX is GridSize - X,
RealX > 0,
RealY is Y + 1,
\+ route_member([RealX, RealY], Route),
boundary(RealX, RealY),
NextY is Y + 1,
NextY =< GridSize,
write(' * '),
draw_row(GridSize, X, NextY, Route).
%Draw the route
draw_row(GridSize, X, Y, Route) :-
RealX is GridSize - X,
RealX > 0,
RealY is Y + 1,
\+ boundary(RealX, RealY),
route_member([RealX, RealY], Route),
NextY is Y + 1,
NextY =< GridSize,
write(' X '),
draw_row(GridSize, X, NextY, Route).
%Base case for the column number boundary drawer
draw_col_num(N, N):-
nl.
%Initializer for column number drawer
draw_col_num(N, -1) :-
write(' '),
draw_col_num(N, 0).
%Recursive column numberer for number less than 11
draw_col_num(N, Y) :-
NextY is Y + 1,
NextY =< 10,
write(' '), write(NextY), write(' '),
draw_col_num(N, NextY).
%Recursive column numberer for numbers greater than 10
draw_col_num(N, Y) :-
NextY is Y + 1,
NextY > 10,
NextY =< N,
write(NextY), write(' '),
draw_col_num(N, NextY).