Hey guys, this is my first post here and I need a lot of help. I'd like to start off by saying that I'm VERY new to this so I might have some really obvious errors in here/my code might not make sense(i hope this is not the case) and yes I have added some comments to help you guys help me. :D
I'm in a]Computer Science class at my high school and we are supposed to make a game of Rock Paper Scissors that has some form of computer AI in it. The only rules are that it must:
1) Have some form of AI
2) In 4 turns, you must have used at least one of every option (Rock Paper or Scissors)
If it violates this rule, there is a # of points penalty taken away.
Here's what my thought process is:
1) Have two parallel arrays. One will be the computer's input and the other will be the
User's input. The arrays will be int arrays with 4 slots. With each choice a value
will be given.(Rock=1,Paper=3,Scissors=9)
2) The computer AI will take the sum of the last 3 values played, and because each value
is unique (i.e a value of 21 would be Two Scissors and One Paper) it will know what
it has to play in order to (A)not violate rule #2 and (B) beat the other person's
choices because it will also search their array sum.
So, here's my problem:
1) I'm not very skilled with arrays, and I don't know how to (take the sum) or how to
search through the arrays to check the values.
2) Also, once I have looped through 4 rounds of the game (i.e my array lists are full)
I am not sure how to delete the 1st input(userinput[0]) or (computerinput[0]) in order
for the AI to keep refreshing and basing it's decisions off of new information.
OKAY: So here's my code. If there are undefined variables, most likely it's because it was an idea I was thinking about trying, but couldn't figure out how to make it work.
import java.io.*;
import java.util.*;
public class PlayGame
{
static int index=4;
static int y;
static int numGames=0;
static int Userinput[]=new int[index];
static int Compinput[]=new int[index];
static int Rock=1;
static int Paper=3;
static int Scissors=9;
static boolean rock,paper,scissors;
public static void main(String args[])
{
//set up scanner
Scanner RPS = new Scanner(System.in);
//set up strings
System.out.println("Welcome to the Rock Paper Scissors Game\n");
System.out.println("Are you ready to play? y/n");
//User defines if they are ready to play
//Set input as a char for a switch
String WouldYouPlay = RPS.nextLine();
char YesOrNo = WouldYouPlay.charAt(0);
//Define Switch
switch(YesOrNo)
{
case 'y':
PlayGame.RockPaperScissors();
break;
case 'n':
System.out.println("Goodbye!");
break;
}
}
public static void RockPaperScissors()
{
//set up another scanner
Scanner rpsReader = new Scanner(System.in);
//Computer outputs a random number, either 0,1,or 2
//if the comp outputs a 0 it equals Rock, and puts a 1 in the 1st spot of the comp array
//if the comp outputs a 1 it equals Paper, and puts a 3 in the 1st spot of the comp array
//if the comp outputs a 2 it equals Scissors, and puts a 9 in the 1st spot of the comp array
int CompStart = (int)(Math.random()*3);
if(CompStart==0)
{
Compinput[0]=Rock;
System.out.println("My choice is Rock");
}
else if(CompStart==1)
{
Compinput[0]=Paper;
System.out.println("My choice is Paper");
}
else if(CompStart==2)
{
Compinput[0]=Scissors;
System.out.println("My choice is Scissors");
}
for(int xx=0;xx<4;xx++)
{
System.out.println("Your selection R,P,S)?");
String RockPaperScissors=rpsReader.nextLine();
char RPSchoice= RockPaperScissors.charAt(0);
if(xx==0)
{
y=0;
}
else if(xx==1)
{
y=1;
}
else if(xx==2)
{
y=2;
}
else if(xx==3)
{
y=3;
System.out.println("Last slot of array, (xx==3) it needs to loop over again from this point");
//when xx==3, its on the fourth slot in the array (y) (I was checking to see if this would work may not be necessary.
}
switch(RPSchoice)
{
case 'R':
case 'r':
Userinput[y]=Rock;
System.out.println("You chose Rock!");
boolean rock=true;//an idea that i was messing with, may not be necessary: SEE COMPUTER AI
ComputerAI();//if you enter an 'r' it will call in the computer AI to find out what to play next
break;
case 'P':
case 'p':
Userinput[y]=Paper;
boolean paper=true;
System.out.println("You chose Paper!");
ComputerAI();
break;
case 'S':
case 's':
Userinput[y]=Scissors;
boolean scissors=true;
System.out.println("You chose Scissors!");
ComputerAI();//if you enter an 's' it will call in the computer AI to find out what to play next
break;
}
}
}
public static void ComputerAI()
{
if(rock=true)//checks to see if the User selected 'r'. If the user did, then it will search it's own array to see if it needs to play
{ //something mandatory, if not it will play paper
if(Compinput.equals())
{
}
}
}
}