private bool checkForKing(figure kingMy) { figureColor oppColor = kingMy.getColor() == figureColor.White ? figureColor.Black : figureColor.White; figure oppKing = getKing(oppColor); return(Math.Abs(kingMy.x - oppKing.x) > 1 || Math.Abs(kingMy.y - oppKing.y) > 1); }
private bool checkForPawn(figure kingMy) { figureColor kingColor = kingMy.getColor(); int ix; int iy; for (int i = 0; i <= Pawn.stepForCheck[kingColor].Length - 1; i++) { ix = kingMy.x + Pawn.stepForCheck[kingColor][i].dx; iy = kingMy.y + Pawn.stepForCheck[kingColor][i].dy; if (ix <= 7 && ix >= 0 && iy <= 7 && iy >= 0 && board[iy, ix] != null && board[iy, ix].getColor() != kingMy.getColor() && board[iy, ix].getName() == figureType.Pawn) { return(false); } } return(true); }
private bool checkForDia(figure kingMy) { bool res = true; for (int i = 0; (i <= Bishop.stepsForCheck.Length - 1) && res; i++) { int ix = kingMy.x + Bishop.stepsForCheck[i].dx; int iy = kingMy.y + Bishop.stepsForCheck[i].dy; while (ix <= 7 && iy <= 7 && ix >= 0 && iy >= 0) { if (board[iy, ix] != null) { res = res && ((board[iy, ix].getColor() == kingMy.getColor()) || (board[iy, ix].getName() != figureType.Queen && board[iy, ix].getName() != figureType.Bishop)); break; } ix += Bishop.stepsForCheck[i].dx; iy += Bishop.stepsForCheck[i].dy; } } return(res); }
private bool checkForKnight(figure kingMy) { int ix; int iy; for (int i = 0; i <= Knight.stepsForCheck.Length - 1; i++) { ix = kingMy.x + Knight.stepsForCheck[i].dx; iy = kingMy.y + Knight.stepsForCheck[i].dy; if (ix <= 7 && iy <= 7 && ix >= 0 && iy >= 0 && board[iy, ix] != null && board[iy, ix].getColor() != kingMy.getColor() && board[iy, ix].getName() == figureType.Knight) { return(false); } } return(true); }