-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.pl
More file actions
61 lines (57 loc) · 1.66 KB
/
main.pl
File metadata and controls
61 lines (57 loc) · 1.66 KB
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
/* Module Imports */
?- [engine/engine].
?- [settings].
/**
* game_loop/2
* Defines the main game loop (check the output for results)
* @1: +Board - the inital board
* @2: +Plaer - the starting player (w or b)
*/
game_loop(Board, w) :- % Not finished, w's turn
not(is_finished(Board)),
admissible_plays(w, Board, _, _),
display(Board),
writeln('White is playing…'),
ai_w(w, Board, Row, Col),
flip_pawns(Board, Row, Col, w, NewBoard),
game_loop(NewBoard, b).
game_loop(Board, b) :- % Not finished, b's turn
not(is_finished(Board)),
admissible_plays(b, Board, _, _),
display(Board),
writeln('Black is playing…'),
ai_b(b, Board, Row, Col),
flip_pawns(Board, Row, Col, b, NewBoard),
game_loop(NewBoard, w).
game_loop(Board, CurrentPlayer) :- % Not finished, one player is stuck
not(is_finished(Board)),
not(admissible_plays(CurrentPlayer, Board, _, _)),
reverse_pawn(CurrentPlayer, NextPlayer),
game_loop(Board, NextPlayer).
game_loop(Board, _) :- % Game finished, score time !
is_finished(Board),
score(Board, w, WhiteScore),
score(Board, b, BlackScore),
display(Board),
writeln(''),
writeln('Scores:'),
writeln('-------'),
write('White: '),
write(WhiteScore),
writeln(''),
write('Black: '),
write(BlackScore).
?- set_prolog_stack(global, limit(1*10**9)). % 1GB max global stack size
?- set_prolog_stack(local, limit(1*10**9)). % 1GB max local stack size
% Start the loop !
?- game_loop([
[e, e, e, e, e, e, e, e],
[e, e, e, e, e, e, e, e],
[e, e, e, e, e, e, e, e],
[e, e, e, w, b, e, e, e],
[e, e, e, b, w, e, e, e],
[e, e, e, e, e, e, e, e],
[e, e, e, e, e, e, e, e],
[e, e, e, e, e, e, e, e]
], b).
?- halt.