public IChessGame Create() { var piecesFactory = new PiecesFactory(); var movementHistory = new MovementHistory(); var piecePromoter = new PiecePromoter(movementHistory); var castlingMover = new CastlingMover(movementHistory); var enPassantMover = new EnPassantMover(movementHistory); var pieceMover = new PieceMover(movementHistory, piecePromoter, castlingMover, enPassantMover); var chessBoard = new ChessBoard(piecesFactory, pieceMover); List <IMovement> movements = new(); var pawnMovement = new PawnMovement(chessBoard); var enPassantMovement = new EnPassantMovement(chessBoard); var kingMovement = new KingMovement(chessBoard); var horizontalMovement = new HorizontalMovement(chessBoard); var verticalMovement = new VerticalMovement(chessBoard); var pdiagonalMovement = new PositiveDiagonalMovement(chessBoard); var ndiagonalMovement = new NegativeDiagonalMovement(chessBoard); var knightMovement = new KnightMovement(chessBoard); movements.Add(pawnMovement); movements.Add(enPassantMovement); movements.Add(kingMovement); movements.Add(horizontalMovement); movements.Add(verticalMovement); movements.Add(pdiagonalMovement); movements.Add(ndiagonalMovement); movements.Add(knightMovement); var movementComposite = new MovementComposite(movements); List <IMovement> movementsWithCastling = new(); var queensideCastlingMovement = new QueensideCastlingMovement(chessBoard, movementComposite); var kingsideCastlingMovement = new KingsideCastlingMovement(chessBoard, movementComposite); movementsWithCastling.Add(movementComposite); movementsWithCastling.Add(queensideCastlingMovement); movementsWithCastling.Add(kingsideCastlingMovement); var movementCompositeWithCastling = new MovementComposite(movementsWithCastling); var promotionDetector = new PromotionDetector(chessBoard); var checkDetector = new CheckDetector(chessBoard, movementCompositeWithCastling); var legalMovement = new LegalMovement(chessBoard, movementCompositeWithCastling, checkDetector); var moveValidator = new MoveValidator(chessBoard, legalMovement, promotionDetector); var gameFinishedDetector = new GameFinishedDetector(checkDetector, legalMovement); return(new ChessGame(chessBoard, moveValidator, promotionDetector, gameFinishedDetector, legalMovement)); }
public void WhenThereIsBlackPawnEligibleForPromotionReturnsTrue() { //WK - white king //WP - white pawn //BK - black king //BP - black pawn //7 BK //6 //5 //4 //3 //2 //1 WP //0 WK BP // 0 1 2 3 4 5 6 7 var boardMock = new Mock <IChessBoard>(MockBehavior.Strict); var whiteKingMock = new Mock <IReadOnlyChessPiece>(MockBehavior.Strict); var whitePawnMock = new Mock <IReadOnlyChessPiece>(MockBehavior.Strict); var blackKingMock = new Mock <IReadOnlyChessPiece>(MockBehavior.Strict); var blackPawnMock = new Mock <IReadOnlyChessPiece>(MockBehavior.Strict); var whiteKingPosition = new Position(4, 0); var whitePawnPosition = new Position(4, 1); var blackKingPosition = new Position(4, 7); var blackPawnPosition = new Position(7, 0); var pieces = new List <IReadOnlyChessPiece>() { whiteKingMock.Object, whitePawnMock.Object, blackKingMock.Object, blackPawnMock.Object }; whiteKingMock .SetupGet(k => k.Color) .Returns(ChessColor.White); whiteKingMock .SetupGet(k => k.PieceType) .Returns(ChessPieceType.King); whiteKingMock .SetupGet(k => k.Position) .Returns(whiteKingPosition); whitePawnMock .SetupGet(e => e.Color) .Returns(ChessColor.White); whitePawnMock .SetupGet(k => k.PieceType) .Returns(ChessPieceType.Pawn); whitePawnMock .SetupGet(k => k.Position) .Returns(whitePawnPosition); blackKingMock .SetupGet(k => k.Color) .Returns(ChessColor.Black); blackKingMock .SetupGet(k => k.PieceType) .Returns(ChessPieceType.King); blackKingMock .SetupGet(k => k.Position) .Returns(blackKingPosition); blackPawnMock .SetupGet(e => e.Color) .Returns(ChessColor.Black); blackPawnMock .SetupGet(k => k.PieceType) .Returns(ChessPieceType.Pawn); blackPawnMock .SetupGet(k => k.Position) .Returns(blackPawnPosition); boardMock .SetupGet(b => b.Pieces) .Returns(pieces); var promotionDetector = new PromotionDetector(boardMock.Object); var isPromotionRequired = promotionDetector.IsPromotionRequired(); Assert.AreEqual(true, isPromotionRequired); }