Rock Paper Scissors Game

This is a discussion on Rock Paper Scissors Game within the C++ Programming forums, part of the General Programming Boards category; I am currently trying to make like a text based rock paper scissors game and i need to find a ...

  1. #1
    Registered User
    Join Date
    Jun 2007
    Posts
    24

    Rock Paper Scissors Game

    I am currently trying to make like a text based rock paper scissors game and i need to find a way to make my computer do a random order of three numbers each to equal rock paper or scissors

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,485
    See the FAQ ?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Jun 2007
    Posts
    24
    just checked nothing about a random pattern

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,594
    Just checked and found How do I... Generate random numbers?

    Additionally, take a look at:
    Using rand()
    Random Numbers Tutorial
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Jun 2007
    Posts
    24
    Quote Originally Posted by laserlight View Post
    Just checked and found How do I... Generate random numbers?

    Additionally, take a look at:
    Using rand()
    Random Numbers Tutorial
    but i need to get the numbers 1 2 and 3 in random order I don't need random numbers

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,485
    Oh, you mean a "shuffle" - rearrange a set of things into a random order, like one would do for a deck of cards.

    Search the board, there are some examples of that.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  7. #7
    Registered User
    Join Date
    Jun 2007
    Posts
    24
    yeah a shuffle

  8. #8
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    Add the three numbers to your array/vector and call random_shuffle.

    In this case, since there are only three numbers, you can also use rand. Just pick a random number in the range [1,3] and let that be first, then pick another random number. If it is even switch the order of the two leftover numbers.

  9. #9
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    902
    Besides, wouldn't the possibility of the computer opponent repeating a throw be integral? One could easily figure out that the computer will throw all three in three moves, and gain a statistical advantage.
    Consider just making each of the computer's moves random.
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  10. #10
    Registered User
    Join Date
    Jun 2007
    Posts
    24
    Quote Originally Posted by Daved View Post
    Add the three numbers to your array/vector and call random_shuffle.
    Ummm........ I'm not that good with arrays and or vectors is there somewhere online I could learn about them

  11. #11
    Registered User
    Join Date
    Dec 2005
    Location
    Canada
    Posts
    267

    OS: Windows 7, XUbuntu 11.10, Arch Linux
    IDE: CodeBlocks
    Compiler: GCC

  12. #12
    Registered User
    Join Date
    Jun 2007
    Posts
    24
    ty for the help


    but I still cant figure out what rand or random_shuffle has to do with arrays and or vectors

    i mean for rand you don't even need arrays do u?
    Last edited by tbca; 07-08-2007 at 08:14 AM.

  13. #13
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    What did you ding when you looked up random_shuffle? There should be examples. It is simple to use, for an array:
    Code:
    random_shuffle(arr, arr+size);
    For a vector:
    Code:
    random_shuffle(vec.begin(), vec.end());
    Depending on your platform you might have to call srand() once at the start of your program just like if you use rand().

    >> i mean for rand you don't even need arrays do u?
    You don't need an array if you only have three values. The point of using an array or vector as well as random_shuffle is that those solutions scale to larger problems. For three values it is overkill, we are mostly just giving solutions assuming the point is to learn how to do it for bigger problems.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. paper rock scissors
    By Amyaayaa in forum C++ Programming
    Replies: 4
    Last Post: 02-12-2008, 09:59 AM
  2. my upcoming UNO card game :)
    By Hussain Hani in forum Game Programming
    Replies: 5
    Last Post: 01-24-2008, 12:19 AM
  3. Please comment on my c++ game
    By MegaManZZ in forum Game Programming
    Replies: 10
    Last Post: 01-22-2008, 10:03 AM
  4. Replies: 8
    Last Post: 10-24-2007, 05:46 PM
  5. need help with rock paper scissors program
    By Mshock in forum C Programming
    Replies: 3
    Last Post: 04-22-2006, 07:44 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21