This isn't your parents' Mastermind game!
This program is 439 bytes (with the name MSTRMIND) and includes such features as:
- A number input system without using Input (takes a bit from our Number Pad Routine)
- As graphical an interface as the homescreen can offer
- Red and white pegs (formula from Wolfram Mathworld
This is the formula for white pegs, as used in the program:
where ci is the amount of times that i is in the code, gi is how many times it is in the guess, and r is the amount of red pegs. Red pegs are how many numbers are right and in their correct position, white pegs are how many numbers are right, but in the wrong position.
Now for the boring stuff…
In this Mastermind clone, you have 15 tries to guess a code of 4 numbers randomly generated by the calculator.
Use the number pad to enter in numbers, LEFT to undo one letter, and ENTER to guess. It will then tell you the red and white peg count, and if there are 4 red pegs, you win! Press ENTER to get past the win screen. Press CLEAR to exit at any time during play.
I've spent 3 months with this program, and I've decided to release it now, as I think it's good enough to be another one of our examples.
ClrHome "? Disp "NUMBER:","",Ans,Ans,Ans,Ans Output(8,1,"RED: 0 WHITE: 0 DelVar TDelVar GDelVar Rint(10rand(4→L1 4→dim(L2 Repeat T=14 or K=45 or R=4 Repeat Ans getKey End Ans(102≠Ans)-13int(Ans/13(2>abs(5-abs(5-abs(Ans-83→K If Ans=105 and G=4 Then For(X,1,4 Output(2+X,3+T,L2(X End DelVar GT+1→T sum(L1=L2→R Output(8,6,Ans Output(8,16,‾Ans+sum(seq(min(sum(L1=X),sum(L2=X)),X,0,9 Output(1,9," //4 spaces Else If Ans≤9 and G≠4 Then G+1→G K→L2(Ans End If Ans=24 and G Then G-1→G Output(1,Ans+9," //1 space End End For(X,0,G If X Output(1,8+X,L2(X End End For(X,1,4 Output(2+X,1,L1(X End If K≠45 Then Output(1,1,"YOU "+sub("WIN! LOSE...",8-7(R=4),7 Pause End DelVar GDelVar KDelVar RDelVar TDelVar XDelVar L1DelVar L2ClrHome
Whaddaya think? Any improvements or suggestions? And can this be integrated with the Mastermind example here?
:ClrHome:Disp "HOW DOES A","MATHEMATICIAN","LOSE WEIGHT? :Pause " :Pause "BINOMIALS! :Pause "(BUY NO MEALS)":ClrHome