public PieceMove(Piece movedPiece, int toX, int toY, Piece capturedPiece = null, PieceMove lastMove = null, bool connectedMove = false) { MovedPiece = movedPiece; FromX = movedPiece.X; FromY = movedPiece.Y; PieceHasMoved = movedPiece.HasMoved; ToX = toX; ToY = toY; CapturedPiece = capturedPiece; LastMove = lastMove; ConnectedMove = connectedMove; }
private void PerformMove(Piece piece, int x, int y) { var destPiece = fields[x, y]; if (piece is Pawn && destPiece == null && piece.X != x) { destPiece = LastMove.MovedPiece; } var rokada = (piece as King)?.Rokada(x, y); LastMove = new PieceMove(piece, x, y, destPiece, LastMove); if (destPiece != null) { fields[destPiece.X, destPiece.Y] = null; destPiece.IsCaptured = true; } fields[piece.X, piece.Y] = null; piece.X = x; piece.Y = y; piece.HasMoved = true; fields[x, y] = piece; if (rokada != null) { PerformMove(rokada.Item1, rokada.Item2, rokada.Item3); LastMove.ConnectedMove = true; } else if (piece is Pawn && (piece.Y == 0 || piece.Y == SIZE - 1)) { var queen = new Queen(piece.Color, this, -1, -1); LastMove = new PieceMove(queen, piece.X, piece.Y, piece, LastMove); LastMove.ConnectedMove = true; fields[x, y] = queen; queen.X = x; queen.Y = y; pieces.Add(queen); piece.IsCaptured = true; } }
public static string ToMoveString(this PieceMove pieceMove) { return(new StringBuilder(FieldToString(pieceMove.FromX, pieceMove.FromY)).Append(',').Append(FieldToString(pieceMove.ToX, pieceMove.ToY)).ToString()); }