Dead and Injured on IOS
Who remembers the game “dead-and-injured”? I don’t remember what the real name is.
I have been playing the game with my colleague on paper and I decided to experiment it on IOS just to put everything I have been learning and reading into good use.
What in this life is dead-and-injured?
It is played between two players. Both players have their secret numbers. The secret numbers are picked by following these rules:
- The numbers have an agreed number of digits, usually four.
- The digits of the number must be unique i.e no repetition
Therefore, 3456 is VALID. 3436 is INVALID because 3 is repeated.
Player A tries to decode the player B’s secret number by using the player’s responses to guess the next set of digits. The response is in the format described below:
Situation Response When digits of the guessed number exactly match the digits of the secret number i.e the same positions Dead When digits of the guessed number exist in the secret number but the positions don’t match Injured
For example, my secret number is 5678.
The following guesses will give the corresponding responses.
Guess Response 1234 0 dead, 0 injured 4537 2 injured, 0 dead 5479 0 dead, 2 injured 5678 All dead
As simple as the game appears, it needs logic and reasoning to be able to crack the secret number in few steps.
You can find the demo of the IOS app in the video below. Source code can be made available on request.
PS: I forgot to demo the part where the validation of the numbers was done.