Jump to content
BrainDen.com - Brain Teasers

Rock Paper Scissors Lizard Spock


phil1882
 Share

Recommended Posts

I've always thought that the rock paper scissors programming contest hosted by bonanova was one of the funnest.

I've tried this contest before without much success here, but i would like to try one more time before giving up.

the goal is the following. write a program that plays rock paper scissors lizard spock against another such program.

each program will receive as input all it's previous moves, all opponents previous moves, and the round number. the only "strict" rule is no random functions. you are of course allowed to write pseudo random number generators if you really want,

but most code submissions should hopefully be deterministic.

if you aren't much of a programmer, you may submit to me your general idea and ill try to code it for you.

here would be some example programs:

def only_rock(my[],op[],i):

return ROCK

def rotate_moves(my[],op[].i):

return i%5

def beat_previous(my[],op[],i):

if i == 0:

return PAPER

else:

return (op[i-1]+2)%5

you may of course write as complicated or as simple programs as you desire. may the best coder win!

Link to comment
Share on other sites

#include <iostream>
#include <ctype.h>
#define EVER ;;

using namespace std;

int main ()
{
enum GameOptions { ROCK, PAPER, SCISSORS };
char myChoice, playAgain;
int compChoice;
bool shouldQuit = false;

for(EVER)
{
if (shouldQuit)
break;
{
cout << "Pick your weapon [R]ock [P]aper cissors or [Q]uit: ";
cin >> myChoice;
myChoice = tolower(myChoice);
compChoice = rand() % 3;

if (myChoice == 'q')
{
shouldQuit = true;
break;
}

switch(compChoice)
{
case ROCK:
if (myChoice == 'r')
cout << "Computer chose 'ROCK'... it's a tie" << endl;
if (myChoice == 'p')
cout << "Computer chose 'ROCK'... you win" << endl;
if (myChoice == 's')
cout << "Computer chose 'ROCK'... you lose" << endl;
break;
case PAPER:
if (myChoice == 'r')
cout << "Computer chose 'PAPER'... you lose" << endl;
if (myChoice == 'p')
cout << "Computer chose 'PAPER'... it's a tie" << endl;
if (myChoice == 's')
cout << "Computer chose 'PAPER'... you win" << endl;
break;
case SCISSORS:
if (myChoice == 'r')
cout << "Computer chose 'SCISSORS'... you win" << endl;
if (myChoice == 'p')
cout << "Computer chose 'SCISSORS'... you lose" << endl;
if (myChoice == 's')
cout << "Computer chose 'SCISSORS'... it's a tie" << endl;
break;
default:
cout << "ERROR: Please try again";
break;
}

cout << "Would you like to play again (y or n): ";
cin >> playAgain;
playAgain = tolower(playAgain);

switch(playAgain)
{
case 'y':
system("CLS");
break;
case 'n':
shouldQuit = true;
break;
default:
cout << "Invalid choice! Restarting game...";
system("CLS");
break;
}
}
}

my code relies on the user to input their move then mine tells what it plays.

Edited by BMAD
Link to comment
Share on other sites

CMAD, this is completely unnecessary, i already have the tournament code.

your objective is to write a code that plays ROCK PAPER SCISSORS LIZARD SPOCK.

note that random functions are not allowed.

and you won't be competing against a computer, you'll be competing against other programs. written by other people.

so for example someone may write the beat previous move program i have as an example above. so you want to try to write code that will beat as many deterministic ROCK PAPER SCISSORS LIZARD SPOCK players as possible.

Link to comment
Share on other sites

here's my code for the tourney, written in python.

ROCK = 0
PAPER = 4
SCISSORS = 3
SPOCK = 2
LIZARD = 1

def program1(my,op,i):
   pass
def program2(my,op,i):
   pass

names = ["program1","program2"]
victories = [0]*len(names)
for i in range(0,len(names)-1):
   for j in range(i+1,len(names)):
      player1 = []
      player2 = []
      victory1 = 0
      victory2 = 0
      for k in range(0,50):
         move1 = eval(names[i]+"(player1,player2,"+str(k)+")")
         move2 = eval(names[j]+"(player2,player1,"+str(k)+")")
         player1 += [move1]
         player2 += [move2]
         if move1 -move2 == 0:
            victory1 += 0.5
            victory2 += 0.5
         elif (move1 -move2 +5)%2 == 1:
            victory1 += 1
         else:
            victory2 += 1
      if victory1 > 2.5 +victory2:
         victories[i] += 1
      elif victory1 < victory2 -2.5:
         victories[j] += 1
      else:
         victories[i] += 0.5
         victories[j] += 0.5
for i in range(0,len(names)):
   print names[i],victories[i]

Link to comment
Share on other sites

edit:

slight code correction.

ROCK = 0
PAPER = 4
SCISSORS = 3
SPOCK = 2
LIZARD = 1

def program1(my,op,i):
   pass
def program2(my,op,i):
   pass

names = ["program1","program2"]
victories = [0]*len(names)
for i in range(0,len(names)-1):
   for j in range(i+1,len(names)):
      player1 = []
      player2 = []
      victory1 = 0
      victory2 = 0
      for k in range(0,50):
         move1 = eval(names[i]+"(player1,player2,"+str(k)+")")
         move2 = eval(names[j]+"(player2,player1,"+str(k)+")")
         player1 += [move1]
         player2 += [move2]
         if move1 -move2 == 0:
            victory1 += 0.5
            victory2 += 0.5
         elif ((move1 -move2 +5)%5)%2 == 0:
            victory1 += 1
         else:
            victory2 += 1
      if victory1 > 2.5 +victory2:
         victories[i] += 1
      elif victory1 < victory2 -2.5:
         victories[j] += 1
      else:
         victories[i] += 0.5
         victories[j] += 0.5
for i in range(0,len(names)):
   print names[i],victories[i]

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...