(41CX) Master Logic - Mastermind - Code-breaking Game with letters combination - Nihotte(lma) - 08-09-2024 03:21 PM
(41CX) Master Logic - Mastermind - Code-breaking Game with letters combination
Mastermind is a wellknown game for two players : a codemaker chooses a combination of four or five pegs and the other player will try to break this code.
This publication is based on a program for the 41CX : it was written in 07/2004.
At this time, I prefered to use the names of the colors instead of the position of a color in my set.
So, I prepared this program to use letters instead of numbers to represent colors.
Code:
** LBL TSMM Super Master Mind – Version 07/2004 for 41CX
CLRG
CF 29
FIX 0
XEQ d
STO 24 Keeps the number of pegs
1
+ The programs needs 'd' registers to store the code to find downto STO 01
ΣREG IND X Provides the program work area assigned to the successive guesses control
TIME
FRC
STO 00 RAN#
RCL 24
STO 20
* LBL 06 Generates the code to break
XEQ c
RCL 00
10↑X
PI
+
FRC
STO 00
ALENG
*
AROT
ATOX
STO IND 20
DSE 20
GTO 06
* LBL 01
AON
XEQ c
TͰˍ?
CLST
STOP Prompts and waits for a guess
AOFF
ALENG
RCL 24
X≠Y? Simple control of the size of of the guess
GTO 01
STO 20
CLΣ Easy reset of the work area (1 if a peg of the code is assigned, 0 otherwise)
CLX
STO 21 Result of the white scoring
STO 22 Result of the black scoring
ASTO 00
1
ST+ 23 Number of attempts already made by the user
* LBL 02 Calculates the number of well-placed pegs found
22
XEQ 08 Verifies each of the 5 pegs of the guess with the same position in the code to break
DSE 20
GTO 02
RCL 22
RCL 24
X=Y? The guess obtains full well-placed pegs ?
GTO 03
STO 20
* LBL 04
CLA
ARCL 25 Restores the portion of the guess always without affectation 'black' or 'white'
ALENG
X=0? All the guess has been verified ?
GTO 07
STO 26 Size of the leaving portion of the guess not already controlled
* LBL 05 Calculates the number of good colors found
21
XEQ 08 Verifies the current pegs of the guess within the always free pegs of the code to break
DSE 26
GTO 05
* LBL 07
DSE 20
GTO 04
CLA Displays the score obtained by the guess
ARCL 00
TͰˍˍ
ARCL 22
TͰBˍ
ARCL 21
TͰW
PROMPT
RCL 23
XEQ e
X>Y?
GTO 01
XEQ a Game is over : you failed to break the code
TͰ==>ˍ
ARCL 24
TͰB
TONE 0
GTO 09
* LBL 03 Game is over : successful result
XEQ a
TͰˍINˍ
ARCL 23
TͰa
BEEP
* LBL 09 Exit from the program
AVIEW
SF 29
FIX 9
RTN
* LBL 08 Dynamic subroutine of checking for a peg (guess) to a peg (code)
XEQ b
FS?C 06 Has been the peg successful assigned ?
XTOA No : we keep the peg for a next chance in the same turn
ASTO 25 Keeps the portion of the guess that remains to be verified
RTN
* LBL b
SF 06 Flag to know if the current peg of the guess is to be kept
RCL IND 20 Code to break is stored from STO 05 downto STO 01 (in the case of 5 pegs to store)
ATOX
X≠Y? Is the current peg of the guess suitable with the current peg of the code ?
RTN No : back
RCL Z
RCL 20
RCL 24
+
RCL IND X
X≠0? Is the current peg of the code already used ?
RCL T Yes : assumes X register is not null
X≠0? The current peg of the code is really free ?
RTN No : back
CF 06 Yes : no needs to keep the current peg of the guess because it has been assigned
1
STO IND Z The current peg of the code is no more free
ST+ IND T STO 22 (black) or STO 21 (white) is increased
RTN
* LBL a Insert the full code to break in the display (alpha register)
CLA
RCL 24
* LBL 10
RCL IND X
XTOA
R↓
DSE X
GTO 10
TͰˍ
RTN
* LBL c List of usable colors
TBJGMNORV
RTN
* LBL d Number of pegs
5
RTN
* LBL e Number of guesses allowed
12
END
Requires SIZE 027
Modifies ΣREG statement
148 lines – 282 bytes
Just enter XEQ 'ALPHA' SMM to start the program
You receive BJGMNORV ? at display when you can choose your guess and R/S
The 41CX answers the number of pegs you have found (B) and the number of pegs with the good color (W) but not well-placed
The number of attempts is limited to 12 (in LBL e)
The number of pegs in a combination is declared on LBL d (with 5)
The list of available colors is known by LBL c (BJGMNORV : 8 colors)
Keep you safe !
Laurent
#modified 08/09/2024 - 23:00 (typos...)
RE: (41CX) Master Logic - Mastermind - Code-breaking Game with letters combination - Nihotte(lma) - 08-13-2024 12:01 AM
Little reflection by myself about this program.
It dates back to 2004.
Of course, this program could be improve.
From several axes, I think.
In fact, it makes the job in good conditions. But some details make it is not longer exactly in line with my ideal finish, today.
If you see at the start of the programm, you find a "natural" instruction CLRG : it makes clean the environment before using it.
This way was usual in a program to run on the HP11C; or the HP34C, probably. These calculators had a restrictive memory space and it was
really more easy to free this work space with a single instruction.
Now, I rarely use an instruction with such radical effects. I'm more carreful when using a program that must coexist with several others.
This is all the more important as the memory space is shared and certain registers may contain constants which must be preserved.
Well, in the context of this program, it's actually quite simple: just replace the CLRG instruction with two others:
CLX followed by STO 23. Because, this is indeed the only interest of the CLRG here.
The random number generator used to generate the code to be found is not exceptional.
I now commonly use a dedicated number generator by calling a specialized routine (XEQ RAN#, for example) and I keep a root in a dedicated register (STO 00, often).
In this program, register 00 is assigned to two uses. I would try to separate them.
Another reality is the strange distribution of memory usage by the program. The characters chosen to form the code are stored in memories 01 to 05 (for a 5-letter code).
In this case, the following 5 memories are necessary to confirm whether a letter has been matched to the last combination proposed by the player who must solve the code.
Or registers 06 to 10. But then, that gives a lot of unused registers from 11 to 19.
I think that today, I would avoid having such a large amplitude of registers used.
The advantage would then be to reduce the minimum SIZE required for using the application (here SIZE 027).
Thus, starting on the basis of a code of maximum size of 6 letters (size imposed by the use of CLΣ which concerns 6 registers only),
this would give a reservation of registers from 01 to 06, then 07 to 13 for storing the code and the workspace for checking the proposed combinations
and requisitioning registers 14 to 20 for the counters (loops and operation).
Now, Concerning, precisely, the use of ΣREG: it can be avoided but this requires the use of a CLRGX instruction
which is more demanding in execution time and in program space.
On yet another aspect, it is possible to be even more economical with storage registers by using an assignment table on a single memory register.
It's then sufficient to position a number 1 by the power of 10 in adequation with the character number of the code which has just been assigned (such as black or white).
So, if all five characters of the code are affected we will find a check number at 111110, for example.
It will be more economical, but also more demanding in program space.
You have certainly understood that each character of the proposition is studied through each character of the code to be guessed.
A first time in exact correspondence (to know if we are in the presence of a character with BLACK potential), then possibly,
a second time with respect to each character of the code which has not yet been assigned (potential presence of a WHITE character
among the characters not already declared BLACK in the proposition).
Precisely, the program can be criticized for not checking until late whether the character of the code was indeed free.
In fact, it is only after observing the exact correspondence that the program ensures whether the reference character of the code has not already been assigned.
If we want to avoid this, from the start of the subroutine (LBL 08-LBL b), we must check the availability of the code character.
Be careful in this case, because the subroutine receive the context of the control, directly as a parameter in the stack.
That's why, you can also read a double X≠0? in the LBL b subroutine : the role of this instruction is also to perpetuate the presence of the parameters in the stack!
Otherwise, an additional register would need to be assigned to the Indirect Results Management (IND) role.
The strong point of this program is to allow the use of characters (letters or other special characters, for that matter) in the creation of codes to break.
The all-rotation technique implemented (XTOA followed by the possible ATOX) to preserve a character in the event of a association failure
allowed me to never again resort to the ALPHA register for the code to be discovered at the end of its creation.
But this led me to distribute the various characters of this code over registers 01 to 05, for example.
However, the use of an ASTO 25 to recover the residual of the user's combination at the end of a control cycle limits the size of the codes to 6 characters.
Nothing prevents us from directly managing the characters to be matched using XTOA instructions in parallel (original code versus user code).
Perhaps it would be enough to use synthetic instructions that directly affect the M register (and to do an XTOA on each of the two codes) to avoid slowing down the program too much.
In summary, this program is already very interesting as it is, but it is even more so because of the progress and openings it offers us.
Through this Mastermind program, we see that to get it to work properly, you need a code to break (of a size of 4 to 5 characters, usually)
and an assignment table which allows you to know if one of the characters of the code to find is already supported (reserved) in one way or another (black or white)
by the code proposed by the user. From then on, the creation of a good program, one which will return the correct result, is assured.
Keep you safe
Laurent
RE: (41CX) Master Logic - Mastermind - Code-breaking Game with letters combination - Nihotte(lma) - 08-15-2024 09:38 PM
Of course, this program could be improve... I said
So, this program uses the flags 01 to 06 as assigned table
As well, it doesn't run on a 41CV or a 41C
The XTOA and ATOX instructions are used in this program
X<>F could be changed by CF 00 to CF 07
Program for HP41CX
Code:
** LBL TSMM Super Master Mind – Actualised version of 08/2024 for 41CX
CLX
STO 10 Number of guesses already tried
CF 29
FIX 0
XEQ d Number of pegs
STO 07 Keeps the number of pegs
STO 08 Count of loops #1
* LBL 06 Generates the code to break
XEQ c
XEQ TRAN≠
ALENG
*
AROT
ATOX Chooses a character
STO IND 08
DSE 08
GTO 06
* LBL 01 Gives the list of the distinct characters
AON
XEQ c
TͰˍ?
CLST
STOP Prompts and waits for a guess
AOFF
ALENG
RCL 07
X≠Y? Simple control of the size of of the guess
GTO 01
STO 08
CLX
STO 11 Result of the white scoring
STO 12 Result of the black scoring
ASTO 13
1
ST+ 10 Number of attempts already made by the user
* LBL 02 Calculates the number of well-placed pegs found
12 Black counter in deal
XEQ 08 Verifies each of the 5 pegs of the guess with the same position in the code to break
DSE 08
GTO 02
RCL 12
RCL 07
X=Y? The guess obtains full well-placed pegs ?
GTO 03
STO 08
* LBL 04
CLA
ARCL 14 Restores the portion of the guess always without affectation 'black' or 'white'
ALENG
X=0? All the guess has been verified ?
GTO 07
STO 09 Size of the leaving portion of the guess not already controlled - Count of loops #2
* LBL 05 Calculates the number of good colors found
11 White counter in deal
XEQ 08 Verifies the current pegs of the guess within the always free pegs of the code to break
DSE 09
GTO 05
* LBL 07
DSE 08
GTO 04
XEQ b
CLA Displays the score obtained by the guess : Black and White positions
ARCL 13
TͰˍ
ARCL 12
TͰBˍ
ARCL 11
TͰW
TONE 7 Result of the guess is ready
PROMPT
RCL 10
XEQ e
X>Y? Number of attempts reached ?
GTO 01 No : next guess
XEQ a Game is over : you failed to break the code
TͰ==>ˍ
ARCL 07
TͰB
TONE 0
GTO 00
* LBL 03 Game is over : successful result
XEQ a
TͰINˍ
ARCL 10
TͰa
BEEP
* LBL 00 Exit from the program
AVIEW
SF 29
FIX 9
XEQ b
RTN
* LBL b Flags 0-7 set to cleared status
CLST Clean all the stack
X<>F
CLX
RTN
* LBL 08 Dynamic subroutine of checking for a peg (guess) to a peg (code)
FS? IND 08
RTN Has been the peg successful assigned ?
SF 00 Keeps the portion of the guess that remains to be verified
RCL IND 08
ATOX
X≠Y? Is the current peg of the guess suitable with the current peg of the code ?
GTO 09 No : back
CF 00 No needs to keep the current peg of the guess : it has been paired with the code to break
RCL Z
1
SF IND 08 The current peg of the code is no more free
ST+ IND Y STO 12 (black) or STO 11 (white) is increased
* LBL 09
FS?C 00 Is the current peg of the guess paired ?
XTOA No : keep it . Later, maybe...
ASTO 14
RTN
* LBL a Insert the full code to break in the display (alpha register)
CLA
RCL 07 Recalls the number of pegs
* LBL 10
RCL IND X
XTOA
X<>Y
DSE X
GTO 10
TͰˍ
RTN
* LBL c List of usable colors
TBJGMNORV Accepts 6, 7, 8 or 9 characters
RTN
* LBL d Number of pegs
5 Insert 3, 4, 5 or 6 – but not 7 or more
RTN
* LBL e Number of guesses allowed
12 Usually 6 or 12 – but 99 is smart
END 136 lines – 260 bytes
** LBL TRAN≠ Generates a random number : between 0 and 1
RCL 00 Seed
FRC
X=0?
.5284163
997
*
FRC
STO 00
END 10 lines – 29 bytes
Requires SIZE 015
Uses Flags 0 to 6
Registers :
00 : Ran#
01 to 06 : Characters of the code to break
07 : Number of pegs
08 : Counter of loops #1
09 : Counter of loops #2
10 : Number of attempts made by the user
11 : Number of white positions for the last guess
12 : Number of black positions for the last guess
13 : Keeps a copy of the last user guess
14 : Unpaired part of a guess
(41CX) Master Logic - Mastermind - Code-breaking Game with letters combination
Mastermind is a wellknown game for two players :
a codemaker chooses a combination of four or five pegs and the other player will try to break this code.
This publication is based on a program for the 41CX : it was written in 07/2004 and actualised in 08/2024
At this time, I prefered to use the names of the colors instead of the position of a colour in my set.
So, I prepared this program to use letters instead of numbers to represent colors.
Just enter XEQ 'ALPHA' SMM to start the program
You receive BJGMNORV ? at display when you can choose your guess and R/S
The 41CX answers the number of pegs you have found (B) and the number of pegs with the good color (W)
but not well-placed
The number of attempts is limited to 12 (in LBL e)
The number of pegs in a combination is declared on LBL d (with 5)
The list of available colors is known by LBL c (BJGMNORV)
Example
Code:
f π STO 00 : stores PI in register 00 for the seed of the generator
XEQ TSMM
----- 74 71 71 66 86 in R05 to R01 : JGGBV
GGVVV R/S : GGVVV 2B 1W
R/S
VBJGG R/S : VBJGG 0B 5W
R/S
BVGJV R/S : BVGJV 2B 2W
R/S
…
JGGBV R/S : JGGBV IN 8a
R/S
Keep you safe
Laurent
RE: (41CX) Master Logic - Mastermind - Code-breaking Game with letters combination - Nihotte(lma) - 08-18-2024 12:08 AM
Yet another episode on the theme.
This time, I only kept in the program mechanism the characters that remained without pairing between the code to find and the combination proposed by the user.
That is to say, I no longer use an assignment table in the execution of the program.
The principle adopted is the following:
- if a character can match, it disappears from both codes (the code to be broken and the one proposed by the user)
- otherwise it is kept for a possible later stage of the same control phase
The program always proceeds in two verification phases:
- a first step which brings each pawn closer to the same position (position declared BLACK)
- a second step which brings the remaining pawns together and checks if they coincide but with regard to another location (position only WHITE declared)
The program is this one
Code:
** LBL TSMM Super Master Mind – Actualised version of 08/2024 for 41CX
CLX
STO 10 Number of guesses already tried
CF 29
FIX 0
XEQ d Number of pegs
STO 07 Keeps the number of pegs
STO 08 Count of loops #1
CLA
ASTO 01
* LBL 06 Generates the code to break
XEQ c
XEQ TRAN≠
ALENG
*
AROT
ATOX Chooses a character
CLA
ARCL 01
XTOA
ASTO 01
DSE 08
GTO 06
* LBL 01 Gives the list of the distinct characters
AON
XEQ c
TͰˍ?
CLST
STOP Prompts and waits for a guess
AOFF
ALENG
RCL 07
X≠Y? Simple control of the size of of the guess
GTO 01
STO 08
CLX
STO 06 Result of the white scoring
STO 11 Result of the black scoring
ASTO 04
ASTO 03
1
ST+ 10 Number of attempts already made by the user
RCL 01
STO 02
RCL 03
* LBL 02 Calculates the number of well-placed pegs found
XEQ 08 Verifies each of the 5 pegs of the guess with the same position in the code to break
DSE 08
GTO 02
RCL 07
RCL 06
STO 12
ST- 11
X=Y? Does he guess obtain full well-placed pegs ?
GTO 03
-
STO 08 Number of pegs of the code without 'black' affectations
* LBL 04
CLA
ARCL 02 Restores the part of the code to break always without affectations
ALENG
X=0? All the guess has been verified ?
GTO 07
STO 09 Size of the leaving portion of the guess not already controlled - Count of loops #2
RCL 02 Residual code
RCL 03 Residual guess
* LBL 05 Calculates the number of good colors found
CLX
RCL 03 White counter in deal for the current pegs of the guess
XEQ 08 Verifies the current pegs of the guess within the current free peg of the code to break
DSE 09
GTO 05
* LBL 07
STO 03
DSE 08
GTO 04
RCL 06
ST+ 11
CLST Cleans the stack
CLA Displays the score obtained by the guess : Black and White positions
ARCL 04 Restores all the guess in deal
TͰˍ
ARCL 12
TͰBˍ
ARCL 11
TͰW
TONE 7 Result of the guess is ready
PROMPT
RCL 10
XEQ e
X>Y? Number of attempts reached ?
GTO 01 No : next guess
XEQ a Game is over : you failed to break the code
TͰ==>ˍ
ARCL 07
TͰB
TONE 0
GTO 00
* LBL 03 Game is over : successful result
XEQ a
TͰINˍ
ARCL 10
TͰa
BEEP
* LBL 00 Exit from the program
AVIEW
SF 29
FIX 9
RTN
* LBL 08 Dynamic subroutine of checking for a peg (guess) to a peg (code)
CLA
ARCL X
ATOX
ASTO 05
CLA
ARCL Z
ATOX
X≠Y? Is the current peg of the guess suitable with the current peg of the code ?
GTO 09 No : back
1 Yes : adds a point for 'black' or 'white' positions
ST+ 06
ASTO X Adjusts for the next peg in the code without keeping the current peg
STO 02
RCL 05 Adjusts for the peg in the guess without keeping the current peg
STO 03
RTN
* LBL 09 The current peg of the guess does not match with the current peg of the code
XTOA So, keep them. Later, maybe...
ASTO X
X<>Y
CLA
ARCL 05
XTOA
ASTO X
RTN
* LBL a Insert the full code to break in the display (alpha register)
CLA
ARCL 01 Recalls the number of pegs
TͰˍ
RTN
* LBL c List of usable colors
TBJGMNORV Accepts 6, 7, 8 or 9 characters
RTN
* LBL d Number of pegs
5 Insert 3, 4, 5 or 6 – but not 7 or more
RTN
* LBL e Number of guesses allowed
12 Usually 6 or 12 – but 99 is smart
END 149 lines – 269 bytes
** LBL TRAN≠ Generates a random number : between 0 and 1
RCL 00 Seed
FRC
X=0?
.5284163
997
*
FRC
STO 00 Next seed
END 10 lines – 29 bytes
Requires SIZE 013 at least
Registers :
00 : Ran#
01 : Code to break
02 : Work copy of the code to break
03 : Work copy of the guess
04 : Saves the current guess
05 : untested part of the guess
06 : Counter of good paired pegs (black or white without distinction)
07 : Save the total number of pegs
08 : Counter of loops #1
09 : Counter of loops #2
10 : Number of attempts made by the user
11 : Number of white positions for the last guess
12 : Number of black positions for the last guess
(41CX) Master Logic - Mastermind - Code-breaking Game with letters combination
Mastermind is a wellknown game for two players :
a codemaker chooses a combination of four or five pegs and the other player will try to break this code.
This publication is based on a program for the 41CX : it was written in 07/2004 and actualised in 08/2024
At this time, I prefered to use the names of the colors instead of the position of a colour in my set.
So, I prepared this program to use letters instead of numbers to represent colors.
Just enter XEQ 'ALPHA' SMM to start the program
You receive BJGMNORV ? at display when you can choose your guess and R/S
The 41CX answers the number of pegs you have found (B) and the number of pegs with the good color (W)
but not well-placed
The number of attempts is limited to 12 (in LBL e)
The number of pegs in a combination is declared on LBL d (with 5)
The list of available colors is known by LBL c (BJGMNORV)
With the same process and example
Code:
f π STO 00 : stores PI in register 00 for the seed of the generator
XEQ TSMM
----- 74 71 71 66 86 sent into R01 : JGGBV
GGVVV R/S : GGVVV 2B 1W
R/S
VBJGG R/S : VBJGG 0B 5W
R/S
BVGJV R/S : BVGJV 2B 2W
R/S
…
JGGBV R/S : JGGBV IN 8a
R/S
Few changes in the use of the registers
R06 counts and grows for all the paired pegs : black or white without distinction
Code:
00 : Ran#
01 : Code to break
02 : Work copy of the code to break
03 : Work copy of the guess
04 : Saves the current guess
05 : untested part of the guess
06 : Counter of good paired pegs (black or white without distinction)
07 : Save the total number of pegs
08 : Counter of loops #1
09 : Counter of loops #2
10 : Number of attempts made by the user
11 : Number of white positions for the last guess
12 : Number of black positions for the last guess
Keep you safe !
Laurent
|