🎮 WDC #24 Let's Play Mastermind!

Looks great, @muneer! And thanks for your kind words. I enjoyed our California <–> Bahrain evening/morning game of Mastermind. :grinning:

4 Likes

I agree to this… I played today after i copied the project and i really enjoyed :blush:
A color picker to choose a color, and not to click till desired color will set, a check not to validate a round before all 4 colors are set, a bit of hapiness design and the game is ready to be uploaded on Store, really :smiling_face_with_three_hearts:

3 Likes

Thank you for your comments @mimostel
I built the app as WDC not as an app to be published. As you know these changes can easily be implemented but will not add much for WDC.

The app was developed using DnD UI which was not an easy task but I wanted to take it as a challenge.

There are issues in DnD UI preventing good use of the app such as the colors. The screen color is ok when using the computer but it shows with a different color on the phone. The strange thing is the “New Game” button, it changes color when you click on it although there is no code in the app to change its color.

If I would think of publishing the game I will re-do it using StP UI.

2 Likes

I know. I just wanted to emphasize that the application is so good that it could be published. :blush:

2 Likes

Ha… so StP rock :innocent:

1 Like

In awe of everyone’s submissions!

Here’s mine: it’s quite basic and I’m sure it has a lot of bugs in it (and the UI is also horrible), but I’m submitting it as v1 :grinning:
https://x.thunkable.com/projectPage/6157322ac8a7bf00107a0a23
A black peg means that the color is placed correctly, a white peg means that the color exists in the code but is placed somewhere else, and a grey peg means that the color doesn’t exist at all in the code. In the game I have, there are only 6 tries before you lose. Unlike @muneer’s and @tatiang’s apps, though, you don’t click on the cells to set a colour. There are colours at the bottom of the page, and when you click on them, they automatically set into the right cell. Any suggestions would be highly appreciated!

Screenshots:





Enjoy!

5 Likes

Looks good, @codeswept! The first time I played, though, I got impossible results:

It’s showing that there are six pegs in the secret code, two from the first row and four from the second row.

2 Likes

Oh no! It looks like when displaying the white peg for a color it’s including the one ‘red’ regardless of whether or not I’ve already marked that. Do you have any tips on what I can do to fix it?

i got my “poor man’s mastermind” almost working!
for this debugging run, my target is at the top (supposed to be hidden). the feedback “2M 1F” means two numbers were found with the same value and at the same location and one number was found but not in the correct position.
i’m allowing 4 numbers only and the digits cannot repeat and it can only be numbers 1 thru 8.
(in this run, i was only allowing 1 thru 6) and the direction play is “downwards”. i still have to add the check for win or loss. i am not much of a GUI guy.

5 Likes

But you voted for StP UI in voting. :angry:

… and “StP rock” means a positive thing, lol it means that is better than good :rofl: (stays as strong as a rock)

I will just quote as edit here, cause this is nor the place, neither the time to argue with you, but with all the respect that this awesome community deserve, i dont get you… Im sorry.

2 Likes

I’m trying to figure this out in my own project and if I do, I’ll let you know. I was thinking of having the secret code list and then doing a get and remove after a matching peg color is found.

2 Likes

I made it in a staged way. I have 2 counters that are set to 0 at the start of each round. One counter for the red colored pegs and the other for white (I used grey) colored pegs.

The first stage I loop through the 4 buttons checking if the color matches the hidden one using the same index. If it is then I increment red-counter.

I then check the red-counter value, if 4 then it’s a WIN, else I continue to next stage.

The second stage, I go through a loop again checking the colors of the active row with colors available in the hidden buttons and check that the index is not the same, if yes then I increment the white-counter.

The last step is to check the two counters to change the peg colors accordingly.

Hope this makes sense.

2 Likes

I tried the same thing, but I got confused halfway and left it.

1 Like

Would it be possible to show a screenshot of these blocks?

1 Like

Stage 1

Stage 2

Show results

This is available in the project I shared, but I keep enhancing so better remix to get the latest.
In this version, I use a list instead of creating 2 counters but I tried both ways and both are working.

[Edit]
Just forgot to mention. I am using DnD and cloning is not yet available so I had to name the buttons in a systematic way to be able to refer to them by code. So just ignore the naming complication and focus on the approach/technique.

1 Like

actually you can do the checking in one loop - by using a dictionary to keep track of colors used. (a dictionary is a kind of array that can be indexed by non-number, eg. Sales[“Monday”]=37). At the time the TARGET is entered, store the colors used in a dictionary.

for example, the target (red.blue.green,green) would populate the dictionary this way:

image

the value of COLORS_USED_COUNT[“green”] indicates that there are 2 greens in the target - it doesn’t matter if they’re side by side or not.

everytime you process a guess, make a fresh copy of this dictionary and update it as you find colors.

  LOOP i=1 to 4 {
    color=guess(i)
    if colors_used_count[color] > 0  {   // (ie. was this color used in target?
       if guess(i)=target(i)  {          // does it match corresponding target}
          match_count = match_count + 1  // must be a match
       else
          found_count = found_count + 1  // just a found
       }
       colors_used_count [color] = colors_used_count[color] - 1  // mark 1 color used
    }
  }

i know we don’t have dictionaries in thunkable (- yet ?) but you can simulate them using regular arrays but you have to keep track of mapping color values to index values.

3 Likes

I am actually using the same logic. I store the randomly selected colors in a list and I compare it with the color list of the active row to check matches. I’m just doing it in two stages as I feel it would be easier to debug.

Thanks for the excellent explanation.

2 Likes

Yeah, I’m doing the same thing. Very helpful explanation!

3 Likes

I’m pretty happy with this so far. It still needs a little polishing… I’ll be adding the following:

  1. Reveal the secret code when you win
  2. Notify you when you lose
  3. Restart game button

But I’m close to getting done! The hard part is out of the way. Phew! :sunglasses:

I’ve added a hint button that reveals one of the secret peg colors. Try it out here: https://thunkable.site/web-build/index.html?webAppId=iG5c-QgZZ

(No sound)

5 Likes