-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.pl
160 lines (123 loc) · 4.49 KB
/
utils.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
game_board_size(8). % game_board_size(-N), size of the game board, given by N*N, for Taktikus 8x8 is recommended
numberLetter(1, 'a').
numberLetter(1, 'A').
numberLetter(1, '1').
numberLetter(2, 'b').
numberLetter(2, 'B').
numberLetter(2, '2').
numberLetter(3, 'c').
numberLetter(3, 'C').
numberLetter(3, '3').
numberLetter(4, 'd').
numberLetter(4, 'D').
numberLetter(4, '4').
numberLetter(5, 'e').
numberLetter(5, 'E').
numberLetter(5, '5').
numberLetter(6, 'f').
numberLetter(6, 'F').
numberLetter(6, '6').
numberLetter(7, 'g').
numberLetter(7, 'G').
numberLetter(7, '7').
numberLetter(8, 'h').
numberLetter(8, 'H').
numberLetter(8, '8').
numberLetter(9, 'i').
numberLetter(9, 'I').
numberLetter(9, '9').
count(_, [], 0).
count(E, [E | T], N) :- count(E, T, NT),
N is NT + 1.
count(E, [H | T], N) :- H \= E,
count(E, T, N).
count_list(_, [], 0).
count_list(E, [H|T], N) :-
count(E, H, HN),
count_list(E, T, TN),
N is HN + TN.
% read_number(_,_,_):.
% Read the number from whithin a menu range.
read_number(Min,Max,Number):-
format('Option [~d-~d]: ', [Min, Max]),
read(Number),nl,
number(Number),
Number =< Max, Number >= Min.
% if the user type a wrong Number from the current menu ask again for the input.
read_number(Min,Max,Number):-
write('\e[0;91m\nInvalid option! \nChoose an option from the current menu\n\e[0;39m'),nl,
read_number(Min, Max, Number).
% index_increment_by_direction(+DirectionType, +RowIndex, +ColIndex, -RowIndex2, ColIndex2)
% Depending on the type of direction, increments the index to loop through the board.
index_increment_by_direction(top, 1, _, 0, 0):-
!.
index_increment_by_direction(top, RowIndex, ColIndex, RowIndex2, ColIndex):-
!,RowIndex2 is RowIndex - 1.
index_increment_by_direction(bottom, RowIndex, _, RowIndex2, ColIndex2):-
game_board_size(BoardSize),
RowIndex = BoardSize,
!,
RowIndex2 = 0,
ColIndex2 = 0.
index_increment_by_direction(bottom, RowIndex, ColIndex, RowIndex2, ColIndex):-
!,RowIndex2 is RowIndex + 1.
index_increment_by_direction(right, _, ColIndex, RowIndex2, ColIndex2):-
game_board_size(BoardSize),
ColIndex = BoardSize,
!,
RowIndex2 = 0,
ColIndex2 = 0.
index_increment_by_direction(right, RowIndex, ColIndex, RowIndex, ColIndex2):-
!,ColIndex2 is ColIndex + 1.
index_increment_by_direction(left, _, 1, 0, 0):-
!.
index_increment_by_direction(left, RowIndex, ColIndex, RowIndex, ColIndex2):-
!,ColIndex2 is ColIndex - 1.
% Example game states for testing purposes
gamestate_example_1([
[[white,white,white,white,white,white,white,white],
[empty,empty,empty,empty,empty,empty,empty,empty],
[empty,empty,empty,empty,empty,empty,empty,empty],
[empty,empty,empty,empty,empty,empty,empty,empty],
[empty,empty,empty,empty,empty,empty,empty,empty],
[empty,empty,empty,empty,empty,empty,empty,empty],
[empty,empty,empty,empty,empty,empty,empty,empty],
[black,black,black,black,black,black,black,black]]
|white]).
gamestate_example_2([
[[empty,white,empty,empty,empty,empty,empty,empty],
[empty,empty,empty,black,empty,empty,empty,empty],
[empty,white,empty,empty,empty,empty,empty,empty],
[empty,empty,empty,empty,empty,empty,empty,empty],
[empty,empty,empty,empty,empty,empty,empty,empty],
[empty,empty,empty,empty,empty,empty,empty,empty],
[empty,empty,empty,empty,empty,empty,empty,empty],
[empty,empty,black,empty,empty,empty,empty,empty]]
|black]).
gamestate_example_3([
[[empty,empty,empty,empty,white,empty,empty,empty],
[empty,empty,black,empty,empty,empty,empty,empty],
[empty,white,empty,white,empty,empty,empty,empty],
[empty,empty,empty,empty,empty,empty,empty,empty],
[empty,empty,empty,empty,empty,empty,empty,empty],
[empty,empty,empty,empty,empty,empty,empty,empty],
[empty,empty,empty,empty,empty,empty,empty,empty],
[empty,empty,black,empty,empty,empty,empty,empty]]
|black]).
gamestate_example_4(
[
[empty,empty,black,empty,empty,empty],
[empty,white,empty,empty,empty,empty],
[empty,white,empty,empty,empty,empty],
[empty,white,empty,empty,empty,empty],
[empty,black,empty,empty,empty,empty]]).
gamestate_example_5([
[[empty,empty,empty,empty,empty,empty,empty,empty],
[empty,white,black,empty,empty,empty,empty,empty],
[empty,empty,empty,white,empty,empty,empty,empty],
[empty,empty,empty,empty,empty,empty,empty,empty],
[empty,empty,empty,empty,empty,empty,empty,empty],
[empty,empty,empty,empty,empty,empty,empty,empty],
[empty,empty,empty,empty,empty,empty,empty,empty],
[empty,empty,empty,empty,empty,empty,empty,empty]]
|white]).