Commit a744669e authored by amir's avatar amir

latest changes(I wanna uninstall intellij and reinstall this piece of shet!)

parent 58e04d78
...@@ -8,7 +8,7 @@ public class Main { ...@@ -8,7 +8,7 @@ public class Main {
// write your code here // write your code here
Player1 player1 = new Player1(); Player1 player1 = new Player1();
Player2 player2 = new Player2(); Player2 player2 = new Player2();
smallBoards s = new smallBoards(); smallBoards smallBoard = new smallBoards();
board1 b1 = new board1(); board1 b1 = new board1();
board2 b2 = new board2(); board2 b2 = new board2();
board3 b3 = new board3(); board3 b3 = new board3();
...@@ -16,16 +16,16 @@ public class Main { ...@@ -16,16 +16,16 @@ public class Main {
Player p = new Player(); Player p = new Player();
p.display(player1.getarr(), player2.getarr()); p.display(player1.getarr(), player2.getarr());
int turns = 0; int turns = 0;
while ((!player1.searchIfMatchEnds(player1.getarr())) while ((!player1.searchIfMatchEnds())
&& (!player2.searchIfMatchEnds(player2.getarr()))){ && (!player2.searchIfMatchEnds())){
Scanner scanner = new Scanner(System.in); Scanner scanner = new Scanner(System.in);
turns++; turns++;
if (turns %2 == 1){ if (turns %2 == 1){
System.out.println("Player1, it's your turn.");
byte x = scanner.nextByte(); byte x = scanner.nextByte();
byte y = scanner.nextByte(); byte y = scanner.nextByte();
System.out.println("Player1, it's your turn."); byte b = smallBoard.whichBoard(x, y);
byte b = s.whichBoard(x, y); player1.addDisc(player2.getarr(), x, y);
player1.addDisc(player1.getarr(), player2.getarr(), x, y);
if (x > 2) x -= 3; if (x > 2) x -= 3;
if (y > 2) y -= 3; if (y > 2) y -= 3;
if (b == 1) b1.addDiscToTheBoard(x, y, (byte) 1); if (b == 1) b1.addDiscToTheBoard(x, y, (byte) 1);
...@@ -33,12 +33,12 @@ public class Main { ...@@ -33,12 +33,12 @@ public class Main {
if (b == 3) b3.addDiscToTheBoard(x, y, (byte) 1); if (b == 3) b3.addDiscToTheBoard(x, y, (byte) 1);
if (b == 4) b4.addDiscToTheBoard(x, y, (byte) 1); if (b == 4) b4.addDiscToTheBoard(x, y, (byte) 1);
p.display(player1.getarr(), player2.getarr()); p.display(player1.getarr(), player2.getarr());
if ((player1.searchIfMatchEnds(player1.getarr())) || (player2.searchIfMatchEnds(player2.getarr()))) if ((player1.searchIfMatchEnds()) || (player2.searchIfMatchEnds()))
break; break;
else else
System.out.println("Please select a board to rotate(0 for none of them)"); System.out.println("Please select a board to rotate(0 for none of them)");
byte r = scanner.nextByte(); byte boardNumber = scanner.nextByte();
switch (r){ switch (boardNumber){
case 1: case 1:
b1.rotate(); b1.rotate();
break; break;
...@@ -54,16 +54,20 @@ public class Main { ...@@ -54,16 +54,20 @@ public class Main {
default: default:
break; break;
} }
if ((boardNumber > 0) && (boardNumber < 5)){
player1.rotate(boardNumber);
player2.rotate(boardNumber);
}
p.display(player1.getarr(), player2.getarr()); p.display(player1.getarr(), player2.getarr());
if ((player1.searchIfMatchEnds(player1.getarr())) || (player2.searchIfMatchEnds(player2.getarr()))) if ((player1.searchIfMatchEnds()) || (player2.searchIfMatchEnds()))
break; break;
} }
else{ else{
System.out.println("Player2, it's your turn.");
byte x = scanner.nextByte(); byte x = scanner.nextByte();
byte y = scanner.nextByte(); byte y = scanner.nextByte();
System.out.println("Player2, it's your turn."); byte b = smallBoard.whichBoard(x, y);
byte b = s.whichBoard(x, y); player2.addDisc(player1.getarr(), x, y);
player2.addDisc(player2.getarr(), player1.getarr(), x, y);
if (x > 2) x -= 3; if (x > 2) x -= 3;
if (y > 2) y -= 3; if (y > 2) y -= 3;
if (b == 1) b1.addDiscToTheBoard(x, y, (byte) 2); if (b == 1) b1.addDiscToTheBoard(x, y, (byte) 2);
...@@ -71,12 +75,12 @@ public class Main { ...@@ -71,12 +75,12 @@ public class Main {
if (b == 3) b3.addDiscToTheBoard(x, y, (byte) 2); if (b == 3) b3.addDiscToTheBoard(x, y, (byte) 2);
if (b == 4) b4.addDiscToTheBoard(x, y, (byte) 2); if (b == 4) b4.addDiscToTheBoard(x, y, (byte) 2);
p.display(player1.getarr(), player2.getarr()); p.display(player1.getarr(), player2.getarr());
if ((player1.searchIfMatchEnds(player1.getarr())) || (player2.searchIfMatchEnds(player2.getarr()))) if (player1.searchIfMatchEnds() || (player2.searchIfMatchEnds()))
break; break;
else else
System.out.println("Please select a board to rotate(0 for none of them)"); System.out.println("Please select a board to rotate(0 for none of them)");
byte r = scanner.nextByte(); byte boardNumber = scanner.nextByte();
switch (r){ switch (boardNumber){
case 1: case 1:
b1.rotate(); b1.rotate();
break; break;
...@@ -92,8 +96,12 @@ public class Main { ...@@ -92,8 +96,12 @@ public class Main {
default: default:
break; break;
} }
if ((boardNumber > 0) && (boardNumber < 5)){
player1.rotate(boardNumber);
player2.rotate(boardNumber);
}
p.display(player1.getarr(), player2.getarr()); p.display(player1.getarr(), player2.getarr());
if ((player1.searchIfMatchEnds(player1.getarr())) || (player2.searchIfMatchEnds(player2.getarr()))) if ((player1.searchIfMatchEnds()) || (player2.searchIfMatchEnds()))
break; break;
} }
} }
......
package com.company; package com.company;
public class Player { public class Player {
// a two dimensional array that saves the player's coordinate
private byte[][] playerCoordinate; private byte[][] playerCoordinate;
/**
* Creates a player with it's "playerCoordinate"
*/
public Player(){ public Player(){
playerCoordinate = new byte[6][6]; playerCoordinate = new byte[6][6];
} }
/**
* returns "playerCoordinate"
* @return playerCoordinate
*/
public byte[][] getarr() { public byte[][] getarr() {
return playerCoordinate; return playerCoordinate;
} }
/**
* gets a player's array, a x and a y of a coordinate to check if this coordinate is a blank or not
* @param arr the player's array
* @param x the x of coordinate to check
* @param y the y of coordinate to check
* @return true if it's not blank and false if it is almost a blank
*/
public boolean containsInArray(byte[][] arr, int x, int y){ public boolean containsInArray(byte[][] arr, int x, int y){
if (arr[x][y] != 0) if (arr[x][y] != 0)
return true; return true;
...@@ -18,15 +33,22 @@ public class Player { ...@@ -18,15 +33,22 @@ public class Player {
return false; return false;
} }
public void addDisc(byte[][] arr, byte[][]arrOpponent, int x, int y){ /**
if ((!containsInArray(arr, x, y)) && (!containsInArray(arrOpponent, x, y))) * gets the opponent array of coordinates and a x and y coordinate to check
arr[x][y]++; * if it's blank, add a disc to the list of coordinates
* @param arrOpponent
* @param x
* @param y
*/
public void addDisc(byte[][]arrOpponent, int x, int y){
if ((!containsInArray(playerCoordinate, x, y)) && (!containsInArray(arrOpponent, x, y)))
playerCoordinate[x][y]++;
} }
public boolean searchIfMatchEnds(byte[][] arr){ public boolean searchIfMatchEnds(){
for (int i = 0; i < 6; i++){ for (int i = 0; i < 6; i++){
for (int j = 0; j < 6; j++){ for (int j = 0; j < 6; j++){
if (containsInArray(arr, j, i)){ if (containsInArray(playerCoordinate, j, i)){
if (checkSides(j, i)) if (checkSides(j, i))
return true; return true;
} }
...@@ -97,17 +119,18 @@ public class Player { ...@@ -97,17 +119,18 @@ public class Player {
} }
public void display(byte[][] arr, byte[][]arr2){ public void display(byte[][] arr, byte[][]arr2){
System.out.println(" 0 1 2 3 4 5"); System.out.println(" 0 1 2 3 4 5");
for (int i = 0; i < 3; i++){ for (int i = 0; i < 3; i++){
System.out.print(i + "|"); System.out.print(i + "|");
for (int j = 0; j < 6; j++){ for (int j = 0; j < 6; j++){
if (containsInArray(arr, j, i)) if (containsInArray(arr, j, i))
System.out.println("R"); System.out.print("r");
else { else {
if (containsInArray(arr2, j, i)) if (containsInArray(arr2, j, i))
System.out.println("B"); System.out.print("b");
else else
System.out.print("\uD83D\uDD34"); //unicode of white circle
System.out.print('\u25CB');
} }
if ((j == 2) || (j == 5)) if ((j == 2) || (j == 5))
System.out.print("|"); System.out.print("|");
...@@ -117,19 +140,20 @@ public class Player { ...@@ -117,19 +140,20 @@ public class Player {
System.out.println(); System.out.println();
} }
System.out.print(" "); System.out.print(" ");
for (int j = 1; j < 15; j++) for (int j = 1; j < 12; j++)
System.out.print("_"); System.out.print("_");
System.out.println(); System.out.println();
for (int i = 3; i < 6; i++) { for (int i = 3; i < 6; i++) {
System.out.print(i + "|"); System.out.print(i + "|");
for (int j1 = 0; j1 < 6; j1++) { for (int j1 = 0; j1 < 6; j1++) {
if (containsInArray(arr, j1, i)) if (containsInArray(arr, j1, i))
System.out.println("R"); System.out.print("r");
else { else {
if (containsInArray(arr2, j1, i)) if (containsInArray(arr2, j1, i))
System.out.println("B"); System.out.print("b");
else else
System.out.print("\uD83D\uDD34"); //unicode of white circle
System.out.print('\u25CB');
} }
if ((j1 == 2) || (j1 == 5)) if ((j1 == 2) || (j1 == 5))
System.out.print("|"); System.out.print("|");
......
package com.company; package com.company;
public class smallBoards { public class smallBoards {
// a two dimensional array that saves the board's coordinate
private byte[][] boardsCoordinate; private byte[][] boardsCoordinate;
/**
* Creates a smallBoard with it's "boards coordinate"
*/
public smallBoards(){ public smallBoards(){
boardsCoordinate = new byte[3][3]; boardsCoordinate = new byte[3][3];
} }
/**
* gets a x and a y and returns the number of board that this x and y belongs to.
* @param x the x of the coordinate
* @param y the y of the coordinate
* @return the boardNumber
*/
public byte whichBoard(byte x, byte y){ public byte whichBoard(byte x, byte y){
if ((x >= 0) && (x < 3) && (y >= 0) && (y < 3)) if ((x >= 0) && (x < 3) && (y >= 0) && (y < 3))
return 1; return 1;
...@@ -16,9 +26,13 @@ public class smallBoards { ...@@ -16,9 +26,13 @@ public class smallBoards {
return 3; return 3;
if ((x >= 3) && (x < 6) && (y >= 3) && (y < 6)) if ((x >= 3) && (x < 6) && (y >= 3) && (y < 6))
return 4; return 4;
// returns 0 if the x and y don't belong to any of small boards
return 0; return 0;
} }
/**
* this method rotates the small board 90 degrees clockwise
*/
public void rotate(){ public void rotate(){
byte tmp = boardsCoordinate[2][0]; byte tmp = boardsCoordinate[2][0];
boardsCoordinate[2][0] = boardsCoordinate[0][0]; boardsCoordinate[2][0] = boardsCoordinate[0][0];
...@@ -38,7 +52,13 @@ public class smallBoards { ...@@ -38,7 +52,13 @@ public class smallBoards {
} }
/**
* gets a x and a y of the board and playerNumber to check if
* the coordinate doesn't belong to any players
* @param x is the x of the coordinate
* @param y is the x of the coordinate
* @param playerNumber is the number of player
*/
public void addDiscToTheBoard(byte x, byte y, byte playerNumber){ public void addDiscToTheBoard(byte x, byte y, byte playerNumber){
if (boardsCoordinate[x][y] == 0) if (boardsCoordinate[x][y] == 0)
boardsCoordinate[x][y] = playerNumber; boardsCoordinate[x][y] = playerNumber;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment