05-10-2020 02:52 AM
Hello everyone,
In this quarintine I´ve developed a snake game code in Labview and I would like you to tell me what do you think about it? How can I improve it?
Thank you
Wait for your reply
Solved! Go to Solution.
05-10-2020 03:46 AM
How do you play it?
I felt the game was very slow to respond to my button presses. Sometimes not responding at all.
05-10-2020 12:34 PM
Hi alhebu,
@alhebu wrote:
How can I improve it? Wait for your reply
Why is there a 1000ms wait function in parallel to your event structure with a 100ms timeout event?
Your "tablero 2" arrays shows the result of the last iteration instead of showing the result of the current iteration…
Why do all your controls have a " 2" in their label?
05-10-2020 11:36 PM - edited 05-10-2020 11:57 PM
Great first effort! Congratulations! 😄
Now try to redo it with cleaner and less code. Some ideas:
See ow far you get!
05-11-2020 01:37 AM
Thank you for the second line 😄
05-11-2020 02:10 AM
Thank you for your reply! 😄
1.But if I would like to use the cursor keys I would use an event structure right?
2.Okay so I would have to write some code in order to get to a winning message if there´s no enough space for a red field right? Or why is it risky? Should I change this part?
3. I don´t understand... could you explain why not ocurr at the same probability?
4. Okay, I understand, LabView is slower if I insert and delete it many times right? Or just for do a cleaner code?
5. ...
6, 7, 8. I´ll do it thank you!
Thank you for taking some time to check my code and I would be grateful if you help me with my questions 😄
05-11-2020 02:17 AM - edited 05-11-2020 02:22 AM
Hi alhebu,
@alhebu wrote:
Thank you for your reply! 😄
1.But if I would like to use the cursor keys I would use an event structure right?
2.Okay so I would have to write some code in order to get to a winning message if there´s no enough space for a red field right? Or why is it risky? Should I change this part?
3. I don´t understand... could you explain why not ocurr at the same probability?
4. Okay, I understand, LabView is slower if I insert and delete it many times right? Or just for do a cleaner code?
5. ...
6, 7, 8. I´ll do it thank you!
Thank you for taking some time to check my code and I would be grateful if you help me with my questions 😄
1. Yes.
2. It's risky because your code may end up in a loop running forever: bad UX for the players…
3. Because the RandomNumber function outputs the numbers within a certain range. And there are certain rounding rules applied when converting from DBL to I32…
4. Cleaner code (most often) results in less buggy code: why do you even need to delete/insert when you can replace?
Ideas on "simpler code":
Why do you need 2 comparisons and an OR function to check the postion when there is a CoerceAndInRange function doing the same operation?
Why do you need to duplicate that check for the other coordinate? (To reuse code you either use subVIs or a loop…)
This is how my Snake game looks like:
It uses an event structure to catch key down events, like cursor keys…
05-11-2020 12:45 PM
@alhebu wrote:
3. I don´t understand... could you explain why not ocurr at the same probability?
Because you are rounding to the nearest index, so e.g. 0 occurs for values between 0 and 0.5, while 1 occurs for values between 0.5 and 1.5, a range twice as wide! Correct is to multiply by 11 and round down towards the next lowest integer. Now 0 occurs for values 0..1, 1 occurs for values 1..2, etc. All ranges have the same width! Note that the random number is never exactly 0 or 1, so you don't need to worry about rare edge effects.
Here's a quick demo. Note that since we are in 2D, edges get half and corners only a quarter with your code. You'll never get a job working for a Vegas Casino if your random numbers are biased. 😄
05-11-2020 12:57 PM
Gerd already answered most points. Here's some additional info:
05-15-2020 07:41 PM
Heeeeeyyyy,
I don´t know if have to open a new to topic because I already chose one answer as a solution and my question is litle bit different about what we were talking about...
I´ve added the things you told me to my code and now I have subvi´s and a type defeinition for my data cluster and my question is... How do I send my code to other person... I mean Is there anyway in wich I just send, I don´t know... just the Labview project and all the subvis goes with it? Do I have to send always my code and all the subvi´s?