Post Reply 
(11C) Code guessing game
04-27-2018, 12:52 PM (This post was last modified: 04-30-2018 09:13 AM by Dieter.)
Post: #7
RE: (11C) Code guessing game
(04-26-2018 10:10 PM)Rogier Wrote:  I'll give your program a try, Dieter. Looks fine too. The scoring is more in line with "official" Mastermind rules and it is shorter.

I have tried to understand how your program works, especially the scoring routine, but I admit I haven't understood all details. For comparison here is how my version works:

LBL A: code generation. This generates four individual random digits. A counter in R0 is incremented on each loop and the loop at LBL 2 checks if the digit is equal to one of the previously generated ones. In this case a new digit is generated. Else the number is stored in the next higher data register. This way (assuming the default settings) R1...R4 are filled one after another with four different numbers between 1 and 6. The code length (here 4) is kept in R,0 so that it can be recalled from there later.

LBL B: score evaluation. The guess is stored in R7, the guess counter in R9 incremented and the loop counter in R0 is initialized with 4 (guess digits to compare). The main loop at LBL 3 splits off a single guess digit (from right to left) and checks if it matches one of the code digits. This is done in the loop at LBL 4. This way first the 4th guess digit is compared with the code digits #4, #3, #2, #1, then the 3rd guess digit is compared with the code digits #4, #3, #2, #1, ... etc.

If a match is detected the loop is exited (GTO 6) and the score is added: if the loop counter in R0 - which indicates the current digit's position in the guess - matches the position in the code - which is held in R I - the score in R8 is increased by 1. If the positions are not equal only 0,1 is added. This can be done very elegantly with a simple test that skips over the decimal point if the positions match.

Finally (LBL 5) the loop counter is decremented until it becomes zero. 15C owners may also use a simple DSE 0 here. After all digits have been compared the program checks if the score equals the code length, which means that all guess digits were correct. If not it jumps back to LBL 0 to display the score and stop, else it moves the number of guesses into the tens exponent so that the final display in scientific notation shows the score along with the number of required guesses, e.g. "4,0          12".

I hope this was clear enough. ;-)
If not, just ask.

Dieter

Edited to reflect the program's updated register use.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
(11C) Code guessing game - Rogier - 04-25-2018, 06:18 PM
RE: (11C) Code guessing game - Dieter - 04-26-2018, 06:57 PM
RE: (11C) Code guessing game - Rogier - 04-26-2018, 10:10 PM
RE: (11C) Code guessing game - Dieter - 04-27-2018, 06:54 AM
RE: (11C) Code guessing game - Dieter - 04-27-2018 12:52 PM
RE: (11C) Code guessing game - Rogier - 04-28-2018, 12:24 PM
RE: (11C) Code guessing game - Dieter - 04-29-2018, 09:00 PM
RE: (11C) Code guessing game - pier4r - 04-28-2018, 07:23 PM
RE: (11C) Code guessing game - Rogier - 04-29-2018, 09:58 PM
RE: (11C) Code guessing game - Dieter - 04-30-2018, 08:11 AM
RE: (11C) Code guessing game - Rogier - 04-30-2018, 07:29 PM
RE: (11C) Code guessing game - SlideRule - 07-23-2018, 03:22 PM
RE: (11C) Code guessing game - Rogier - 05-02-2018, 06:49 PM



User(s) browsing this thread: 1 Guest(s)