コード例 #1
0
        public IActionResult GetAvailableMoves(string chessPieceName, [Required] string startingPosition)
        {
            PieceBase chessPiece = PieceFactory.CreateChessPiece(chessPieceName);

            if (chessPiece == null)
            {
                return(NotFound("Chess piece '" + chessPieceName + "' not found."));
            }

            Board chessBoard = new Board();

            Square startingSquare = chessBoard.GetSquare(startingPosition);

            if (startingSquare == null)
            {
                return(BadRequest("Starting position was not found on the chess board."));
            }

            startingSquare.piece = chessPiece;

            List <Square> availableMoves = chessBoard.GetAvailableMoves(startingSquare);

            string availableMovesOutput = Board.ConvertToCSV(availableMoves);
            string json = "{ 'availableChessMoves': '" + availableMovesOutput + "' }";

            return(Ok(json));
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: Grimlek/Chess
        private static PieceBase _GetChessPieceFromUser()
        {
            while (1 == 1)
            {
                Console.WriteLine("The available chess pieces are Rook, Queen, Bishop, and King.\n");
                Console.WriteLine("Please enter the name of the chess piece.");

                string chessPieceInput = Console.ReadLine();

                PieceBase chessPiece = PieceFactory.CreateChessPiece(chessPieceInput);

                if (chessPiece == null)
                {
                    Console.WriteLine();
                    Console.WriteLine("Chess piece '" + chessPieceInput + "' is invalid. Please Try Again!");
                    Console.WriteLine();
                }
                else
                {
                    return(chessPiece);
                }
            }
        }