Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class singleplayer {
- boolean gameOver;
- int control;
- int blackPoints;
- int whitePoints;
- Scanner input = new Scanner(System.in);
- board startBoard = new board();
- int AIDifficulty;
- public void begin(){
- blackPoints=0;
- whitePoints=0;
- control=1;
- gameOver=false;
- startBoard.prntboard();
- getAiDiff();
- control();
- }
- public int getAiDiff(){
- System.out.println();
- System.out.println("What difficulty of AI would you like, 1 for easy, 2 for medium");
- int temp = input.nextInt();
- if (temp ==1){AIDifficulty=1; return AIDifficulty;}
- if (temp ==2){AIDifficulty=2; return AIDifficulty;}
- return AIDifficulty;
- }
- public void control(){
- while(!gameOver){
- while(control ==1){
- System.out.println();
- System.out.println();
- System.out.println("Current Score is: "+whitePoints+" for White and "+blackPoints+ " for Black!.");
- System.out.println("You are white -o");
- System.out.println("Select token to move, (Row then column, with no space) or e to exit: ");
- String selected = input.next();
- if (selected.equals("e")){
- System.exit(0);
- }else{
- String[] parts = {selected.substring(0,1),selected.substring(1) };
- String row1 = parts[0];
- String column1 = parts[1];
- System.out.println("Select space to move to or e to exit: ");
- String dest = input.next();
- if (dest.equals("e")){
- System.exit(0);
- }
- String[] destParts= {dest.substring(0,1),dest.substring(1) };
- String row2 = destParts[0];
- String column2 = destParts[1];
- startBoard.getControlInput(row1,row2,column1,column2,control);
- //if(row2.equals(0)){pointForwhite();}
- control=2;
- }
- }
- while(control==2){
- if (AIDifficulty == 1){EzAI();}
- if (AIDifficulty ==2){HrdAI();}
- control =1;
- }
- }
- } //End of Control method
- public void EzAI(){
- String[][] blackLoc=startBoard.blackLocation;
- int direction = (int) Math.random()*3 +1;
- switch(direction){
- case 1: { String startRow;
- String startCol;
- int tempRow=0;
- int tempCol=0;
- for(int x=0;x<8;x++){
- for (int y=0;y<8;y++){
- if(blackLoc[x][y]==null){
- y++;}else{
- String tokenColour = blackLoc[x][y].substring(0, 2);
- if(startBoard.lastColourLanded.contains(tokenColour)){
- tempRow= x;
- tempCol=y;
- break;}
- }}}
- startRow =String.valueOf(tempRow);
- startCol=String.valueOf(tempCol);
- int distance = (int)Math.random() * 4 +1;
- int tempDestCol=tempCol -distance;
- int tempDestRow=tempRow+distance;
- String destRow = String.valueOf(tempDestRow);
- startBoard.checkValid(tempRow, tempCol, tempDestRow, tempDestCol, 2);
- while(!startBoard.valid){
- int distance2 = (int)Math.random() * 3 +1;
- int tempDestCol2=tempCol -distance2;
- int tempDestRow2=tempRow+distance2;
- String destRow2 = String.valueOf(tempDestRow2);
- startBoard.checkValid(tempRow, tempCol, tempDestRow2, tempDestCol2, 2);
- }
- if(startBoard.valid){
- startBoard.getControlInput(startRow, destRow, startCol, startCol, 2);
- } //diagonal Left Move
- break;
- }
- case 2:{ //StraightForward
- String startRow;
- String startCol;
- int tempRow=0;
- int tempCol=0;
- //String lastColourLanded= board.LastColour();
- for(int x=0;x<8;x++){
- for (int y=0;y<8;y++){
- if(blackLoc[x][y]==null){y++;}else{
- if(startBoard.lastColourLanded.contains(blackLoc[x][y])){
- tempRow= x;
- tempCol=y;
- break;
- }}}}
- startRow =String.valueOf(tempRow);
- startCol=String.valueOf(tempCol);
- int distance = (int)Math.random() * 4 +1;
- int tempDestRow=tempRow-distance;
- String destRow = String.valueOf(tempDestRow);
- startBoard.checkValid(tempRow, tempCol, tempDestRow, tempCol, 2);
- while(!startBoard.valid){
- int distance2 = (int)Math.random() * 4 +1;
- int tempDestRow2=tempRow-distance2;
- String destRow2 = String.valueOf(tempDestRow2);
- startBoard.checkValid(tempRow, tempCol, tempDestRow2, tempCol, 2);
- }
- if(startBoard.valid){
- startBoard.getControlInput(startRow, destRow, startCol, startCol, 2);
- } break;
- }
- case 3:{ //Diagonal Right
- String startRow;
- String startCol;
- int tempRow=0;
- int tempCol=0;
- for(int x=0;x<8;x++){
- for (int y=0;y<8;y++){
- if(blackLoc[x][y]==null){y++;}else{
- if(startBoard.lastColourLanded.contains(blackLoc[x][y])){
- tempRow= x;
- tempCol=y;
- break;
- }
- }}}
- startRow =String.valueOf(tempRow);
- startCol=String.valueOf(tempCol);
- int distance = (int)Math.random() * 3 +1;
- int tempDestCol=tempCol +distance;
- int tempDestRow=tempRow-distance;
- String destRow = String.valueOf(tempDestRow);
- startBoard.checkValid(tempRow, tempCol, tempDestRow, tempDestCol, 2);
- while(!startBoard.valid){
- int distance2 = (int)Math.random() * 4 +1;
- int tempDestRow2=tempRow-distance2;
- String destRow2 = String.valueOf(tempDestRow2);
- startBoard.checkValid(tempRow, tempCol, tempDestRow2, tempCol, 2);
- }
- if(startBoard.valid){
- startBoard.getControlInput(startRow, destRow, startCol, startCol, 2);
- }
- break;
- }
- }
- }
- public void HrdAI(){
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement