Master Mind Script
Webb - all rights reserved - ©2004
spacer
Author - Jann Scheuer
Email: scheuer@coco.ihi.ku.dk
Webpage:

Summary: Master Mind with adjustable string length, scoring system and
fast guessing facilities

Instructions:
J-Mast

MasterMind for the rpn (guess a randomized string of numbers)

Adjustable:
string length adjustable between 1 and 9
max value of numbers in string adjustable between 1 and 9

Utilities:
simple facilities for fast guessing

Scoring features:
time spent
number of guesses spent
scoring system with high score

Controls:
Mx - create a new string to guess, (and reset timer, score and number of
guesses)
St - set parameters menu
Sc - score menu
Cl - clear stack, timer, score and number of guesses
+ + + + + + - increase digits 1 to 6 in tos (current guess)
- - - - - - - decrease digits 1 to 6 in tos (current guess)
# - put a string in tos consisting only of 1's, 2's, 3's and so forth
(see example below)
? - compute guess
< - rotate stack but keep tos
> - rotate stack backwards but keep tos

Set parameters menu:
M - set max value of numbers in string to guess
L - set length of string to guess
Rh - reset high score
Rv - reveal string to guess

Score menu:
#Guess - number of guesses spent
T - time spent
S - score
H - high score

Example:
Set string length to 4 and maximium value of numbers in string to 4.
(Press St and M and L
respectively to adjust.)

Press Mx to start timer and create string to guess (not shown of course,
but let's assume that the string '2144' is created).

Press # to put '1111' in tos.
Press ? to compute guess.
Let's say that rpn answers '1111.1'. This means that one number in the
guess is correct.

Press # to put '2222' in tos. Press the leftmost - to change to '1222'.
Press ? to compute guess.
Let's say that rpn answers '1222.02'. This means that two numbers are in
the hidden string but in other locations.

Press # to put '3333' in tos. Press leftmost - once, and next - twice
to change to '2133'.
Press ? to compute guess.
Rpn answers '2133.2'. (Two correct numbers).

Press input field to repeat guess, i.e. duplicate '2133.2'. Press + in
third and fourth position
to change to '2144.2'.
Press ? to compute guess (fractional part of guess doesn't matter).
Rpn answers 'Correct!' and '2144.4'. You got it!

You can now inspect number of guesses, guessing time and score. If you
made a high score you will be told.

IMPORTANT WARNING:
Before using the application for the first time, suitable values for
string length and maximum
value of numbers should be chosen! Otherwise the application may go into
an endless loop when
computing a guess!

Follow this routine before application is used for the first time:
Press St for setting parameters.
Press M for adjusting maximum value of numbers in string. Use arrows to
adjust to value between 1 and 9.
Press L for adjusting length of string. Use arrows to adjust to value
between 1 and 9.

Remark:
Values for time and score will only be correct after guessing the right
string.

Code:

RPN.1.m \ J-Mast
[t]#'10';
[%]Ct%;
[w]Ct/w;
[z]V1Xa{CtxaPv>(B:xa1+Xa)}xa;
[r]XbxbC%CtxbCzP*xb+Cw;
[s]Xcxc0XexcCzV{_vxcC%xdC%=0
(xcCwXcxdCwXdxe#'0.1'+Xe:xcCrXcxdCrXd)};
[v]xcCzV{_vxcC%CuxcCwXc};
[u]VxdCzXg{xdC%v=0(xdCwXdxe#'0.01'+XeB:xdCrXd)xg1-Xgxg0=0(B)};
[e]Csxd0=0(Ttxl-Ct2P/XlD'Correct!|Ok|'d1Ctxixh+1-Pxjxl*/wXmxmxk>(xmXkxkUdD'Master
Mind!\High score!|Ok|'d1d1):Cv)xe+;
[h]xhr2-g11<(d1.)XbXaxaxaCtxb1-P/wC%;
[f]Chxi<(Ctxb1-P+);
[g]Ch1>(Ctxb1-P-);
"J-Mast"
"Mx"TtXl0Xj#''bxi%1+Xfxh1-V{_vxfCt*Xf#''bxi%1+xf+wXf};
"St"D'Max, Length, Reset high, \Reveal |M|L|Rh|Rv|-|'
c(xiUd{D'Max|<|Ok|>|'c(g11>(1-):XiB:g19<(1+))Ud}:xhUd{D'# of
fig|<|Ok|>|'c(g11>(1-):XhB:g19<(1+))Ud}:0Xk:xf:);
"Pt"D'#Guess, Time, Score, High \score|#|T|S|H|-|'c(xj:xl:xm:xk:);
"Cl"hV{_vd1}0Xf0Xj0Xl0Xm;
~
"+"0Cf;"+"1Cf;"+"2Cf;"+"3Cf;"+"4Cf;"+"5Cf;
~
"-"0Cg;"-"1Cg;"-"2Cg;"-"3Cg;"-"4Cg;"-"5Cg;
~
"#"xjxi<(xj1+:xi)XbxbXaxh1-V{_vxaCt*xb+Xa}xa;
"?"xj1+XjxfXdwCe;
"<"Vhr@v;
">"Vhk@v;