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