-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.pl
158 lines (121 loc) · 4.79 KB
/
game.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
155
156
157
158
:- module(game, [cell/6, color_now/1, turn/1, last_move/1, player/2]).
:- use_module(change_turn).
:- use_module(bug_can_put).
:- use_module(bug_can_move).
:- use_module(bug_can_power).
:- use_module(play_can_do).
:- use_module(possible_colocation).
:- use_module(real_valid_moves).
:- use_module(power).
:- use_module(make_move).
:- use_module(win).
:- use_module(init_cells).
:- use_module(expantions).
:- use_module(ai).
:- use_module(players).
:- use_module(paint).
:- dynamic cell/6.
:- dynamic color_now/1.
:- dynamic turn/1.
:- dynamic last_move/1.
:- dynamic player/2.
init_game() :-
remove_all_cells(),
remove_all_states(),
Bugs = [queen, ant, grasshopper, beetle, spider],
Amounts = [1, 3, 3, 2, 2],
init_game_cells(Bugs, Amounts),
select_expantions(),
assert(color_now(white)),
assert(turn(1)),
assert(last_move(cell(quee, 0, 0, white, -1, false))),
assert(player(1, human)),
assert(player(2, human)),
select_players(),
enter_game().
enter_game() :-
game_finished(Result),
enter_game_2(Result).
enter_game() :-
color_now(Color),
turn(Turn),
player_turn(Turn, Player),
player(Player, PlayerType),
paint_board(),
write("Player turn: " + Player + " Player type: " + PlayerType + " Color: " + Color + " Turn: " + Turn + "\n"),
begin_play(PlayerType, Color, Turn),
change_turn(_),
advance_turn(),
write("----------------------------------------------------------\n"),!,
enter_game().
enter_game_2(tie) :-
write("TIE").
enter_game(Result) :-
write("Winner " + Result).
begin_play(human, Color, Turn) :-
select_play(Color, Turn).
begin_play(ai, Color, Turn) :-
best_play_ai(Color, Turn, 4, _, Play),
write(Play + "\n"),
make_play_ai(Color, Play).
select_play(Color, Turn) :-
play_can_do(Color, PlayCanDo),
select_play2(Color, Turn, PlayCanDo).
select_play2(_, _, []) :-
write("No play to do\n").
select_play2(Color, Turn, PlayCanDo) :-
PlayCanDo = [_|_],
write("Select play to do " + PlayCanDo + "\n"),
read(PlayToDo),
nth1(PlayToDo, PlayCanDo, Play),!,
write("Play selected " + Play + "\n"),
play(Play, Color, Turn).
play(put, Color, Turn) :-
bug_can_put(Color, Turn, BugCanPut),
write("Select bug to put: " + BugCanPut + "\n"),
read(BugToPut),
nth1(BugToPut, BugCanPut, Bug),!,
write("Bug selected: " + Bug + "\n"),
possible_colocation(Color, PossiblesColocations),
write("Select colocation: " + PossiblesColocations + "\n"),
read(ColocationSelected),
nth1(ColocationSelected, PossiblesColocations, [ColocationR, ColocationC]),!,
write("Colocation selected: " + [ColocationR, ColocationC] + "\n"),
select_cell_to_put(Color, Bug, [B, R, C, Color, Sp]),
make_move(cell(B, R, C, Color, Sp, false), [ColocationR, ColocationC], SP_greater),
retract(last_move(cell(_, _, _, _, _, _))),
assertz(last_move(cell(B, ColocationR, ColocationC, Color, SP_greater, true))).
play(move, Color, _) :-
bug_can_move(Color, BugCanMove),
write("Select bug to move: " + BugCanMove + "\n"),
read(BugToMove),
nth1(BugToMove, BugCanMove, [B, R, C, Color, Sp]),!,
write("Bug selected " + [B, R, C, Color, Sp] + "\n"),
real_valid_moves(cell(B, R, C, Color, Sp, true), RealValidMoves),
write("Select move to do " + RealValidMoves + "\n"),
read(MoveToDo),
nth1(MoveToDo, RealValidMoves, [MoveR, MoveC]),!,
write("Move selected: " + [MoveR, MoveC] + "\n"),
make_move(cell(B, R, C, Color, Sp, true), [MoveR, MoveC], SP_greater),
retract(last_move(cell(_, _, _, _, _, _))),
assertz(last_move(cell(B, MoveR, MoveC, Color, SP_greater, true))).
play(power, Color, _) :-
bug_can_power(Color, BugCanPower),
write("Select bug to use power: " + BugCanPower + "\n"),
read(BugToPower),
nth1(BugToPower, BugCanPower, [B, R, C, Color, Sp]),!,
write("Bug selected: " + [B, R, C, Color, Sp] + "\n"),
pillbug_power_can_apply(cell(B, R, C, Color, Sp, true), BugsPowerCanApply),
write("Select bug to apply power: " + BugsPowerCanApply + "\n"),
read(BugToApplyPower),
nth1(BugToApplyPower, BugsPowerCanApply, [BugR, BugC]),!,
write("Bug selected: " + [BugR, BugC] + "\n"),
not_neighbors(cell(B, R, C, Color, Sp, true), PossiblesColocations),
write("Select colocation: " + PossiblesColocations + "\n"),
read(ColocationSelected),
nth1(ColocationSelected, PossiblesColocations, [ColocationR, ColocationC]),!,
write("Colocation selected: " + [ColocationR, ColocationC] + "\n"),
cell(BugP, BugR, BugC, BugColor, BugSp, true),
make_move(cell(BugP, BugR, BugC, BugColor, BugSp, true), [ColocationR, ColocationC], SP_greater),
retract(last_move(cell(_, _, _, _, _, _))),
assertz(last_move(cell(BugP, ColocationR, ColocationC, BugColor, SP_greater, true))).