Jump to content
Science Forums

Rock Paper Scissors To The Max


Recommended Posts

your mission, should you chose to accept it, is to write a program that plays a non random game of rock paper scissors.

you will be given three things, your previous set of moves a[], your opponents set of moves b[], and the current round i.

each coder can submit up to three programs. once again however, no random functions are allowed. in short, your program should play the same set of moves against the same opponent. i will be hosting the contest in java, but you can write in any language you wish, just provide a description of what yours does.

here are some example programs.

int rotate(int a[], int b[], int i){
  return i%3;
}

this one just goes through the three moves in order.

 

int beatUsed(int a[], int b[], int i){
  int[] moves;
  int max = 0, index;
  if(i == 0)  return ROCK;
  moves = new int[3]
  for(j = 0; j<i; j++){
     moves[b[j]]++;
  }
  for(j= 0; j< 3; j++){
     if(moves[j] > max){
        max = moves[j]
        index = j
     }
  }
  return (moves[index]+1)%3;
}

this one plays the move that beats the move the opponent has used the most.

 

and here is my first submission.

int sqFree(int a[], int b[], int i){
  int[] moves;
  int index = 0;
  if(i==0) return PAPER;
  moves = new int[i*3];
  for(j = 0; j< i; j++){
      if(b[j] == 0){
        moves[index] = 1
        moves[index+1] = 2
        index = index +2
     }
     if(b[j] == 1){
        moves[index] = 1
        moves[index+1] = 0
        moves[index+2] = 2
        index += 3
    }
    if(b[j] == 2){
        moves[index] = 0
        index += 1
    }
 }
 return moves[int(index/2)];
}

this program uses the square free substitution rules to try to respond to my opponent without being predictable.

note that most programs will need a static first move.

Link to comment
Share on other sites

  • 4 weeks later...

your playing against other human non random algorithms. everyone will have code that generates rock or 0, paper or 1, and scissors or 2, based on what they think their opponent's next move will be. you have your opponents previous set of moves and your own set of moves to work with.

basically your goal is to do three things. predict what your opponent's algorithm is, play moves that beat it, and try to remain unpredictable yourself.

but the primary point is to have fun! :-)

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...
×
×
  • Create New...