1
0
dust/examples/clue_solver.ds

64 lines
1.2 KiB
Plaintext
Raw Normal View History

2023-11-04 10:02:27 +00:00
all_rooms = ['Library' 'Kitchen']
all_suspects = ['White' 'Green']
all_weapons = ['Rope' 'Lead_Pipe']
2023-10-06 12:17:37 +00:00
2023-11-04 10:02:27 +00:00
is_ready_to_solve = |state| => {
((length state:suspects) == 1)
&& ((length state:rooms) == 1)
&& ((length state:weapons) == 1)
}
take_turn = |opponent_card state| => {
state = (remove_card state opponent_card)
(make_guess state)
state
2023-11-03 22:04:45 +00:00
}
2023-10-19 01:50:45 +00:00
2023-11-04 10:02:27 +00:00
remove_card = |state opponent_card| => {
rooms = filter card in state:rooms {
card != opponent_card
}
suspects = filter card in state:suspects {
card != opponent_card
}
weapons = filter card in state:weapons {
card != opponent_card
2023-11-03 22:04:45 +00:00
}
2023-10-19 01:50:45 +00:00
2023-11-04 10:02:27 +00:00
{
current_room = state:current_room
rooms = rooms
suspects = suspects
weapons = weapons
}
2023-11-03 22:04:45 +00:00
}
2023-10-16 20:48:02 +00:00
2023-11-04 10:02:27 +00:00
make_guess = |state| => {
if (is_ready_to_solve state) {
2023-10-07 01:59:01 +00:00
(output 'It was '
2023-11-04 10:02:27 +00:00
+ state:suspects:0
+ ' in the '
+ state:rooms:0
+ ' with the '
+ state: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-04 10:02:27 +00:00
+ (random state:suspects)
2023-10-24 00:45:47 +00:00
+ ' in the '
2023-11-04 10:02:27 +00:00
# + state:current_room
2023-10-24 00:45:47 +00:00
+ ' with the '
2023-11-04 10:02:27 +00:00
+ (random state:weapons)
2023-10-24 00:45:47 +00:00
+ '!')
2023-11-03 22:04:45 +00:00
}
}
2023-10-31 05:09:29 +00:00
2023-11-04 10:02:27 +00:00
init_state = {
current_room = 'Library'
rooms = all_rooms
suspects = all_suspects
weapons = all_weapons
}
(take_turn 'Green' (take_turn 'Kitchen' (take_turn 'Rope' init_state)))