-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbase.pl
92 lines (75 loc) · 2.48 KB
/
base.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
%% Author : Reynaud Nicolas (Kaldoran)
debug('no').
% Write '+X' if debug mod is on
% ----------------------------- %
writeDebug(X) :-
debug('yes'),
write(X), !.
% Else write nothing
% ------------------ %
writeDebug(_).
% Check if '+X' is a Pawn
% I.E if it's a regular Pawn or a Queen
% ------------------------------------- %
isPawn(X) :-
isRegularPawn(X); isQueen(X).
isX(' x ').
isX(' X ').
isO(' o ').
isO(' O ').
isBlankSpace(' ').
isRegularPawn(' x ').
isRegularPawn(' o ').
isQueen(' O ').
isQueen(' X ').
% Check if Pawn is of color Color
% ------------------------------- %
isSameColor(Pawn,Color):-isX(Pawn),isX(Color),!.
isSameColor(Pawn,Color):-isO(Pawn),isO(Color).
% Invert the current player
% ------------------------- %
invert_player(' x ', ' o ').
invert_player(' o ', ' x ').
% Transform a Pawn into Queen Pawn
% --------------------------------- %
queen(' o ', ' O ').
queen(' x ', ' X ').
% Convert '+[Row, Column]' into '-Square'
% -------------------------------------- %
convert([Row, Column], Square) :-
char_code(Row, Code),
char_code('a', CodeA),
RowMove is Code - CodeA,
Square is RowMove * 10 + Column.
% Convert '+Square' into '-[Row, Column]'
% -------------------------------------- %
revertConvert([0, Column], Square) :-
Square =< 10,
Column is mod(Square, 10), !.
% Given a '+Square'
% Output the '[-Row, -Column]' associate to the Square
% ---------------------------------------------------- %
revertConvert([Row, Column], Square) :-
char_code('a', CodeA),
ColumnVal is mod(Square, 10),
(
ColumnVal \= 0,
Column = ColumnVal,
RowCode is Square // 10 + CodeA, !;
Column is ColumnVal + 10,
RowCode is Square // 10 + CodeA
),
char_code(Row, RowCode).
% the default grid
% ---------------- %
initialize_game([ ' w ',' x ',' w ',' x ',' w ',' x ',' w ',' x ',' w ',' x ',
' x ',' w ',' x ',' w ',' x ',' w ',' x ',' w ',' x ',' w ',
' w ',' x ',' w ',' x ',' w ',' x ',' w ',' x ',' w ',' x ',
' x ',' w ',' x ',' w ',' x ',' w ',' x ',' w ',' x ',' w ',
' w ',' ',' w ',' ',' w ',' ',' w ',' ',' w ',' ',
' ',' w ',' ',' w ',' ',' w ',' ',' w ',' ',' w ',
' w ',' o ',' w ',' o ',' w ',' o ',' w ',' o ',' w ',' o ',
' ',' w ',' o ',' w ',' o ',' w ',' o ',' w ',' o ',' w ',
' w ',' o ',' w ',' o ',' w ',' o ',' w ',' o ',' w ',' o ',
' o ',' w ',' o ',' w ',' o ',' w ',' o ',' w ',' o ',' w '
] ).