internal void SetUpPieces() { Board.Clear(); moves.Clear(); prevHashes.Clear(); progress.Clear(); CurrentTurn = PieceColor.White; for (int i = 0; i < 8; i++) { Board.AddPiece(1, i, new Pawn(PieceColor.Black, Board, i)); Board.AddPiece(6, i, new Pawn(PieceColor.White, Board, i)); } Board.AddPiece(0, 0, new Rook(PieceColor.Black, Board, 8)); Board.AddPiece(0, 7, new Rook(PieceColor.Black, Board, 9)); Board.AddPiece(7, 0, new Rook(PieceColor.White, Board, 8)); Board.AddPiece(7, 7, new Rook(PieceColor.White, Board, 9)); Board.AddPiece(0, 1, new Knight(PieceColor.Black, Board, 10)); Board.AddPiece(0, 6, new Knight(PieceColor.Black, Board, 11)); Board.AddPiece(7, 1, new Knight(PieceColor.White, Board, 10)); Board.AddPiece(7, 6, new Knight(PieceColor.White, Board, 11)); Board.AddPiece(0, 2, new Bishop(PieceColor.Black, Board, 12)); Board.AddPiece(0, 5, new Bishop(PieceColor.Black, Board, 13)); Board.AddPiece(7, 2, new Bishop(PieceColor.White, Board, 12)); Board.AddPiece(7, 5, new Bishop(PieceColor.White, Board, 13)); Board.AddPiece(0, 3, new Queen(PieceColor.Black, Board, 14)); Board.AddPiece(7, 3, new Queen(PieceColor.White, Board, 14)); Board.AddPiece(0, 4, new King(PieceColor.Black, Board, 15)); Board.AddPiece(7, 4, new King(PieceColor.White, Board, 15)); MidGame = true; prevHashes.Push(Board.Hash); chessView.UpdateVisual(Board); }
public void UnMovePiece(Move move) { Position to = move.To; Position from = move.From; // Pawn demotion if (move.Promotion) { Board.DemotePawn(move); } if (move.Piece is King) { King king = move.Piece as King; if (move.Piece.MoveCount == 1) { if (king.Color == PieceColor.White) { Board.UpdatePieceEnum(king, PieceEnum.WhiteKing); } else if (king.Color == PieceColor.Black) { Board.UpdatePieceEnum(king, PieceEnum.BlackKing); } } if (move.Castle) { Board.MovePiece(move.CastleMove.To, move.CastleMove.From); move.CastleMove.Piece.MoveCount--; } } Board.MovePiece(to, from); move.Piece.MoveCount--; if (!(move.Capture is Empty)) { Board.AddPiece(move.Capture.Position.Row, move.Capture.Position.Col, move.Capture); } if (progress.Count > 0) { progress.Pop(); } if (moves.Count > 0) { moves.Pop(); } if (prevHashes.Count > 0) { prevHashes.Pop(); } if (CurrentTurn == PieceColor.White) { CurrentTurn = PieceColor.Black; if (moves.Count > 0 && moves.Peek().EnPassantMove) { Board.UpdatePieceEnum(moves.Peek().Piece, PieceEnum.WhitePawnEnPassant); } } else { CurrentTurn = PieceColor.White; if (moves.Count > 0 && moves.Peek().EnPassantMove) { Board.UpdatePieceEnum(moves.Peek().Piece, PieceEnum.BlackPawnEnPassant); } } }