1
0
dust/examples/clue_solver.ds

58 lines
1.2 KiB
Plaintext
Raw Normal View History

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