# 🎮 WDC #24 Let's Play Mastermind!

**URL:** <https://community.thunkable.com/t/wdc-24-lets-play-mastermind/1538130>\
**Category:** Teachers' Lounge\
**Tags:** wdc\
**Created:** [October 1, 2021, 3:24pm UTC](https://community.thunkable.com/t/wdc-24-lets-play-mastermind/1538130 "2021-10-01T15:24:04Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [October 4, 2021, 6:01pm UTC](https://community.thunkable.com/t/wdc-24-lets-play-mastermind/1538130/22 "2021-10-04T18:01:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mimostel](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/mimostel/32/107661_2.png) [@mimostel](https://community.thunkable.com/u/mimostel)\
**Post date:** [October 4, 2021, 6:33pm UTC](https://community.thunkable.com/t/wdc-24-lets-play-mastermind/1538130/23 "2021-10-04T18:33:01Z")

</div>

> [@tatiang](#):
>
> Looks great, @muneer!

I agree to this… I played today after i copied the project and i really enjoyed 😊  
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 🥰

---

<div class="post-metadata">

**Author:** ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)\
**Post date:** [October 5, 2021, 5:20am UTC](https://community.thunkable.com/t/wdc-24-lets-play-mastermind/1538130/24 "2021-10-05T05:20:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mimostel](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/mimostel/32/107661_2.png) [@mimostel](https://community.thunkable.com/u/mimostel)\
**Post date:** [October 5, 2021, 5:23am UTC](https://community.thunkable.com/t/wdc-24-lets-play-mastermind/1538130/25 "2021-10-05T05:23:54Z")

</div>

> [@muneer](#):
>
> I built the app as WDC not as an app to be published.

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

---

<div class="post-metadata">

**Author:** ![mimostel](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/mimostel/32/107661_2.png) [@mimostel](https://community.thunkable.com/u/mimostel)\
**Post date:** [October 5, 2021, 5:45am UTC](https://community.thunkable.com/t/wdc-24-lets-play-mastermind/1538130/26 "2021-10-05T05:45:13Z")

</div>

> [@muneer](#):
>
> If I would think of publishing the game I will re-do it using StP UI.

Ha… so StP rock 😇

---

<div class="post-metadata">

**Author:** ![codeswept](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/codeswept/32/87755_2.png) [@codeswept](https://community.thunkable.com/u/codeswept)\
**Post date:** [October 5, 2021, 6:05am UTC](https://community.thunkable.com/t/wdc-24-lets-play-mastermind/1538130/27 "2021-10-05T06:05:08Z")

</div>

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 😀  
[https://x.thunkable.com/projectPage/6157322ac8a7bf00107a0a23](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:

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/f/4/f4a835e97c1dc8d33e1efdc075773c5f17122e87.png)  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/b/7/b7435a471e2ba6801b220457501385292c4a9af8.png)  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/1/4/14e9bac09d2b35dbc0b9c441dbddfd5a42863c73.png)  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/6/0/60afc928416ceb17c995dd87d06e1d6c1535b1d1.png)  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/8/0/80121e109cc24e6bb81362ba72d762d96813f726.png)

Enjoy!

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [October 5, 2021, 6:26am UTC](https://community.thunkable.com/t/wdc-24-lets-play-mastermind/1538130/28 "2021-10-05T06:26:32Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/b/6/b6b2b5a8f092b58126b0bf5e687ef5f8173f5864.png)

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

---

<div class="post-metadata">

**Author:** ![codeswept](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/codeswept/32/87755_2.png) [@codeswept](https://community.thunkable.com/u/codeswept)\
**Post date:** [October 5, 2021, 7:09am UTC](https://community.thunkable.com/t/wdc-24-lets-play-mastermind/1538130/29 "2021-10-05T07:09:00Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![manyone](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@manyone](https://community.thunkable.com/u/manyone)\
**Post date:** [October 5, 2021, 7:36am UTC](https://community.thunkable.com/t/wdc-24-lets-play-mastermind/1538130/30 "2021-10-05T07:36:34Z")

</div>

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.

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/a/3/a3d1a329f4099583b4cb3dac7a473263aacc8b6a.png)

---

<div class="post-metadata">

**Author:** ![vishruth-ram](https://avatars.discourse-cdn.com/v4/letter/v/82dd89/32.png) [@vishruth-ram](https://community.thunkable.com/u/vishruth-ram)\
**Post date:** [October 5, 2021, 9:55am UTC](https://community.thunkable.com/t/wdc-24-lets-play-mastermind/1538130/31 "2021-10-05T09:55:56Z")

</div>

> [@mimostel](#):
>
> so StP rock 😇

But you voted for StP UI in voting. 😠

---

<div class="post-metadata">

**Author:** ![mimostel](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/mimostel/32/107661_2.png) [@mimostel](https://community.thunkable.com/u/mimostel)\
**Post date:** [October 5, 2021, 9:57am UTC](https://community.thunkable.com/t/wdc-24-lets-play-mastermind/1538130/32 "2021-10-05T09:57:33Z")

</div>

> [@vishruth-ram](#):
>
> But you voted for StP UI in voting.

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

> [@vishruth-ram](#):
>
> So now getting out of the community as you were not the community guidleines followers group!

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.

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [October 5, 2021, 3:18pm UTC](https://community.thunkable.com/t/wdc-24-lets-play-mastermind/1538130/34 "2021-10-05T15:18:07Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)\
**Post date:** [October 6, 2021, 7:37am UTC](https://community.thunkable.com/t/wdc-24-lets-play-mastermind/1538130/35 "2021-10-06T07:37:14Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![codeswept](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/codeswept/32/87755_2.png) [@codeswept](https://community.thunkable.com/u/codeswept)\
**Post date:** [October 6, 2021, 7:49am UTC](https://community.thunkable.com/t/wdc-24-lets-play-mastermind/1538130/36 "2021-10-06T07:49:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![codeswept](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/codeswept/32/87755_2.png) [@codeswept](https://community.thunkable.com/u/codeswept)\
**Post date:** [October 6, 2021, 7:59am UTC](https://community.thunkable.com/t/wdc-24-lets-play-mastermind/1538130/37 "2021-10-06T07:59:04Z")

</div>

> [@muneer](#):
>
> 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.

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

---

<div class="post-metadata">

**Author:** ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)\
**Post date:** [October 6, 2021, 8:09am UTC](https://community.thunkable.com/t/wdc-24-lets-play-mastermind/1538130/38 "2021-10-06T08:09:44Z")

</div>

Stage 1

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/c/7/c7c410dc14d08bad2411b4f7c6b45c251af0a1ff.png)

Stage 2

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/a/4/a494798aa28ad08adc2d7678c0b298bc51abdb6e.png)

Show results

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/2/4/24864d0c70780143f5873c8da917b165e155e617.png)

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.

---

<div class="post-metadata">

**Author:** ![manyone](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@manyone](https://community.thunkable.com/u/manyone)\
**Post date:** [October 6, 2021, 4:37pm UTC](https://community.thunkable.com/t/wdc-24-lets-play-mastermind/1538130/39 "2021-10-06T16:37:00Z")

</div>

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](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/1/d/1d41b17830b210a107d9b8a91b20a250dea56db3.png)

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.

```auto
  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.

---

<div class="post-metadata">

**Author:** ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)\
**Post date:** [October 6, 2021, 5:42pm UTC](https://community.thunkable.com/t/wdc-24-lets-play-mastermind/1538130/40 "2021-10-06T17:42:18Z")

</div>

> [@manyone](#):
>
> you can simulate them using regular arrays but you have to keep track of mapping color values to index values.

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.

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [October 6, 2021, 5:58pm UTC](https://community.thunkable.com/t/wdc-24-lets-play-mastermind/1538130/41 "2021-10-06T17:58:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [October 6, 2021, 9:36pm UTC](https://community.thunkable.com/t/wdc-24-lets-play-mastermind/1538130/42 "2021-10-06T21:36:29Z")

</div>

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! 🕶

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

[![](https://img.youtube.com/vi/URIQUsvCGlo/hqdefault.jpg "WDC #24 Demo (in progress)") ](https://www.youtube.com/watch?v=URIQUsvCGlo)

(No sound)

[Previous page](https://community.thunkable.com/t/wdc-24-lets-play-mastermind/1538130.md?page=1)

[Next page](https://community.thunkable.com/t/wdc-24-lets-play-mastermind/1538130.md?page=3)
