Jump to content
BrainDen.com - Brain Teasers
  • 0


Guest
 Share

Question

rock breaks scissors and crushes lizard.

paper covers rock and disproves spock.

scissors cut paper and severs lizard.

spock disintegrates rock and disassembles scissors.

lizard poisons spock and eats paper.

you goal is to write a non-random algorithm that will compete against other such algorithms in a game of rock paper scissors lizard spock.

you will be given all the moves you have played so far ( a[] ) along with all your opponents moves ( b[] ), and the round you are currently on ( i ). the player who wins the most rounds will get 1 point. the player with the most points at the end of the tournament wins!

some example programs:


cycle(int a[],int b[],int i){

   return i%5;

}

this program just goes through the 5 choices in order.

titForTat(int a[],int b[], int i){

   if (i == 0) return SPOCK;

   return b[i-1];

plays spock for the first move, after that simply plays opponents previous move. (note: most programs will require a static first move.)

pseudoRandom(int a[],int b[], int i){

   if (i == 0)  return SCISSORS;

   total = 0;

   for(int j = 0; j<i; j++){

      total += a[j] +b[j]

   }

   return total%5;

this program doesn't try to do anything fancy, just take the total of all the previous moves and use that to play a "random" move.

any questions feel free to ask. note that you don't actually need coding skills just a description of what you want it to do will be fine.

Edited by phillip1882
Link to comment
Share on other sites

11 answers to this question

Recommended Posts

  • 0

I have no experience with ANY programming at all, so I'll just be random.

With

1-Rock

2-Paper

3-Scissors

4-Spock

5-Lizard

This is my order for the first 10 sequences.

3,3,5,3,2,2,4,4,3,1

Then you repeat, but starting with the second 3, making it

3,5,3,2,2,4,4,3,1,3.

Link to comment
Share on other sites

  • 0

so here's my first submission


if (algoNum == 1){

       int[] winarr, lossarr;

       int temp, max = 0, min = 1000, index, index2;

       if (i == 0) return SPOCK;

       if (i == 1) return SCISSORS;

       if (i == 2) return ROCK;

       if (i == 3) return LIZARD;

       if (i == 4) return PAPER;

       winarr = new int[5];

       lossarr = new int[5];

       for(int j = 0; j<i; j++){

          temp = (5 +a[j] -b[j])%5;

          if(temp >0){

             if(temp%2 == 1){

               winarr[a[j]] += 1;

             }

             else{

               lossarr[a[j]] += 1;

             }

          }

       }

       for(int j = 0, j<5; j++){

          if (winarr[j] > max){

             index1 = j;

             max = winarr[j];

          }

          if (lossarr[j] < min){

             index2 = j;

             min = lossarr[j];

          }

      }

      temp = (5 +a[i-1] +b[i-1])%5;

      if(temp%2 == 1) return index1;

      else  return index2;

   } 

and here would be the code for filly678:

if (algoNum == 0){

       int[] array= {2,4,2,1,1,3,3,2,0};

       if(i ==0) return 2;

       return array[(i-1)%10];

}

Edited by phillip1882
Link to comment
Share on other sites

  • 0


klose(int a[], int b[], int i)

{


int[] cownter={0,0,0,0,0};

int bigeset=0;


if (i==0) return (int)(Math.random()*5) //needs import java.lang.Math.*


for (int klo=0; klo<i; klo++)

{

   if (b[klo]==0) cownter[0]++;

   if (b[klo]==1) cownter[1]++;

   if (b[klo]==2) cownter[2]++;

   if (b[klo]==3) cownter[3]++;

   if (b[klo]==4) cownter[4]++;

}


for (int klo=0; klo<5; klo++)

   if (cownter[klo]>bigeset) bigeset=cownter[klo];


return (bigeset+(int)(Math.random()*2)*2+2)%5;

}

my javas not working so i have no idea if this works, but the main idea was to start with a random number then find out which number the other person has played the most and beat it. im not really sure what number corresponds to what play so i assumed that a number is beaten by one either 2 or 4 greater than it.

Link to comment
Share on other sites

  • 0

sorry! no random functions allowed!

you can do something pseudo random like calculate pi to some decimal place and use that digit somehow, but the random function itself is off limits. basically your code should play the exact same moves against the same opponent every time.

you are indeed correct though, +2 and +4 wins every time.

Link to comment
Share on other sites

  • 0

sorry! no random functions allowed!

whoops! sorry about that. here is my new code:


klose(int a[], int b[], int i)

{


int[] cownter={0,0,0,0,0};

int bigeset=0;


if (i==0) return (int)(5*(1-1.0/6+1.0/120-1.0/5040); // this should be ~ 5sin(1)


for (int klo=0; klo<i; klo++)

{

   if (b[klo]==0) cownter[0]++;

   if (b[klo]==1) cownter[1]++;

   if (b[klo]==2) cownter[2]++;

   if (b[klo]==3) cownter[3]++;

   if (b[klo]==4) cownter[4]++;

}


for (int klo=0; klo<5; klo++)

   if (cownter[klo]>bigeset) bigeset=cownter[klo];


return (bigeset+(i%2)*2+2)%5;

}

Link to comment
Share on other sites

  • 0

okay your code is entered in. i made a small correction, think you want to play the move that beats the most used move, not play the move that beats how many times the most used move is used.

Link to comment
Share on other sites

  • 0

alright we have results, since it doesn't look like we're gonna get any more submissions.

filly678 vs phillip1882: filly678 wins!

filly678 vs klose: filly678 wins!

phillip1882 vs klose: phillip1882 wins!

well, thanks to those who participated.

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
Answer this question...

×   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...