internal void MovePiece(Move move) { Position to = move.To; Position from = move.From; if (move.Capture is King) { Debug.WriteLine("Not supposed to happen!"); } // Pawn promotion if (move.Promotion) { Board.PromotePawn(move); } if (move.Piece is Pawn) { Pawn pawn = move.Piece as Pawn; if (move.EnPassantMove && pawn.Color == PieceColor.White) { Board.UpdatePieceEnum(pawn, PieceEnum.WhitePawnEnPassant); } else if (move.EnPassantMove && pawn.Color == PieceColor.Black) { Board.UpdatePieceEnum(pawn, PieceEnum.BlackPawnEnPassant); } } if (move.Piece is King) { King king = move.Piece as King; if (move.Castle) { Board.MovePiece(move.CastleMove.From, move.CastleMove.To); move.CastleMove.Piece.MoveCount++; } if (king.Color == PieceColor.White) { Board.UpdatePieceEnum(king, PieceEnum.WhiteKingNoCastle); } else if (king.Color == PieceColor.Black) { Board.UpdatePieceEnum(king, PieceEnum.BlackKingNoCastle); } } if (!(move.Piece is Pawn) || move.Capture is Empty) { if (progress.Count > 0) { progress.Push(progress.Peek() + 1); } else { progress.Push(1); } } else { progress.Push(0); } if (!(move.Capture is Empty)) { Board.RemovePiece(move.Capture.Position.Row, move.Capture.Position.Col); } Board.MovePiece(from, to); move.Piece.MoveCount++; moves.Push(move); prevHashes.Push(Board.Hash); if (CurrentTurn == PieceColor.White) { CurrentTurn = PieceColor.Black; ClearPassant(PieceColor.Black); } else { CurrentTurn = PieceColor.White; ClearPassant(PieceColor.White); } if (IsThreatened(Board.GetKing(CurrentTurn))) { move.CheckBonus = true; } }