-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClueMerged.pl
343 lines (288 loc) · 8.62 KB
/
ClueMerged.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
:- dynamic active_player/1.
:- dynamic current_player/1.
:- dynamic controlling_player/1.
:- dynamic room/1.
:- dynamic weapon/1.
:- dynamic last_play_id/1.
:- dynamic card_in_possession/2.
:- dynamic recorded_suggestion/3.
:- dynamic recorded_to_player_response/3.
:- dynamic recorded_to_opponent_response/2.
/*
Game Setup
*/
init_clue(Type, Players, ControllingPlayer) :-
% Wipe everything first
wipe,
init_weapons(Type),
init_rooms(Type),
init_players(Players),
init_first_player,
assert(controlling_player(ControllingPlayer)),
assert(last_play_id(0)).
init_players([]).
init_players([Name|Names]) :-
assert(active_player(Name)),
init_players(Names).
% If mrsPeacock is playing, then she's first
init_first_player :-
active_player(mrsPeacock),
assert(current_player(mrsPeacock)).
% Else, find whoever is to the left
init_first_player :-
assert(current_player(mrsPeacock)),
next_turn(TrueFirst),
set_current_player(TrueFirst).
% wipe game databases
wipe :-
retractall(weapon(_)),
retractall(room(_)),
retractall(active_player(_)),
retractall(current_player(_)),
retractall(controlling_player(_)),
retractall(recorded_suggestion(_,_,_)),
retractall(recorded_to_player_response(_,_,_)),
retractall(recorded_to_opponent_response(_,_)),
retractall(card_in_possession(_,_)).
/*
Deduction
*/
get_eliminated_cards(All) :-
findall(X, card_in_possession(_,X), All).
/*
Game Cycles
*/
set_current_player(Player) :-
retractall(current_player(_)),
assert(current_player(Player)).
next_turn(NextPlayer) :-
current_player(Current),
relatively_left(Current, NextPlayer),
% That's active
active_player(NextPlayer),
% No more
!.
/*
Main Gameplay
*/
new_suggestion(Id, Player, suggestion(Location, Suspect, Weapon)) :-
% Get a new ID for the suggestion
new_play_id(Id),
% Record it
assert(recorded_suggestion(Id, Player, suggestion(Location, Suspect, Weapon))).
% This happens when someone responds to a move the controlling player makes
player_suggestion_response(SuggestionId, Opponent, DebunkingCard) :-
% We know that the opponent posesses this card
assert(card_in_possession(Opponent, DebunkingCard)),
% Record this response
assert(recorded_to_player_response(SuggestionId, Opponent, DebunkingCard)).
% This happens when someone responds to a move an oppponent makes
opponent_suggestion_response(SuggestionId, Debunker) :-
% TODO: Mark all cards this his suggestion as possibly in the hand of someone
assert(recorded_to_opponent_response(SuggestionId, Debunker)).
new_play_id(X) :-
last_play_id(LastId),
X is LastId + 1,
retractall(last_play_id(_)),
assert(last_play_id(X)).
/*
User Interface
*/
main :-
write('Clue Assistant 1.0\n'),
ask_school(School),
ask_players(Players),
ask_controller(ControllingPlayer),
init_clue(School, Players, ControllingPlayer),
write('Game Initialized.\n\n'),
main_menu(0).
ask_school(School) :-
write('School of Thought [oldSchool, newSchool]: '),
read(School).
ask_players(Players) :-
write('Type the participating players in the following format\n'),
write(' [player0, player1, etc..]: '),
read(Players).
ask_controller(ControllingPlayer) :-
write('Who are you playing as?: '),
read(ControllingPlayer).
% Main Menu
main_menu(0) :-
print_main_menu,
read(Option),
main_menu(Option).
% Record a new suggestion
main_menu(1) :-
new_move(0),
main_menu(0).
% Show suggestion history
main_menu(2) :-
fact_history_menu,
main_menu(0).
% Show card facts
main_menu(3) :-
card_fact_menu,
main_menu(0).
% Repeat the menu
main_menu(_) :- main_menu(0).
print_main_menu :-
write('[1] Record a new suggestion\n'),
write('[2] Show suggestion history\n'),
write('[3] Show card facts\n').
/*
UI: Recording moves
*/
new_move(0) :-
print_new_move,
read(Option),
suggestion_menu(Option).
print_new_move :-
write('[1] Record a suggestion you made\n'),
write('[2] Record a suggestion an opponent made\n').
% A player suggestion
suggestion_menu(1) :-
controlling_player(ControllingPlayer),
generic_suggestion_menu(SuggestionId, ControllingPlayer),
% Check for a response
write('Did anyone show you a card? [yes, no]: '),
read(Response),
player_suggestion_response_menu(Response, SuggestionId).
% An opponent suggestion
suggestion_menu(2) :-
write('Who made this suggestion?: '),
read(Opponent),
generic_suggestion_menu(SuggestionId, Opponent),
write('Did anyone respond to this suggestion? [yes, no]: '),
read(Response),
opponent_suggestion_response_menu(Response, SuggestionId).
generic_suggestion_menu(SuggestionId, Player) :-
write('(Suggestion) Who: '),
read(Character),
write('(Suggestion) Where: '),
read(Where),
write('(Suggestion) With What: '),
read(Weapon),
% Record this suggestion
new_suggestion(SuggestionId, Player, suggestion(Where, Character, Weapon)).
% When someone responds to a suggestion a player made
player_suggestion_response_menu(no, _).
player_suggestion_response_menu(yes, SuggestionId) :-
write('Who responded?: '),
read(Debunker),
write('Which card was shown?: '),
read(Card),
player_suggestion_response(SuggestionId, Debunker, Card).
% When someone responds to a suggestion an opponent made
opponent_suggestion_response_menu(no, _).
opponent_suggestion_response_menu(yes, SuggestionId) :-
write('Who responded?: '),
read(Debunker),
opponent_suggestion_response(SuggestionId, Debunker).
/*
UI: Move history
*/
fact_history_menu :-
% For each suggestion,
findall(Id,recorded_suggestion(Id,_,_),L),
print_facts(L).
print_facts([]).
print_facts([SuggestionId|Ids]) :-
print_suggestion(SuggestionId),
print_suggestion_response(SuggestionId),
write('\n'),
print_facts(Ids).
print_suggestion(SuggestionId) :-
recorded_suggestion(SuggestionId, Player, suggestion(Location, Suspect, Weapon)),
write(Player),
write(' suggested ('),
write(Suspect),
write(','),
write(Weapon),
write(','),
write(Location),
write('). ').
print_suggestion_response(SuggestionId) :-
% Is this a player suggestion?
recorded_to_player_response(SuggestionId, Opponent, DebunkingCard),
% It can't be anything else
!,
write(Opponent),
write(' showed '),
write(DebunkingCard).
print_suggestion_response(SuggestionId) :-
% Is this an opponent suggestion?
recorded_to_opponent_response(SuggestionId, Debunker),
!,
write(Debunker),
write(' showed a card.').
print_suggestion_response(_) :-
% Previous goals could not be proven
write('No one responded.').
/*
UI: Cards
*/
card_fact_menu :-
findall(X, card_in_possession(_, X), L),
print_card_facts(L).
print_card_facts([]).
print_card_facts([Card|Cards]) :-
card_in_possession(Owner, Card),
write(Card),
write(' is owned by '),
write(Owner),
write('\n'),
print_card_facts(Cards).
/*
Game Elements and Rules
*/
character(missScarlet).
character(colonelMustard).
character(mrsWhite).
character(mrGreen).
character(mrsPeacock).
character(professorPlum).
% Player Spatial Ordering
left_of(missScarlet, colonelMustard).
left_of(colonelMustard, mrsWhite).
left_of(mrsWhite, mrGreen).
left_of(mrGreen, mrsPeacock).
left_of(mrsPeacock, professorPlum).
left_of(professorPlum, missScarlet).
relatively_left(LeftPlayer, RightPlayer) :- left_of(LeftPlayer, RightPlayer).
relatively_left(LeftPlayer, RightPlayer) :-
left_of(LeftPlayer, DirectlyLeft),
relatively_left(DirectlyLeft, RightPlayer).
init_weapons(oldSchool) :-
assert(weapon(knife)),
assert(weapon(candlestick)),
assert(weapon(revolver)),
assert(weapon(rope)),
assert(weapon(pipe)),
assert(weapon(wrench)).
init_weapons(newSchool) :-
assert(weapon(knife)),
assert(weapon(candlestick)),
assert(weapon(pistol)),
assert(weapon(rope)),
assert(weapon(bat)),
assert(weapon(ax)).
init_rooms(oldSchool) :-
assert(room(kitchen)),
assert(room(ballroom)),
assert(room(conservatory)),
assert(room(billiard)),
assert(room(library)),
assert(room(study)),
assert(room(hall)),
assert(room(lounge)),
assert(room(dining_room)).
init_rooms(newSchool) :-
assert(room(kitchen)),
assert(room(patio)),
assert(room(spa)),
assert(room(theatre)),
assert(room(living)),
assert(room(observatory)),
assert(room(hall)),
assert(room(guest)),
assert(room(dining)).