Alice Community  

Go Back   Alice Community > Alice 2 > How do I...?

Reply
 
Thread Tools Display Modes
compare user input to a randomly generated computer action?
Old
LadyReyna
Guest
 
Status:
Posts: n/a
Red face compare user input to a randomly generated computer action? - 05-19-2010, 12:37 PM

My students are creating a user v. computer game or Paper, Rock, Scissors. They have everything done and working except a scoreboard. They are trying to create the code to compare user input (P,R,S) to what action the computer chose to take. (They have the computer randomly choose between a method of paper, rock, or scissors). Once they get the comparison, they know how to generate the score...it is just this comparison that is sticking them. As I am a new Alice user myself, this is one problem I have not been able to help them solve. Any help you can provide would be greatly appreciated.

Things they have tried:
If/else with a and b true, a being the user input using a string parameter, and b trying to make it the computers choice, but can not figure out HOW.
   
Reply With Quote
Old
x2495iiii
Super Moderator
 
x2495iiii's Avatar
 
Status: Offline
Posts: 3,508
Join Date: Dec 2008
Location: Somewhere in the Continental U.S.
Default 05-19-2010, 12:51 PM

Did you say you made two string variables holding the value of both the user and the computer input? If so, good, that's the first step. The second step is comparing them with a nested if/else if statement that looks something like this

(assuming the string variables for the input of the user and computer are named userChoice and compChioce respectively)

If userChoice == Rock
{If compChoice == Rock
[Tie Game, do it over]
Else If compChoice == Paper
[Computer Wins]
Else User Wins}
Else If userChoice == Paper
(etc.)


(')>
   
Reply With Quote
Thank you....
Old
LadyReyna
Guest
 
Status:
Posts: n/a
Default Thank you.... - 05-19-2010, 01:02 PM

they are getting ready to try it right now. They were using a parameter instead of a variable....I may be back for more help, depending how this goes.
   
Reply With Quote
Old
x2495iiii
Super Moderator
 
x2495iiii's Avatar
 
Status: Offline
Posts: 3,508
Join Date: Dec 2008
Location: Somewhere in the Continental U.S.
Default 05-19-2010, 01:06 PM

I have to leave for work in 30 minutes, so if there's a problem, I may not be able to answer back immediately. Apologies.


(')>
   
Reply With Quote
Still hitting the same wall...
Old
LadyReyna
Guest
 
Status:
Posts: n/a
Default Still hitting the same wall... - 05-19-2010, 01:08 PM

the computer does not generate a string, it just runs a method (rock, paper, or scissors) that makes the arm move. Do they need to have the method generate a string? (And how??) OR is there a way to make the variable accept that a choosen method is the input?? I have attached their most current copy of the file. It is very rough, but this is the first forray into interactive programming for all of them.
Attached Files
File Type: a2w Q4P2 Final.a2w (905.4 KB, 10 views)
   
Reply With Quote
Old
x2495iiii
Super Moderator
 
x2495iiii's Avatar
 
Status: Offline
Posts: 3,508
Join Date: Dec 2008
Location: Somewhere in the Continental U.S.
Default 05-19-2010, 01:30 PM

Here you go. I made the first part of the code I mentioned (it could be a bit more polished, but i was pressed for time). Choose Rock to see what I mean. The rest of the code, along with the scoring, is up to you.
Attached Files
File Type: a2w Q4P2 FinalMOD.a2w (877.6 KB, 14 views)


(')>
   
Reply With Quote
Reply

Tags
compare two choices, scoreboard, student project, using a and b function

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



Copyright ©2021, Carnegie Mellon University
Alice 2.x © 1999-2012, Alice 3.x © 2008-2012, Carnegie Mellon University. All rights reserved.