1.6 KiB
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.
Learning
The solver keeps a set of possible sequences. With every response, to a guess, it removes all sequences from the set, which wouldn't generate the same response. Like this, the solver filters possible sequences, until there is only one left.
Guessing
We have a set of all possible sequences. Now we have to pick a guess, which divides them the most equally. The solver goes through all sequences, not just the remaining possible ones and divides the possible ones by their response. After that, it gives these guesses a weight, depending on how big is its biggest group at any response. Finally it picks the guess, which has the least weight - has the smallest biggest remaining sequences count at worst-case.
This is inspired by Donald Knuth and his algorithm to solve Mastermind.
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.