Omnimaga

Calculator Community => Other Calc-Related Projects and Ideas => TI Z80 => Topic started by: JWinslow23 on November 24, 2013, 03:17:57 pm

Title: Barebones Mastermind Game
Post by: JWinslow23 on November 24, 2013, 03:17:57 pm
This isn't TI|BD's [tibd]Mastermind[/tibd] game!

I made a version of Mastermind in 439 bytes (including the name, MSTRMIND). It uses numbers 0-9, keypresses instead of Input for inputting numbers, and it shows red and white pegs instead of right/part-right/wrong numbers.

I got the white peg formula from Wolfram Mathworld (http://mathworld.wolfram.com/Mastermind.html). This is it, as used in the program:

(http://latex.codecogs.com/gif.latex?w%3D%28%5Csum_%7Bi%3D1%7D%5E%7B9%7D%20%5Cmin%20%28c_%7Bi%7D%2Cg_%7Bi%7D%29%29-r)

ci is how many times color i was in the code, and gi is how many times it was in the guess. r, of course, is how many red pegs thrown out.

The file is attached. You press the number pad to input numbers, ENTER to guess it, and CLEAR anytime to quit. A half-second after guessing, you will see the change in red and white pegs. You get 14 guesses.

Give tips for even more optimization, if possible!
Title: Re: Barebones Mastermind Game
Post by: AssemblyBandit on November 24, 2013, 07:34:38 pm
Found  a bug! Because it checks for the winning number when I enter it, all I have to do is find 2 or 3 numbers then randomly enter the other digits, hit left to erase them, and repeat until it says I win!
Title: Re: Barebones Mastermind Game
Post by: JWinslow23 on November 24, 2013, 08:57:07 pm
What do you mean by that? Give me an example.
Title: Re: Barebones Mastermind Game
Post by: AssemblyBandit on November 24, 2013, 09:51:19 pm
You know how you type in the 4 numbers then press enter and it copies the numbers to the side? If you never press enter you can press 0000 then press left to erase it, then 0001... eventually you would find the right number and win without ever using one guess! Instead of checking for the winning number after its posted, the game checks for it as its entered.
Title: Re: Barebones Mastermind Game
Post by: JWinslow23 on November 25, 2013, 09:29:55 am
Now that I know what you mean, I will fix it.

EDIT: I found the problem! Alternate download coming soon, but for now:
1. Replace DelVar TDelVar Gint(10rand(4→L1 with DelVar TDelVar GDelvar Rint(10rand(4→L1
2. Replace Repeat T=14 or K=45 or 4=sum(L1=L2 with Repeat T=14 or K=45 or R=4
3. Replace sum(L1=L2 with sum(L1=L2→R
4. Replace Output(1,1,"YOU "+sub("WIN!   LOSE...",1+7(T=14),7 with Output(1,1,"YOU "+sub("WIN!   LOSE...",8-7(R=4),7
5. Replace DelVar GDelVar KDelVar TDelVar XDelVar L1DelVar L2ClrHome with DelVar GDelVar KDelVar RDelVar TDelVar XDelVar L1DelVar L2ClrHome

Eats up an extra variable, but it has the same size!
Title: Re: Barebones Mastermind Game
Post by: AssemblyBandit on November 25, 2013, 04:47:55 pm
Works perfect!
Title: Re: Barebones Mastermind Game
Post by: JWinslow23 on November 25, 2013, 06:44:07 pm
Thanks for the small bugtest! Download in a few minutes!

EDIT: The file is attached here.