Towards AI in Choicescript: MasterMind solver

Well, the title is a hyperbole, but it was a fun experiment. I quickly put together a little program to guess a sequence, like the old MasterMind puzzle. The computer will guess your sequence, usually in 8 attempts or less.

https://dashingdon.com/play/sciscidiego/mastermind/mygame/

Note that this is more difficult than the standard version with 6 colors. Here there are 10 “colors”, with repetitions.

The program is pure CS, including 10000 lines to create the initial array of combinations, and is compiled from my meta-language to help with loops and functions. Feel free to have a peak behind the curtains!

Yes, the first iteration is a little slow, I have not tried to optimize it. Let me have your thoughts! My thoughts are that we really need arrays, loops and functions in CS!

Update: Given the interest, a few comments on my tools. The startup.txt file is compiled from a source file in my extended language. A few commands I added are:

// Unrolls to a sequence of *create commands.
*array combos 10000 0
// Loop from 0-9. The @i is replaced with a unique symbol.
// Mapped to goto, if, increment.
*for @i 0 10
// Creates a block where the params are replaced with unique
// identifier to prevent conflicts.
*function compare @guess @combo

You can see the source of the game here:
https://dashingdon.com/play/sciscidiego/mastermind/mygame/scenes/mastermind.txt

14 Likes

Woah… I used 1776 and it guessed it in 5 tries. Then I used 0000 and it guessed it in 6 tries. That’s crazy. I don’t know how you did it, but this is really cool!

2 Likes

Who are the love interests?

12 Likes

Amazing! How can I check out the code?

Thanks for your interest @YHGS . Like all hosted games, you can easily see the CS file in your browser.

https://dashingdon.com/play/sciscidiego/mastermind/mygame/scenes/startup.txt

The generated code is very confusing - it’s like machine language with goto and jumps. The source that goes into my preprocessor is here, and should be much easier to follow.

https://dashingdon.com/play/sciscidiego/mastermind/mygame/scenes/mastermind.txt

Let me know if you have questions. By the way, the logic becomes simpler if you don’t allow for repetitions in the secret code.

Good luck with your game. I’d enjoy testing it!

2 Likes

Thank you, but I have already submitting it to HG

1 Like

Is your CS preprocessor available anywhere? It looks like a lot of these things I’ve been looking for but have been too lazy to write myself.

1 Like

I will send it to you privately, it’s not very polished. Maybe I can clean it up with your suggestions.

Seeing a *function command in your code is like a dream come true. I’d also love to see the preprocessor, if that’s alright!

Sent privately. Let me have your thoughts.