internal override Square[,] CanFigureMove(Square[,] avaibleSquares, Desk desk, Square ownSquare) { foreach (Square square in avaibleSquares) { if (square == ownSquare) { avaibleSquares[square.x, square.y] = Square.none; continue; } if (!((ownSquare.AbsDeltaX(square) == 1 && ownSquare.AbsDeltaY(square) == 2) || (ownSquare.AbsDeltaX(square) == 2 && ownSquare.AbsDeltaY(square) == 1))) { avaibleSquares[square.x, square.y] = Square.none; } else { if (desk.deskSquares[square.x, square.y].ownedPiece.pieceColor == pieceColor) { avaibleSquares[square.x, square.y] = Square.none; movesVector.occupiedSquares.Add(square.Name); } } } return(avaibleSquares); }
//для слона и ферзя protected void CanMoveDiagonal(Square[,] avaibleSquares, Square[,] deskSquares, Square ownSquare) { foreach (Square square in avaibleSquares) { if (square == ownSquare) { avaibleSquares[square.x, square.y] = Square.none; continue; } if (!(ownSquare.AbsDeltaX(square) == ownSquare.AbsDeltaY(square))) { avaibleSquares[square.x, square.y] = Square.none; } } bool blocked = false; int i = 1; while ((ownSquare.x + i <= 7) && (ownSquare.y + i <= 7)) { Square sq = deskSquares[ownSquare.x + i, ownSquare.y + i]; CheckSquare(avaibleSquares, sq, ownSquare.x + i, ownSquare.y + i, ref blocked); i++; } blocked = false; i = 1; while ((ownSquare.x + i <= 7) && (ownSquare.y - i >= 0)) { Square sq = deskSquares[ownSquare.x + i, ownSquare.y - i]; CheckSquare(avaibleSquares, sq, ownSquare.x + i, ownSquare.y - i, ref blocked); i++; } blocked = false; i = 1; while ((ownSquare.x - i >= 0) && (ownSquare.y + i <= 7)) { Square sq = deskSquares[ownSquare.x - i, ownSquare.y + i]; CheckSquare(avaibleSquares, sq, ownSquare.x - i, ownSquare.y + i, ref blocked); i++; } blocked = false; i = 1; while ((ownSquare.x - i >= 0) && (ownSquare.y - i >= 0)) { Square sq = deskSquares[ownSquare.x - i, ownSquare.y - i]; CheckSquare(avaibleSquares, sq, ownSquare.x - i, ownSquare.y - i, ref blocked); i++; } }
//для ладьи и ферзя protected void CanMoveStraight(Square[,] avaibleSquares, Square[,] deskSquares, Square ownSquare) { foreach (Square square in avaibleSquares) { if (square == ownSquare) { avaibleSquares[square.x, square.y] = Square.none; continue; } if (!(ownSquare.AbsDeltaX(square) == 0 || ownSquare.AbsDeltaY(square) == 0)) { avaibleSquares[square.x, square.y] = Square.none; } } bool blocked = false; for (int x = ownSquare.x + 1; x < 8; x++) { Square sq = deskSquares[x, ownSquare.y]; CheckSquare(avaibleSquares, sq, x, ownSquare.y, ref blocked); } blocked = false; for (int x = ownSquare.x - 1; x >= 0; x--) { Square sq = deskSquares[x, ownSquare.y]; CheckSquare(avaibleSquares, sq, x, ownSquare.y, ref blocked); } blocked = false; for (int y = ownSquare.y + 1; y < 8; y++) { Square sq = deskSquares[ownSquare.x, y]; CheckSquare(avaibleSquares, sq, ownSquare.x, y, ref blocked); } blocked = false; for (int y = ownSquare.y - 1; y >= 0; y--) { Square sq = deskSquares[ownSquare.x, y]; CheckSquare(avaibleSquares, sq, ownSquare.x, y, ref blocked); } }
internal override Square[,] CanFigureMove(Square[,] avaibleSquares, Desk desk, Square ownSquare) { //пешки ходят на два хода только со своей начальной горизонтали(2-я для белыхых, 7-я для черных) CanJump = ((ownSquare.y == 1 && pieceKey == PiecesKeys.whitePawn) || (ownSquare.y == 6 && pieceKey == PiecesKeys.blackPawn)); Piece pieceOnSquare; int absDeltaX, deltaY; foreach (Square square in avaibleSquares) { pieceOnSquare = desk.deskSquares[square.x, square.y].ownedPiece; absDeltaX = ownSquare.AbsDeltaX(square); deltaY = ownSquare.DeltaY(square); if (CanJump && absDeltaX == 0 && deltaY == 2 * stepY) { if (desk.deskSquares[square.x, square.y - stepY].ownedPiece != Piece.nullPiece) { avaibleSquares[square.x, square.y] = Square.none; continue; } if (pieceOnSquare != Piece.nullPiece) { movesVector.occupiedSquares.Add(square.Name); avaibleSquares[square.x, square.y] = Square.none; continue; } continue; } if (deltaY == stepY && absDeltaX <= 1) { if (absDeltaX == 0) { if (pieceOnSquare == Piece.nullPiece) { continue; } movesVector.occupiedSquares.Add(square.Name); avaibleSquares[square.x, square.y] = Square.none; } else { if (desk.notation.EnPassant == square.Name && desk.notation.InGameColor == pieceColor) { movesVector.status = "recalculate"; continue; } if (pieceOnSquare.pieceColor != pieceColor.FlipColor()) { movesVector.occupiedSquares.Add(square.Name);//////////////////// avaibleSquares[square.x, square.y] = Square.none; } } continue; } else { avaibleSquares[square.x, square.y] = Square.none; } } return(avaibleSquares); }