The following warnings occurred:
Warning [2] count(): Parameter must be an array or an object that implements Countable - Line: 795 - File: showthread.php PHP 7.4.33 (FreeBSD)
File Line Function
/showthread.php 795 errorHandler->error





Post Reply 
(41CX) Master Logic - Mastermind - Code-breaking Game with letters combination
08-09-2024, 03:21 PM (This post was last modified: 08-09-2024 09:04 PM by Nihotte(lma).)
Post: #1
(41CX) Master Logic - Mastermind - Code-breaking Game with letters combination


(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...)


Attached File(s)
.pdf  HP41CX - Super MasterMind - lmaN for MoHPC.pdf (Size: 75.29 KB / Downloads: 18)
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
(41CX) Master Logic - Mastermind - Code-breaking Game with letters combination - Nihotte(lma) - 08-09-2024 03:21 PM



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