09-07-2019 03:01 PM
How do I write a program to play rock paper scissors game? The specifications are to use a random number generator (between 0-1) and when the random number is <= 0.33 the word ROCK will be displayed. When the random number is between 0.34 and 0.67, the word PAPER will be displayed, and then when the random number is between .68 and 1, the word SCISSORS will be displayed.
09-07-2019 03:58 PM
Have you programmed in LabVIEW before? If not, take the tutorials.
LabVIEW Introduction Course - Three Hours
Learn LabVIEW
Sit down and make a flowchart or some pseudocode on a piece of paper to get started on the programming logic.
Look through the LabVIEW palettes for the functions you need (e.g., random number, case structure, comparisons. Perhaps threshold array.) I would recommend you multiply the random number of 0-1 by three. Round down. Then use that to index an array with the 3 words.)
09-07-2019 08:57 PM
There are two ways to produce programs.
If you want to try the first of these methods, do some learning (Tutorials can be found at the beginning of this Forum, or by doing a Web search), try some examples (like coding a Rock/Paper/Scissors game), and when/if you get stuck, post your code (your .VI files) and ask for help.
Bob Schor
09-09-2019 07:59 PM
Hi, have you figured this out yet? I am also trying to solve this.
09-10-2019 07:36 AM - edited 09-10-2019 07:38 AM
See my previous response. If you are unwilling to do the work required to learn the subject, drop the course. A slightly less drastic move is to go to one of your classmates to "seems to get it" and ask them for help -- if you are lucky, they will teach you what you need to know (as opposed to letting you "copy their answers").
Bob Schor
09-10-2019 10:27 AM
@spikycactus6 wrote:
Hi, have you figured this out yet? I am also trying to solve this.
Ah, school has started again. It's that time of year.
09-10-2019 10:52 AM
@abcd123478 wrote:
How do I write a program to play rock paper scissors game? The specifications are to use a random number generator (between 0-1) and when the random number is <= 0.33 the word ROCK will be displayed. When the random number is between 0.34 and 0.67, the word PAPER will be displayed, and then when the random number is between .68 and 1, the word SCISSORS will be displayed.
Random numbers have significantly more than two decimal digits. What should happen if the random number is between 0.33 ..0.34 or between 0.67..0.68?
Maybe one of these two ranges can be lizard and one spock?
09-10-2019 11:46 AM
So there are a few things you should do when creating this game that should make your life easier....
1. as an extension to altenbach, the random number generator can be quite precise.... I recommend multiplying the random number by 3, and using the round down function to always get either a 0,1,2.
2. you can then wire this integer value to a case structure which will let you execute code based on what you have in your hand.... (ie, if you have a 1, which is paper, and enemy has a 2 which is rock, output win, if they have a 1, output tie, if they have a 0, output lose - this should be a case structure aswell). This will allow you to have 9 unique cases representing every combination of your hand and theirs.....
This all means you need 2 random number generators... 1 for you, and 1 for opponent.... and 2 case structures...
I have gone ahead and included .png with a basic idea of how you would wire the first case structure... and ill let you figure out the second 🙂
09-10-2019 11:56 AM
@Jewsus wrote:
. I recommend multiplying the random number by 3,...
Ravens already suggested that. And you definitely don't need any case structures. 🙂
09-10-2019 12:02 PM
LOL, 24 and i'm already blind. Sorry Raven.
And yea, I was overcomplicating it, using the random number as the index in the string array containing the 3 options is way cleaner... I don't know why I didn't think of that... I guess I'm to used to arrays being just numbers....