(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:
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...) |
|||
08-13-2024, 12:01 AM
(This post was last modified: 08-13-2024 12:05 AM by Nihotte(lma).)
Post: #2
|
|||
|
|||
RE: (41CX) Master Logic - Mastermind - Code-breaking Game with letters combination
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 |
|||
08-15-2024, 09:38 PM
Post: #3
|
|||
|
|||
RE: (41CX) Master Logic - Mastermind - Code-breaking Game with letters combination
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:
Example Code:
Keep you safe Laurent |
|||
08-18-2024, 12:08 AM
(This post was last modified: 08-18-2024 12:17 AM by Nihotte(lma).)
Post: #4
|
|||
|
|||
RE: (41CX) Master Logic - Mastermind - Code-breaking Game with letters combination
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:
With the same process and example Code:
Few changes in the use of the registers R06 counts and grows for all the paired pegs : black or white without distinction Code:
Keep you safe ! Laurent |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)