|
| 1 | +# Instructions |
| 2 | + |
| 3 | +In this exercise, you'll be writing some logic for a video game a friend is developing. |
| 4 | +The game's main character is Annalyn, a brave girl with a fierce and loyal pet dog. |
| 5 | +Unfortunately, disaster strikes, as her best friend is kidnapped while searching for berries in the forest. |
| 6 | +Annalyn will try to find and free her friend, optionally taking her dog with her on this quest. |
| 7 | + |
| 8 | +Annalyn eventually finds the camp in which her friend is imprisoned and it turns out there are two kidnappers: a mighty knight and a cunning archer. |
| 9 | + |
| 10 | +The player is presented with some options for what to do next. |
| 11 | +For each of the four possible options you need to write a word that tells the game whether it should show that option or not. |
| 12 | + |
| 13 | +## 1. Check if the 'Fast Attack' option should be shown |
| 14 | + |
| 15 | +If the knight is sleeping, then Annalyn will be able to make a quick attack into the camp before he can wake up properly and get his armour on. |
| 16 | + |
| 17 | +Implement a word named `can-do-fast-attack` that takes a boolean value indicating whether the knight is awake. |
| 18 | +It returns `t` if the 'Fast Attack' action is available, otherwise `f`: |
| 19 | + |
| 20 | +```factor |
| 21 | +t can-do-fast-attack . |
| 22 | +! => f |
| 23 | +``` |
| 24 | + |
| 25 | +## 2. Check if the 'Spy' option should be shown |
| 26 | + |
| 27 | +The group can be spied upon if at least one of them is awake. Otherwise, spying is a waste of time. |
| 28 | + |
| 29 | +Implement a word named `can-spy` that takes three boolean values, indicating whether the knight, archer and prisoner, respectively, are awake. |
| 30 | +It returns `t` if the 'Spy' action is available, otherwise `f`: |
| 31 | + |
| 32 | +```factor |
| 33 | +f t f can-spy . |
| 34 | +! => t |
| 35 | +``` |
| 36 | + |
| 37 | +## 3. Check if the 'Signal Prisoner' option should be shown |
| 38 | + |
| 39 | +The prisoner can be signalled using bird sounds if she is awake and the archer is sleeping. |
| 40 | +If the archer is awake then she can't be safely signaled because the archer is also trained in bird signalling. |
| 41 | + |
| 42 | +Implement a word named `can-signal-prisoner` that takes two boolean values, indicating whether the archer and prisoner, respectively, are awake. |
| 43 | +It returns `t` if the 'Signal Prisoner' action is available, otherwise `f`: |
| 44 | + |
| 45 | +```factor |
| 46 | +f t can-signal-prisoner . |
| 47 | +! => t |
| 48 | +``` |
| 49 | + |
| 50 | +## 4. Check if the 'Free Prisoner' option should be shown |
| 51 | + |
| 52 | +Annalyn can try sneaking into the camp to free her friend. This is a risky thing to do and can only succeed in one of two ways: |
| 53 | + |
| 54 | +- If Annalyn has her pet dog with her, she can rescue the prisoner if the archer is asleep. |
| 55 | + The knight is scared of the dog and the archer will not have time to get ready before Annalyn and her friend can escape. |
| 56 | + |
| 57 | +- If Annalyn does not have her dog, then she and the prisoner must be very sneaky! |
| 58 | + Annalyn can free the prisoner if the prisoner is awake and the knight and archer are both sleeping. |
| 59 | + If the prisoner is sleeping, she can't be rescued: she would be startled by Annalyn's sudden appearance and wake up the knight and archer. |
| 60 | + |
| 61 | +Implement a word named `can-free-prisoner` that takes four boolean values. |
| 62 | +The first three parameters indicate whether the knight, archer and prisoner, respectively, are awake. |
| 63 | +The last parameter indicates whether Annalyn's pet dog is present. |
| 64 | +It returns `t` if the 'Free Prisoner' action is available, otherwise `f`: |
| 65 | + |
| 66 | +```factor |
| 67 | +f t f f can-free-prisoner . |
| 68 | +! => f |
| 69 | +``` |
0 commit comments