LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Rock Paper Scissors game

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.

0 Kudos
Message 1 of 15
(3,227 Views)

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.)

0 Kudos
Message 2 of 15
(3,193 Views)

There are two ways to produce programs.

  1. Learn a programming language (such as LabVIEW) and hone your skills by writing programs.  While one can theoretically "learn" a language from a book or in a classroom, until you actually write (and try to execute) programs, you won't really produce much useful code.
  2. Pay someone who has spent the time to acquire programming skills to produce programs for you.

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

0 Kudos
Message 3 of 15
(3,162 Views)

Hi, have you figured this out yet? I am also trying to solve this. 

0 Kudos
Message 4 of 15
(3,053 Views)

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

0 Kudos
Message 5 of 15
(3,011 Views)

@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.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 6 of 15
(2,988 Views)

@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?

 

lizard.png

0 Kudos
Message 7 of 15
(2,975 Views)

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 🙂

0 Kudos
Message 8 of 15
(2,958 Views)

@Jewsus wrote:

. I recommend multiplying the random number by 3,...


Ravens already suggested that. And you definitely don't need any case structures. 🙂

0 Kudos
Message 9 of 15
(2,952 Views)

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

0 Kudos
Message 10 of 15
(2,949 Views)