Commit 8b09ab57 authored by Omid Sayfun's avatar Omid Sayfun

Socket added

parent 67380b70
This diff is collapsed.
......@@ -36,7 +36,7 @@ public class Bishop extends Piece{
int yShift = (y - p.y) / Math.abs(y - p.y);
int i = 1;
while( x != (char)(p.x + i * xShift) && y != p.y + i * yShift ){
if( checkTaken(pieces, (char)(p.x + i * xShift), p.y + i * yShift) ){
if( checkTaken(pieces, (char)(p.x + i * xShift), p.y + i * yShift) != null && !(checkTaken(pieces, (char)(p.x + i * xShift), p.y + i * yShift) instanceof King) ){
return false;
}
......@@ -50,7 +50,7 @@ public class Bishop extends Piece{
int yShift = (y - this.y) / Math.abs(y - this.y);
int i = 1;
while( x != (char)(this.x + i * xShift) && y != this.y + i * yShift ){
if( checkTaken(pieces, (char)(this.x + i * xShift), this.y + i * yShift) ){
if( checkTaken(pieces, (char)(this.x + i * xShift), this.y + i * yShift) != null && !(checkTaken(pieces, (char)(this.x + i * xShift), this.y + i * yShift) instanceof King) ){
return false;
}
......
......@@ -343,15 +343,21 @@ public class Board{
}
public boolean virtualCheck(ArrayList<Piece> enemy, char x, int y){
String temp = Character.toString(enemy.get(0).getName().charAt(0));
for(Piece p : enemy){
if( p.canMove(x, y) ){ // Check if move is valid
if( p.checkWay(this.allPieces, x, y) ){
if( p instanceof Pawn && p.getX() - x == 0 ){
return false;
}else{
return true;
}
}
}
}
return false;
}
......@@ -630,7 +636,31 @@ public class Board{
if( found.checkWay(this.allPieces, x, y) ){
if( (found instanceof Pawn) && found.crossMove(x, y) && attack == null ){
if( (found instanceof Pawn) && found.crossMove(x, y) ){
if( attack == null ){
return false;
}else{
if( y == attack.getY() && x == attack.getX() ){
if( found.color && y < found.getY() ){
return true;
}else if( !found.color && found.getY() < y ){
return true;
}else{
return false;
}
}else{
return false;
}
}
}else if( (found instanceof Pawn) && attack != null && found.getX() - attack.getX() == 0 ){
return false;
}else if( (found instanceof King) && virtualCheck(enemy, x, y)){
return false;
}else{
......
......@@ -55,7 +55,7 @@ public class Pawn extends Piece{
return true;
}else{
int yShift = (y - this.y) / Math.abs(y - this.y);
if( checkTaken(pieces, this.x, this.y + yShift) || checkTaken(pieces, this.x, this.y + 2 * yShift) ){
if( checkTaken(pieces, this.x, this.y + yShift) != null || checkTaken(pieces, this.x, this.y + 2 * yShift) != null ){
return false;
}
......
......@@ -47,14 +47,15 @@ public abstract class Piece{
return this.color;
}
public static boolean checkTaken(ArrayList<Piece> pieces, char x, int y){
public static Piece checkTaken(ArrayList<Piece> pieces, char x, int y){
for(Piece p : pieces){
if( p.x == x && p.y == y ){
return true;
return p;
}
}
return false;
return null;
}
public boolean crossMove(char x, int y){
......
......@@ -63,7 +63,7 @@ public class Rook extends Piece{
int i = 1;
boolean flag = true;
while( this.x != (char)(x + i * xShift) || this.y != y + i * yShift ){
if( checkTaken(pieces, (char)(x + i * xShift), y + i * yShift) ){
if( checkTaken(pieces, (char)(x + i * xShift), y + i * yShift) != null && !(checkTaken(pieces, (char)(x + i * xShift), y + i * yShift) instanceof King) ){
flag = false;
}
......@@ -90,7 +90,7 @@ public class Rook extends Piece{
}
int i = 1;
while( x != (char)(p.x + i * xShift) || y != p.y + i * yShift ){
if( checkTaken(pieces, (char)(p.x + i * xShift), p.y + i * yShift) ){
if( checkTaken(pieces, (char)(p.x + i * xShift), p.y + i * yShift) != null && !(checkTaken(pieces, (char)(p.x + i * xShift), p.y + i * yShift) instanceof King) ){
return false;
}
......
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