|
-
December 30th, 2010, 12:11 AM
#1
Rock, ..., Spock Random Numbers
Hello,
I wrote a Rock, Paper, Scissors, Lizard, Spock program in Haskell for my last project in a class. Haskell allows you to take a certain input and actually manually specify the answer for that particular input. So, what I wound up doing is keeping track of how many times the user chose rock, paper, etc. If the user chose them an equal amount of times I generated a character list with all choices and had the computer choose from that list. If the user chose say rock the most, I then had the computer choose from a list of the other options. I can post the Haskell code if you like... but I am ultimately trying to convert this into a c++ program.
I am running into a...road block when it comes down to the algorithm. Ultimately I may have to do some hack like I did in Haskell, but I think there should be a better way. Since there are five options I am using srand() and rand() to generate the random numbers. However, I want this generation to change depending on the choice count. So, if we have:
Rock = 3
Paper = 2
Scissors = 3
Lizard = 5
Spock = 4
It will see that the user has selected the Lizard the most and remove that option from its set of choices. Ideally, if that number becomes so large then it will choose from one of the two options that are guaranteed to beat Lizard, etc. If two options are maxed out then it should choose from the remaining three. If three or more options have been chosen an equal number of time, then it defaults to picking from the entire set.
Right now I have it find the maximum value in vector of ints. Then I iterate through that same vector in order to create another vector which contains a 1 in all the places the maximum value appears. At this point I have a vector that might contain [0,1,0,0,1]. The 0 index corresponds to Rock and 4 corresponds to Spock. The problem becomes choosing from the remaining options. If you need concrete code I can post it. Then again, I may decide to opt for a function which will return a string. The string would correspond to the set of appropriate options.
I know this is long. I can post some code if you would like. But for now, I am going to go to bed. Thanks for any help/ideas.
Edit: I believe I have figured out a solution to this. Guess I posted too soon.
Last edited by Alterah; December 30th, 2010 at 08:16 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|