logik/DOC.md

44 lines
2.3 KiB
Markdown

# logik documentation
## Game
At first, the game asks the player for game specs.
That can be done either by command-line argumenst, or if not specified - by stdin prompt.
Then it has two modes:
### Human mode
In this mode, the player has to deduce the secret sequence, which is done by guessing sequences like it.
Inside of the game, all that is happening is a loop consisting of taking user input, generating a response and outputting it.
### Bot mode
Works the same way, but instead of the player typing guessed sequences, there is a program guessing.
The real fun happens inside of the solver, where it makes the guesses and learns from responses.
The solver keeps track of past guesses with their responses in history.
It also remembers a table with which colors can be on which positions - this starts at all colors possible on all positions.
#### Learning
With each new guess-response duo, the solver adds it to the history.
Then it goes through all the historical, extracting all possible information from them.
This is repeated as long as some new information is learnt.
While extracting info from history, it is important to strip guesses from the info already gained,
so they are simplified and information is easier to recognize. That is done by replacing the known colors
in the guess with an unreal color, like *-1* and decreasing the response accordingly.
Extracting information from a guess-response duo is a complicated process,
it has many possibilities, depending on the response.
[A/B] meaning A colors are somewhere else in the sequence, B colors are correct.
- [0/0]: None of the colors from the guess are in the sequence. Now we can erase these colors from the table,
as they are nowhere in the sequence. Of course we must not erase them from the positions we already know they are in,
but were cleared to simplify the guess.
- [X/0]: None of these colors are on the right spot.
- [0/X]: If these colors cannot be on their spot, they can't be in the sequence.
Also if only the colors that can be in those spots are left, they are correct.
- [X/X]: If only the colors that can be in those spots are left, they are correct too.
#### Guessing
### Response generating
When a guess is entered, all that is done to make a response is comparing that guess to the secret sequence.
First it counts right colors, then the out-of-place right colors.