Rock Paper Scissors Lizard Spock

5 posts in this topic

Posted · Report post

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!

0

Share this post


Link to post
Share on other sites

Posted (edited) · Report post

#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
0

Share this post


Link to post
Share on other sites

Posted · Report post

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.

0

Share this post


Link to post
Share on other sites

Posted · Report post

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]

0

Share this post


Link to post
Share on other sites

Posted · Report post

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]

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.