Example #1
0
 public ValidateChessPieceMoveRequest(
     ChessPieceKind chessPieceKind, ChessboardPositionDto currentPosition, ChessboardPositionDto targetPosition)
 {
     ChessPieceKind  = chessPieceKind;
     CurrentPosition = currentPosition;
     TargetPosition  = targetPosition;
 }
Example #2
0
        public static string ChessPieceKindToFEN(ChessPieceKind kind)
        {
            switch (kind)
            {
            case ChessPieceKind.None:
                return("");

            case ChessPieceKind.Pawn:
                return("p");

            case ChessPieceKind.Knight:
                return("n");

            case ChessPieceKind.Bishop:
                return("b");

            case ChessPieceKind.Rook:
                return("r");

            case ChessPieceKind.Queen:
                return("q");

            case ChessPieceKind.King:
                return("k");
            }
            throw new ArgumentException($"Unable to translate {kind} into a FEN abbreviation.");
        }
        public async Task <GetChessPiecePossibleMovesResponse> GetAvailableMoves(
            int currentX, int currentY, ChessPieceKind chessPieceKind)
        {
            var request = new GetChessPiecePossibleMovesRequest(
                new ChessboardPositionDto(currentX, currentY), chessPieceKind);

            return(await mediator.Send(request));
        }
        public ChessboardState TestPieceMoveValidation(ChessPieceKind chessPieceKind, ChessboardState initialState)
        {
            var currentPosition = initialState.GetCurrentPosition();
            var request         = new GetChessPiecePossibleMovesRequest(currentPosition, chessPieceKind);
            var result          = HandleRequest(request);

            Assert.That(result.CurrentPosition, Is.EqualTo(currentPosition));
            return(ChessboardState.CreateFromMoves(result.CurrentPosition, result.PossibleMoves));
        }
Example #5
0
        public ValidateChessPieceMoveResponse TestPieceMoves(
            ChessPieceKind chessPieceKind, ChessboardState chessboardState)
        {
            var currentPosition = chessboardState.GetCurrentPosition();
            var targetPosition  = chessboardState.GetTargetPosition();
            var request         = new ValidateChessPieceMoveRequest(chessPieceKind, currentPosition, targetPosition);
            var result          = HandleRequest(request);

            return(result);
        }
        public void PutPiece_Should_PutThePieceOnTheBoard(ChessPieceKind kindOfPiece, ChessColor pieceColor, string square)
        {
            //	Arrange
            SUT        board = new SUT();
            ChessPiece piece = new ChessPiece(kindOfPiece, pieceColor);

            //	Act
            board.PutPiece(piece, new ChessSquare(square));

            //	Assert
            Assert.IsTrue(piece == board.GetPieceAt(new ChessSquare(square)));
        }
        public void RemovePieceAt_Should_RemoveThePiece(string square, ChessPieceKind expectedPiece, ChessColor expectedColor)
        {
            //	Arrange
            SUT        board = new SUT();
            ChessPiece actualPiece;

            //	Act
            actualPiece = board.RemovePieceAt(new ChessSquare(square));

            //	Assert
            Assert.AreEqual(expectedPiece, actualPiece.Kind);
            Assert.AreEqual(expectedColor, actualPiece.Color);
        }
Example #8
0
        private Ellipse createChessPieceShape(ChessPieceKind kind)
        {
            var newShape = new Ellipse
            {
                Height     = chessPieceSize,
                Width      = chessPieceSize,
                Stroke     = new SolidColorBrush(Color.FromArgb(255, 0, 0, 0)),
                Fill       = kind == ChessPieceKind.BlackChessPiece ? blackChessBrush : writeChessBrush,
                Visibility = Visibility.Hidden
            };

            chessboardCanvas.Children.Add(newShape);

            return(newShape);
        }
Example #9
0
        public bool PlaceChessPiece(int x, int y)
        {
            if (!CanPlaceChessPiece(x, y))
            {
                throw new InvalidOperationException("非法落子");
            }
            positions[x, y] = NextMoveKind;
            ChessPieceInfo chessPiece = new ChessPieceInfo {
                X = x, Y = y, Kind = NextMoveKind
            };

            previousMove = chessPiece;
            bool isWin = calcResult(chessPiece);

            if (isWin)
            {
                Result = previousMove.Kind;
            }
            NextMoveKind = NextMoveKind == ChessPieceKind.BlackChessPiece ? ChessPieceKind.WriteChessPiece : ChessPieceKind.BlackChessPiece;
            OnChessPlaced(chessPiece, isWin);
            return(isWin);
        }
 public void ChessPieceToFEN_Should_ReturnCorrectFENPiece(ChessPieceKind pieceKind, ChessColor pieceColor, string expectedFEN)
 {
     //	Assert
     Assert.AreEqual(expectedFEN, SUT.ChessPieceToFEN(new ChessPiece(pieceKind, pieceColor)));
 }
Example #11
0
 private PieceMoveTestDataBuilder(ChessPieceKind chessPiece)
 {
     this.chessPiece = chessPiece;
 }
Example #12
0
 public static IInitialChessboardStateStep ForChessPiece(ChessPieceKind chessPiece)
 {
     return(new PieceMoveTestDataBuilder(chessPiece));
 }
 public static IValidatedMoveStep ForChessPiece(ChessPieceKind chessPiece)
 {
     return(new ValidateMoveTestDataBuilder(chessPiece));
 }
Example #14
0
 public ChessPieceInfo(ChessPieceKind id, string label, string unicode)
 {
     this.Id      = id;
     this.Label   = label;
     this.Unicode = unicode;
 }
Example #15
0
 public Node(Position previousPlacedPosition, ChessPieceKind previousChessPieceKind)
 {
     PreviousPlacedPosition = previousPlacedPosition;
     PreviousChessPieceKind = previousChessPieceKind;
 }
Example #16
0
 private void PctBxKnight_Click(object sender, EventArgs e)
 {
     ChoosePiece  = ChessPieceKind.Knight;
     DialogResult = DialogResult.OK;
 }
Example #17
0
 private void PctBxBishop_Click(object sender, EventArgs e)
 {
     ChoosePiece  = ChessPieceKind.Bishop;
     DialogResult = DialogResult.OK;
 }
Example #18
0
 private void PctBxRook_Click(object sender, EventArgs e)
 {
     ChoosePiece  = ChessPieceKind.Rook;
     DialogResult = DialogResult.OK;
 }
Example #19
0
 public ChessPiece(ChessPieceKind kind, ChessColor color)
 {
     this.Kind  = kind;
     this.Color = color;
 }