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)