1
0
dust/examples/clue_solver.ds
2023-11-10 16:24:19 -05:00

58 lines
1.2 KiB
Plaintext

all_cards = {
rooms = ['Library' 'Kitchen' 'Conservatory']
suspects = ['White' 'Green' 'Scarlett']
weapons = ['Rope' 'Lead_Pipe' 'Knife']
}
is_ready_to_solve = |cards| => {
((length cards:suspects) == 1)
&& ((length cards:rooms) == 1)
&& ((length cards:weapons) == 1)
}
take_turn = |opponent_card, current_room, cards| => {
(remove_card opponent_card cards)
(make_guess current_room cards)
cards
}
remove_card = |opponent_card cards| => {
remove card from cards:rooms {
card == opponent_card
}
remove card from cards:weapons {
card == opponent_card
}
remove card from cards:suspects {
card == opponent_card
}
}
make_guess = |current_room cards| => {
if (is_ready_to_solve cards) {
(output 'It was '
+ cards:suspects:0
+ ' in the '
+ cards:rooms:0
+ ' with the '
+ cards:weapons:0
+ '!')
} else {
(output 'I accuse '
+ (random cards:suspects)
+ ' in the '
+ current_room
+ ' with the '
+ (random cards:weapons)
+ '!')
}
}
(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))))))