From Saturday, Nov 23rd 7:00 PM CST - Sunday, Nov 24th 7:45 AM CST, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW Digest Programming Challenges

cancel
Showing results for 
Search instead for 
Did you mean: 

LabVIEW Digest Challenge 4

Coding Challenge 4 - The Memory Game

 

Email your entries to LabVIEWDigestCompetition@ni.com

Deadline - 26th January 2018

 

This challenge asks you to build a simple memory game. On the VI there is a colour box indicator. Your task is to have it display a growing series of random colours. So we start by displaying one colour, the user inputs the colour using the controls. Then we display the first colour again but add another random colour to the sequence, the user inputs the two colours of the sequence. Then we add a third colour and so on. 

 

 

Front Panel.png

 

 

The program should:

 

  • Display the colour sequence at a rate of 500ms (first one colour, then two, then 3 etc)
  • Allow the user to type the colour sequence in using the provided buttons
  • Display a dialog to the user to say whether they are correct or not
  • If they are correct, add another colour to the end of the sequence
  • If they’re wrong, restart the game

 

Please use one of the attached VIs.

 

I have included an NXG version but colour box constants are not in NXG 1.0 so I have used words instead. The same coding is required, but you display the names of colours, not the actual colour.

 

 

Please note the competition is only open to LabVIEW users in Europe, Middle East, India and Africa. 

Competition Rules

 

 

 

Good luck,

Charlotte

 

Download All
Message 1 of 12
(13,596 Views)

Yes, I will participate, but I will stay out of the challenge, I don't want to win again 😉

Message 2 of 12
(13,554 Views)

For some reason, despite subscribing, I'm not getting notifications. Did I miss the deadline for this competition?

Thoric (CLA, CLED, CTD and LabVIEW Champion)


0 Kudos
Message 3 of 12
(13,339 Views)

Hey, 

 

thanks for reminding me about the deadline. I put it in my calendar but not in the post for some reason! It's the 26th January and it's in the post now. 

 

So definitely still plenty of time.


I've also noticed notifications not working as I didn't see Phil's comment until I actually came back to the post. 😐 Hopefully that's a temporary thing, I'll flag it up with the web team. 

 

Thanks,

Charlotte

0 Kudos
Message 4 of 12
(13,327 Views)

Hi Charlotte,

Thanks for this new challenge, it seems a little bit more difficult than the previous, but I prefer like this 🙂
I have a question: what do you mean about the fail message "the correct color was XXXX"?
XXXX represent all the colors of the test (in string like Blue, Green ...)? Only the first failed color? The latest color of the test?
Thanks 😉

0 Kudos
Message 5 of 12
(13,206 Views)

Yeah, I thought I'd try and switch between a simple challenge and more of a full application every other time now. As I think it's nice to sometimes think about the structure a bit more, than just develop and algorithm. 

 

So the XXXX should be replaced with whatever colour the person failed at. So yes, the first failed colour. 

 

So if the sequence is Blue, Red, Black and I entered Blue, Green the program should stop the game as soon as I got it wrong and display the message 'the correct colour was Red'.


I hope that makes more sense. 

 

Thanks,

Charlotte

0 Kudos
Message 6 of 12
(13,161 Views)

Hi everybody, 

 

I hope you my best wishes for this new year Smiley Wink

and I sent my code for this challenge!
Bye.
Phil

0 Kudos
Message 7 of 12
(12,858 Views)

Hello All,

 

I have also sent my code long back.

 

Thanks

0 Kudos
Message 8 of 12
(12,537 Views)

Hi Everyone, 

 

Thank you to everyone that joined in with this challenge! This one was definitely a bit harder than some of the others as I saw a lot of entries that almost worked but didn't quite. 

 

This challenge's winner is user HugoPaul! They had one of the easiest to understand solutions I saw and it was very nicely documented. I believe they're looking to take their CLD so the good documentation practices will come in handy. 

The winning code is attached below as I realise the block diagram is hard to see in the images

Winning block diagramWinning block diagramProof it worksProof it works

 

Key Point of Feedback:

Many solutions relied on a lot of local variables in state machines. Local variables can lead to race conditions which are hard to debug but can cause errors in your code.

 

Now you should be fine in a state machine as things don't happen in parallel which is where race conditions become likely. But it's really great practice to not use local variables when you don't have to. Even if you get lucky and never have a race condition, it's a lot easier to debug your code when you have wires updating the UI.

 

Ways to avoid using them in a state machine include only updating an indicator from one state, or updating the indicators after the case structure. Does anyone have other ways to deal with this? 


There's a tutorial on race conditions here. 

 

A way of updating an indicator in multiple states without local variablesA way of updating an indicator in multiple states without local variables

 

 

 

Interesting Solution

One of the issues with the UI I designed is that it was hard to tell if the same colour came up twice in a row. Thoric had a great solution to this by adding some fancy transitions! Code attached if you want to understand how it works!

 

test.gif

 

 

 

 

 

Message 9 of 12
(12,295 Views)

Hi Charlotte,

 

when is the next challenge. Is it open for devleopers in india?

 

Thanks,

Bharath

Thanks & Regards,
Bharath Kumar
GCentral
0 Kudos
Message 10 of 12
(11,876 Views)