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