dust/examples/clue_solver.ds

55 lines
1.2 KiB
Plaintext
Raw Normal View History

2023-11-28 16:01:38 +00:00
all_cards = {
2023-11-10 21:24:19 +00:00
rooms = ['Library' 'Kitchen' 'Conservatory']
suspects = ['White' 'Green' 'Scarlett']
weapons = ['Rope' 'Lead_Pipe' 'Knife']
}
2023-10-06 12:17:37 +00:00
is_ready_to_solve = (fn cards <map>) <bool> {
2023-12-02 03:16:50 +00:00
((length cards:suspects) == 1)
&& ((length cards:rooms) == 1)
&& ((length cards:weapons) == 1)
2023-11-04 10:02:27 +00:00
}
take_turn = (fn cards <map>, opponent_card <str>, current_room <str>) <map> {
cards = (remove_card cards opponent_card)
cards = (make_guess cards current_room)
2023-11-10 21:24:19 +00:00
cards
2023-11-27 20:02:08 +00:00
}
2023-10-19 01:50:45 +00:00
remove_card = (fn cards <map>, opponent_card <str>) <map> {
2023-11-27 20:02:08 +00:00
cards:rooms -= opponent_card
cards:suspects -= opponent_card
cards:weapons -= opponent_card
2023-12-05 21:42:11 +00:00
cards
2023-11-03 22:04:45 +00:00
}
2023-10-16 20:48:02 +00:00
make_guess = (fn cards <map>, current_room <str>) <map> {
2023-11-10 21:24:19 +00:00
if (is_ready_to_solve cards) {
2023-10-07 01:59:01 +00:00
(output 'It was '
2023-11-10 21:24:19 +00:00
+ cards:suspects:0
2023-11-04 10:02:27 +00:00
+ ' in the '
2023-11-10 21:24:19 +00:00
+ cards:rooms:0
2023-11-04 10:02:27 +00:00
+ ' with the '
2023-11-10 21:24:19 +00:00
+ cards:weapons:0
2023-10-25 18:41:23 +00:00
+ '!')
2023-11-03 22:04:45 +00:00
} else {
2023-10-07 01:59:01 +00:00
(output 'I accuse '
2023-11-10 21:24:19 +00:00
+ (random cards:suspects)
2023-10-24 00:45:47 +00:00
+ ' in the '
2023-11-10 21:24:19 +00:00
+ current_room
2023-10-24 00:45:47 +00:00
+ ' with the '
2023-11-10 21:24:19 +00:00
+ (random cards:weapons)
2023-11-28 16:01:38 +00:00
+ '.')
2023-11-03 22:04:45 +00:00
}
2023-12-05 21:42:11 +00:00
cards
2023-11-03 22:04:45 +00:00
}
2023-10-31 05:09:29 +00:00
2023-12-05 21:42:11 +00:00
all_cards
-> (take_turn 'Rope' 'Kitchen')
-> (take_turn 'Library' 'Kitchen')
-> (take_turn 'Conservatory' 'Kitchen')
-> (take_turn 'White' 'Kitchen')
-> (take_turn 'Green' 'Kitchen')
-> (take_turn 'Knife' 'Kitchen')
2023-11-04 10:02:27 +00:00