Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import lejos.nxt.Button;
- import lejos.nxt.LCD;
- import lejos.nxt.Motor;
- import lejos.util.Delay;
- import java.util.*;
- import java.lang.Math;
- import lejos.nxt.Sound;
- public class Robotic {
- public static boolean keepgoing = true;
- public static int turns = 0;
- public static int rockScore = 0;
- public static int paperScore= 0;
- public static int scissorScore = 0;
- public static int win = 0;
- public static int lose = 0;
- public static Boolean playedRock1 = false;
- public static Boolean playedRock2 = false;
- public static Boolean playedRock3 = false;
- public static Boolean playedScissors1 = false;
- public static Boolean playedScissors2 = false;
- public static Boolean playedScissors3 = false;
- public static Boolean playedPaper1 = false;
- public static Boolean playedPaper2 = false;
- public static Boolean playedPaper3 = false;
- public static Boolean result = false;
- //Here is where you can change the weight of each strategy.I suggest increasing the weight of strategies involving paper, but that's just me.
- public static int strategy1 = 10;
- public static int strategy2 = 10;
- public static int strategy3 = 10;
- public static int strategy4 = 10;
- public static int strategy5 = 10;
- public static int strategy6 = 10;
- public static int strategy7 = 10;
- public static int strategy8 = 10;
- public static int strategy9 = 10;
- public static int strategy10 = 10;
- public static int strategy11 = 10;
- public static int strategy12 = 10;
- public static int strategy13 = 10;
- public static int strategy14 = 10;
- public static int strategy15 = 10;
- public static int strategy16 = 10;
- public static int strategy17 = 10;
- public static int strategy18 = 10;
- public static int strategy19 = 10;
- public static int strategy20 = 10;
- public static int strategy21 = 10;
- public static int strategy22 = 10;
- public static int strategy23 = 10;
- public static int strategy24 = 10;
- public static int strategy25 = 10;
- public static int strategy26 = 10;
- public static int strategy27 = 10;
- public static int poopstall = 0;
- public static int[] scores = new int[300];
- public static Random rand = new Random();
- public static void main(String[] args) throws Exception {
- // Introduction
- LCD.drawString("ROCK PAPER SCISSORS", 0, 0);
- LCD.drawString("I LOSE, PUSH LEFT", 0, 1);
- LCD.drawString("I WIN, PUSH RIGHT", 0, 2);
- LCD.drawString("WHEN YOU'RE READY", 0, 3);
- LCD.drawString("PRESS ANYTHING ON SHOOT!", 0, 4);
- Button.waitForAnyPress();
- LCD.clear();
- while (keepgoing){
- Play();
- }
- LCD.clear();
- if (win>lose){
- Sound.beepSequenceUp();
- LCD.drawString("Hahaha I win!", 0, 1);
- LCD.drawString("Hahaha I win!", 0, 2);
- LCD.drawString("Hahaha I win!", 0, 3);
- LCD.drawString("Hahaha I win!", 0, 4);
- LCD.drawString("Hahaha I win!", 0, 5);
- Button.waitForAnyPress();
- }
- else{
- Sound.beepSequence();
- LCD.drawString("Okay you win >:(", 0, 1);
- LCD.drawString("Okay you win >:(", 0, 2);
- LCD.drawString("Okay you win >:(", 0, 3);
- LCD.drawString("Okay you win >:(", 0, 4);
- LCD.drawString("Okay you win >:(", 0, 5);
- Button.waitForAnyPress();
- }
- }
- // }
- public static void Play(){
- // Choose a random set pf 3 moves
- int randomthrow = pickPlay();
- if (randomthrow == 1){
- Rock();
- Rock();
- Rock();
- }
- else if (randomthrow == 2){
- Rock();
- Rock();
- Paper();
- }
- else if (randomthrow == 3){
- Rock();
- Rock();
- Scissors();
- }
- else if (randomthrow == 4){
- Rock();
- Paper();
- Rock();
- }
- else if (randomthrow == 5){
- Rock();
- Paper();
- Paper();
- }
- else if (randomthrow == 6){
- Rock();
- Paper();
- Scissors();
- }
- else if (randomthrow == 7){
- Rock();
- Scissors();
- Rock();
- }
- else if (randomthrow == 8){
- Rock();
- Scissors();
- Paper();
- }
- else if (randomthrow == 9){
- Rock();
- Scissors();
- Scissors();
- }
- else if (randomthrow == 10){
- Paper();
- Rock();
- Rock();
- }
- else if (randomthrow == 11){
- Paper();
- Rock();
- Paper();
- }
- else if (randomthrow == 12){
- Paper();
- Rock();
- Scissors();
- }
- else if (randomthrow == 13){
- Paper();
- Paper();
- Rock();
- }
- else if (randomthrow == 14){
- Paper();
- Paper();
- Paper();
- }
- else if (randomthrow == 15){
- Paper();
- Paper();
- Scissors();
- }
- else if (randomthrow == 16){
- Paper();
- Scissors();
- Rock();
- }
- else if (randomthrow == 17){
- Paper();
- Scissors();
- Paper();
- }
- else if (randomthrow == 18){
- Paper();
- Scissors();
- Scissors();
- }
- else if (randomthrow == 19){
- Scissors();
- Rock();
- Rock();
- }
- else if (randomthrow == 20){
- Scissors();
- Rock();
- Paper();
- }
- else if (randomthrow == 21){
- Scissors();
- Rock();
- Scissors();
- }
- else if (randomthrow == 22){
- Scissors();
- Paper();
- Rock();
- }
- else if (randomthrow == 23){
- Scissors();
- Paper();
- Paper();
- }
- else if (randomthrow == 24){
- Scissors();
- Paper();
- Scissors();
- }
- else if (randomthrow == 25){
- Scissors();
- Scissors();
- Rock();
- }
- else if (randomthrow == 26){
- Scissors();
- Scissors();
- Paper();;
- }
- else if (randomthrow == 27){
- Scissors();
- Scissors();
- Scissors();
- }
- }
- public static int pickPlay(){
- //Choose a random number for a random move
- updateScorecard();
- int randomthrow = rand.nextInt(100);
- int cantthinkofavariable = scores[randomthrow];
- return cantthinkofavariable;
- }
- public static int sumUp(){
- // Add up all occurences of strategies together
- int testnum = strategy1 + strategy2 + strategy3 + strategy4 + strategy5 + strategy6 + strategy7 + strategy8 + strategy9 + strategy10 +
- strategy11+ strategy12 +
- strategy13+strategy14+strategy15+strategy16+strategy17+strategy18+strategy19+strategy20+strategy21+strategy22+strategy23+strategy24+strategy25+strategy26
- +strategy27;
- return testnum;
- }
- public static void updateScorecard(){
- // This is the intelligent part. This ends up with an array proportionally filled with the corresponding number for each strategy
- // The occurence of each strategy dictates the amount of times its number will appear in the array. Then the array is used to choose the
- // Set of 3 moves
- int total = sumUp();
- int a = (int)Math.round(strategy1 * 100.0/total);
- int b = (int)Math.round(strategy2 * 100.0/total);
- int c = (int)Math.round(strategy3 * 100.0/total);
- int d = (int)Math.round(strategy4 * 100.0/total);
- int e = (int)Math.round(strategy5 * 100.0/total);
- int f = (int)Math.round(strategy6 * 100.0/total);
- int g = (int)Math.round(strategy7 * 100.0/total);
- int h = (int)Math.round(strategy8 * 100.0/total);
- int i = (int)Math.round(strategy9 * 100.0/total);
- int j = (int)Math.round(strategy10 * 100.0/total);
- int k = (int)Math.round(strategy11 * 100.0/total);
- int l = (int)Math.round(strategy12* 100.0/total);
- int m = (int)Math.round(strategy13 * 100.0/total);
- int n = (int)Math.round(strategy14 * 100.0/total);
- int o = (int)Math.round(strategy15 * 100.0/total);
- int p = (int)Math.round(strategy16 * 100.0/total);
- int q = (int)Math.round(strategy17 * 100.0/total);
- int r = (int)Math.round(strategy18 * 100.0/total);
- int s = (int)Math.round(strategy19 * 100.0/total);
- int t = (int)Math.round(strategy20 * 100.0/total);
- int u = (int)Math.round(strategy21 * 100.0/total);
- int v = (int)Math.round(strategy22 * 100.0/total);
- int w = (int)Math.round(strategy23 * 100.0/total);
- int x = (int)Math.round(strategy24 * 100.0/total);
- int y = (int)Math.round(strategy25 * 100.0/total);
- int z = (int)Math.round(strategy26 * 100.0/total);
- int ab = (int)Math.round(strategy27 * 100.0/total);
- for(poopstall = 0 ; poopstall <= a ; poopstall++){
- scores[poopstall] = 1;
- }
- for(poopstall = a + 1 ; poopstall <= a + b ; poopstall++){
- scores[poopstall] = 2;
- }
- for(poopstall = a+ b + 1 ; poopstall <=a+ b + c ; poopstall++){
- scores[poopstall] = 3;
- }
- for(poopstall =a+b+ c + 1 ; poopstall <=a+b+ c + d ; poopstall++){
- scores[poopstall] = 4;
- }
- for(poopstall =a+b+c+ d + 1 ; poopstall <=a+b+c+ d + e ; poopstall++){
- scores[poopstall] = 5;
- }
- for(poopstall =a+b+c+d+ e + 1 ; poopstall <=a+b+c+d+ e + f ; poopstall++){
- scores[poopstall] = 6;
- }
- for(poopstall =a+b+c+d+ e + f + 1 ; poopstall <=a+b+c+d+ e + f + g ; poopstall++){
- scores[poopstall] = 7;
- }
- for(poopstall =a+b+c+d+ e + f+g + 1 ; poopstall <=a+b+c+d+ e + f+ g + h ; poopstall++){
- scores[poopstall] = 8;
- }
- for(poopstall =a+b+c+d+ e + f+g+ h + 1 ; poopstall <=a+b+c+d+ e + f+g+ h + i ; poopstall++){
- scores[poopstall] = 9;
- }
- for(poopstall =a+b+c+d+ e + f+g+ h+ i + 1 ; poopstall <=a+b+c+d+ e + f+g+ h+ i + j ; poopstall++){
- scores[poopstall] = 10;
- }
- for(poopstall =a+b+c+d+ e + f+g+ h+ i + j + 1 ; poopstall <=a+b+c+d+ e + f+g+ h+ i + j + k ; poopstall++){
- scores[poopstall] = 11;
- }
- for(poopstall =a+b+c+d+ e + f+g+ h+ i + j + k + 1 ; poopstall <=a+b+c+d+ e + f+g+ h+ i + j +k + l ; poopstall++){
- scores[poopstall] = 12;
- }
- for(poopstall = a+b+c+d+ e + f+g+ h+ i + j + k + l + 1 ; poopstall <=a+b+c+d+ e + f+g+ h+ i + j + k + l + m ; poopstall++){
- scores[poopstall] = 13;
- }
- for(poopstall = a+b+c+d+ e + f+g+ h+ i + j + k + l +m + 1 ; poopstall <=a+b+c+d+ e + f+g+ h+ i + j + k + l + m + n ; poopstall+
- +){
- scores[poopstall] = 14;
- }
- for(poopstall = a+b+c+d+ e + f+g+ h+ i + j + k + l +m +n + 1 ; poopstall <=a+b+c+d+ e + f+g+ h+ i + j + k + l +m + n + o ;
- poopstall++){
- scores[poopstall] = 15;
- }
- for(poopstall =a+b+c+d+ e + f+g+ h+ i + j + k + l +m +n + o + 1 ; poopstall <=a+b+c+d+ e + f+g+ h+ i + j + k + l +m +n + o + p ;
- poopstall++){
- scores[poopstall] = 16;
- }
- for(poopstall =a+b+c+d+ e + f+g+ h+ i + j + k + l +m +n + o + p + 1 ; poopstall <=a+b+c+d+ e + f+g+ h+ i + j + k + l +m +n + o +
- p + q ; poopstall++){
- scores[poopstall] = 17;
- }
- for(poopstall = a+b+c+d+ e + f+g+ h+ i + j + k + l +m +n + o + p +q + 1 ; poopstall <=a+b+c+d+ e + f+g+ h+ i + j + k + l +m +n +
- o + p + q + r ; poopstall++){
- scores[poopstall] = 18;
- }
- for(poopstall =a+b+c+d+ e + f+g+ h+ i + j + k + l +m +n + o + p +q + r + 1 ; poopstall <=a+b+c+d+ e + f+g+ h+ i + j + k + l +m +n
- + o + p +q + r + s ; poopstall++){
- scores[poopstall] = 19;
- }
- for(poopstall =a+b+c+d+ e + f+g+ h+ i + j + k + l +m +n + o + p +q + r + s + 1 ; poopstall <=a+b+c+d+ e + f+g+ h+ i + j + k + l
- +m +n + o + p +q + r + s + t ; poopstall++){
- scores[poopstall] = 20;
- }
- for(poopstall =a+b+c+d+ e + f+g+ h+ i + j + k + l +m +n + o + p +q + r + s + t + 1 ; poopstall <=a+b+c+d+ e + f+g+ h+ i + j + k +
- l +m +n + o + p +q + r + s + t + u ; poopstall++){
- scores[poopstall] = 21;
- }
- for(poopstall =a+b+c+d+ e + f+g+ h+ i + j + k + l +m +n + o + p +q + r + s + t + u + 1 ; poopstall <= a+b+c+d+ e + f+g+ h+ i + j
- + k + l +m +n + o + p +q + r + s + t +u + v ; poopstall++){
- scores[poopstall] = 22;
- }
- for(poopstall = a+b+c+d+ e + f+g+ h+ i + j + k + l +m +n + o + p +q + r + s + t + u + v + 1 ; poopstall <=a+b+c+d+ e + f+g+ h+ i
- + j + k + l +m +n + o + p +q + r + s + t + u + v + v + w ; poopstall++){
- scores[poopstall] = 23;
- }
- for(poopstall = a+b+c+d+ e + f+g+ h+ i + j + k + l +m +n + o + p +q + r + s + t + u + v + w + 1 ; poopstall <=a+b+c+d+ e + f+g+
- h+ i + j + k + l +m +n + o + p +q + r + s + t + u + v + w + x ; poopstall++){
- scores[poopstall] = 24;
- }
- for(poopstall = a+b+c+d+ e + f+g+ h+ i + j + k + l +m +n + o + p +q + r + s + t + u + v + w +x + 1 ; poopstall <=a+b+c+d+ e + f
- +g+ h+ i + j + k + l +m +n + o + p +q + r + s + t + u + v + w + x + y ; poopstall++){
- scores[poopstall] = 25;
- }
- for(poopstall =a+b+c+d+ e + f+g+ h+ i + j + k + l +m +n + o + p +q + r + s + t + u + v + w +x + y + 1 ; poopstall <=a+b+c+d+ e +
- f+g+ h+ i + j + k + l +m +n + o + p +q + r + s + t + u + v + w +x + y + z ; poopstall++){
- scores[poopstall] = 26;
- }
- for(poopstall =a+b+c+d+ e + f+g+ h+ i + j + k + l +m +n + o + p +q + r + s + t + u + v + w +x + y + z + 1 ; poopstall <=a+b+c
- +d+ e + f+g+ h+ i + j + k + l +m +n + o + p +q + r + s + t + u + v + w +x + y + z + ab ; poopstall++){
- scores[poopstall] = 27;
- }
- }
- public static void whoWon(){
- // This updates the screen, telling who won each turn.
- result = false;
- LCD.drawString("DID I WIN?", 0, 0);
- LCD.drawString("ESCAPE TO QUIT", 0, 1);
- LCD.drawString("LEFT IF I WON" , 0, 2);
- LCD.drawString("RIGHT IF I LOST", 0, 3);
- LCD.drawString("Current Score is", 0, 4);
- LCD.drawInt(win,0,5);
- LCD.drawString("wins", 6, 5);
- LCD.drawInt(lose,0,6);
- LCD.drawString("losses", 6, 6);
- Button.waitForAnyPress();
- if (Button.LEFT.isDown()) {
- result = true;
- win += 1;
- } else if (Button.RIGHT.isDown()) {
- result = false;
- lose +=1;
- } else if (Button.ESCAPE.isDown()) {
- keepgoing = false;
- }
- Delay.msDelay(500);
- }
- public static void Rock(){
- // Moves the arm
- ++turns;
- Sound.playTone(1050,400,100);
- Delay.msDelay(700);
- Sound.playTone(1050,400,100);
- Delay.msDelay(700);
- Sound.playTone(1050,400,100);
- Delay.msDelay(700);
- Sound.playTone(1375,400,100);
- Motor.A.setSpeed(10000);
- Motor.B.setSpeed(10000);
- Motor.C.setSpeed(10000);
- Motor.A.rotate(10,true);
- Motor.C.rotate(10,true);
- Motor.B.rotate(10,true);
- whoWon();
- Motor.A.rotateTo(0,true);
- Motor.C.rotateTo(0,true);
- Motor.B.rotateTo(0,true);
- if(turns%3 == 1 && result == true)
- playedRock1 = true;
- else if(turns%3 == 1 && result == false)
- playedScissors1 = true;
- else if(turns%3 == 2 && result == true)
- playedRock2 = true;
- else if(turns%3 == 2 && result == false)
- playedScissors2 = true;
- else if(turns%3 == 0 && result == true)
- playedRock3 = true;
- else if(turns%3 == 0 && result == false)
- playedScissors3 = true;
- gambit();
- }
- public static void Paper(){
- //Moves the arm
- ++turns;
- Sound.playTone(1050,400,100);
- Delay.msDelay(700);
- Sound.playTone(1050,400,100);
- Delay.msDelay(700);
- Sound.playTone(1050,400,100);
- Delay.msDelay(700);
- Sound.playTone(1375,400,100);
- Motor.A.setSpeed(10000);
- Motor.B.setSpeed(10000);
- Motor.C.setSpeed(10000);
- Motor.A.rotate(110,true);
- Motor.C.rotate(90,true);
- Motor.B.rotate(110,true);
- whoWon();
- Motor.A.rotateTo(0,true);
- Motor.C.rotateTo(0,true);
- Motor.B.rotateTo(0,true);
- if(turns%3 == 1 && result == true)
- playedPaper1 = true;
- else if(turns%3 == 1 && result == false)
- playedRock1 = true;
- else if(turns%3 == 2 && result == true)
- playedPaper2 = true;
- else if(turns%3 == 2 && result == false)
- playedRock2 = true;
- else if(turns%3 == 0 && result == true)
- playedPaper3 = true;
- else if(turns%3 == 0 && result == false)
- playedRock3 = true;
- gambit();
- }
- public static void Scissors(){
- // moves the arm
- ++turns;
- Sound.playTone(1050,400,100);
- Delay.msDelay(700);
- Sound.playTone(1050,400,100);
- Delay.msDelay(700);
- Sound.playTone(1050,400,100);
- Delay.msDelay(700);
- Sound.playTone(1375,400,100);
- Motor.C.setSpeed(10000);
- Motor.C.rotate(110,true);
- whoWon();
- Motor.C.rotateTo(0,true);
- if(turns%3 == 1 && result == true)
- playedScissors1 = true;
- else if(turns%3 == 1 && result == false)
- playedPaper1 = true;
- else if(turns%3 == 2 && result == true)
- playedScissors2 = true;
- else if(turns%3 == 2 && result == false)
- playedPaper2 = true;
- else if(turns%3 == 0 && result == true)
- playedScissors3 = true;
- else if(turns%3 == 0 && result == false)
- playedPaper3 = true;
- gambit();
- }
- public static void gambit(){
- // This increments the occurence of each strategy every 3 moves
- if (turns%3 == 0){
- playedRock1 = false;
- playedRock2 = false;
- playedRock3 = false;
- playedScissors1 = false;
- playedScissors2 = false;
- playedScissors3 = false;
- playedPaper1 = false;
- playedPaper2 = false;
- playedPaper3 = false;
- }
- if (playedRock1 && playedRock2 && playedRock3)
- strategy1 +=1;
- else if (playedRock1 && playedRock2 && playedPaper3)
- strategy2 +=1;
- else if (playedRock1 && playedRock2 && playedScissors3)
- strategy3 +=1;
- else if(playedRock1 && playedPaper2 && playedRock3)
- strategy4 += 1;
- else if(playedRock1 && playedPaper2 && playedPaper3)
- strategy5 +=1;
- else if(playedRock1 && playedPaper2 && playedScissors3)
- strategy6 +=1;
- else if(playedRock1 && playedScissors2 && playedRock3)
- strategy7 +=1;
- else if(playedRock1 && playedScissors2 && playedPaper3)
- strategy8 +=1;
- else if(playedRock1 && playedScissors2 && playedScissors3)
- strategy9 +=1;
- else if(playedPaper1 && playedRock2 && playedRock3)
- strategy10 +=1;
- else if(playedPaper1 && playedRock2 && playedPaper3)
- strategy11 +=1;
- else if(playedPaper1 && playedRock2 && playedScissors3)
- strategy12 +=1;
- else if(playedPaper1 && playedPaper2 && playedRock3)
- strategy13 +=1;
- else if(playedPaper1 && playedPaper2 && playedPaper3)
- strategy14 +=1;
- else if(playedPaper1 && playedPaper2 && playedScissors3)
- strategy15 +=1;
- else if(playedPaper1 && playedScissors2 && playedRock3)
- strategy16 +=1;
- else if(playedPaper1 && playedScissors2 && playedPaper3)
- strategy17 +=1;
- else if(playedPaper1 && playedScissors2 && playedScissors3)
- strategy18 +=1;
- else if(playedScissors1 && playedRock2 && playedRock3)
- strategy19 +=1;
- else if(playedScissors1 && playedRock2 && playedPaper3)
- strategy20 +=1;
- else if(playedScissors1 && playedRock2 && playedScissors3)
- strategy21 +=1;
- else if(playedScissors1 && playedPaper2 && playedRock3)
- strategy22 +=1;
- else if(playedScissors1 && playedPaper2 && playedPaper3)
- strategy23 +=1;
- else if(playedScissors1 && playedPaper2 && playedScissors3)
- strategy24 +=1;
- else if(playedScissors1 && playedScissors2 && playedRock3)
- strategy25 +=1;
- else if(playedScissors1 && playedScissors2 && playedPaper3)
- strategy26 +=1;
- else if(playedScissors1 && playedScissors2 && playedScissors3)
- strategy27 +=1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement