Commit 505f5e40 authored by amir's avatar amir

Completing some methods

parent e25994ec
......@@ -4,6 +4,9 @@ public class Main {
public static void main(String[] args) {
// write your code here
Player1 player1 = new Player1();
Player2 player2 = new Player2();
System.out.println(" 0 1 2 3 4 5");
for (int i = 0; i < 3; i++){
System.out.print(i + "|");
......@@ -32,5 +35,7 @@ public class Main {
if (i < 5)
System.out.println();
}
int turns = 1;
}
}
......@@ -27,58 +27,74 @@ public class Player {
for (int i = 0; i < 6; i++){
for (int j = 0; j < 6; j++){
if (containsInArray(arr, j, i)){
if (checkSides(arr, j, i))
return true;
}
}
}
return false;
}
public void checkSides(int[][] arr,int x, int y){
public boolean checkSides(int[][] arr,int x, int y){
if (x != 0){
if (containsInArray(arr, x - 1, y)){
if (checkTheMoveIfPossible(arrOpponent, arr, x, y, -1, 0))
if (countTheMoves(arr, x, y, -1, 0) == 5)
return true;
}
if (y != 0){
if (containsInArray(arr, x - 1, y - 1))
if (checkTheMoveIfPossible(arrOpponent, arr, x, y, -1, -1))
if (countTheMoves(arr, x, y, -1, -1) == 5)
return true;
}
if (y != 5){
if (containsInArray(arr, x - 1, y + 1))
if (checkTheMoveIfPossible(arrOpponent, arr, x, y, -1, +1))
if (countTheMoves(arr, x, y, -1, 1) == 5)
return true;
}
}
if (x != 5){
if (containsInArray(arrOpponent, x + 1, y)){
if (checkTheMoveIfPossible(arrOpponent, arr, x, y, +1, 0))
if (containsInArray(arr, x + 1, y)){
if (countTheMoves(arr, x, y, 1, 0) == 5)
return true;
}
if (y != 0){
if (containsInArray(arrOpponent, x + 1, y - 1))
if (checkTheMoveIfPossible(arrOpponent, arr, x, y, +1, -1))
if (containsInArray(arr, x + 1, y - 1))
if (countTheMoves(arr, x, y, 1, -1) == 5)
return true;
}
if (y != 5){
if (containsInArray(arrOpponent, x + 1, y + 1)) {
if (checkTheMoveIfPossible(arrOpponent, arr, x, y, +1, +1))
if (containsInArray(arr, x + 1, y + 1)) {
if (countTheMoves(arr, x, y, 1, -1) == 5)
return true;
}
}
}
if (y != 0){
if (containsInArray(arrOpponent, x, y - 1))
if (checkTheMoveIfPossible(arrOpponent, arr, x, y, 0, -1))
if (containsInArray(arr, x, y - 1))
if (countTheMoves(arr, x, y, 0, -1) == 5)
return true;
}
if (y != 5){
if (containsInArray(arrOpponent, x, y + 1)) {
if (containsInArray(arr, x, y + 1)) {
if (checkTheMoveIfPossible(arrOpponent, arr, x, y, 0, +1))
if (countTheMoves(arr, x, y, 0, 1) == 5)
return true;
}
}
return false;
}
public int countTheMoves(int[][]arr, int x, int y, int moveX, int moveY){
int x1 = x + moveX;
int y1 = y + moveY;
int counter = 1;
while ((counter < 5) && (x1 > -1) && (x1 < 6)
&& (y1 > -1) && (y1 < 6) && (containsInArray(arr, x1, y1))){
counter++;
x1 += moveX;
y1 += moveY;
}
return counter;
}
}
......@@ -28,13 +28,13 @@ public class smallBoards {
boardsCoordinate[0][2] = tmp1;
boardsCoordinate[0][0] = tmp2;
int tmp3 = boardsCoordinate[1][0];
tmp = boardsCoordinate[1][0];
boardsCoordinate[1][0] = boardsCoordinate[0][1];
int tmp4 = boardsCoordinate[2][1];
boardsCoordinate[2][1] = tmp3;
int tmp5 = boardsCoordinate[1][2];
boardsCoordinate[1][2] = tmp4;
boardsCoordinate[0][1] = tmp5;
tmp1 = boardsCoordinate[2][1];
boardsCoordinate[2][1] = tmp;
tmp2 = boardsCoordinate[1][2];
boardsCoordinate[1][2] = tmp1;
boardsCoordinate[0][1] = tmp2;
return boardNumber;
}
......
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