Ejemplo n.º 1
0
        /*
         * This is the process Driver This class handles all the checkes at the top most level
         * Each failed check throws the exception.
         */
        public String processChess(String move, String board)
        {
            byte sColumn;
            byte sRow;
            byte dColumn;
            byte dRow;
            char csColumn;
            char scrow;
            char cdColumn;
            char dcrow;
            Engine engine = null;
            String fen;
            /*
             * This if/else checks for the move string throws and exception if null is passed in
             * This also checks and verify if the string is correct format it will throw
             * the exceptions
             */
            if (move != null)
            {
                int space = move.LastIndexOf(" ");
                if (space == -1)
                {
                    throw new System.ArgumentException("The move sting is in the wrong format missing space between moves", "Chess");
                }
                Byte[] bytes = Encoding.ASCII.GetBytes(move.ToLower());
                csColumn = (char)bytes[space - 2];
                sColumn = GetByteFromCharL(csColumn);
                scrow = (char)bytes[space - 1];
                sRow = GetByteFromCharN(scrow);
                cdColumn = (char)bytes[space + 1];
                dColumn = GetByteFromCharL(cdColumn);
                dcrow = (char)bytes[space + 2];

                dRow = GetByteFromCharN((char)bytes[space + 2]);

            }
            else
            {
                throw new System.ArgumentException("The move sting is null", "Chess");
            }

            /*
             * This if/else  checks for the board to be null or not and creates the engine
             */
            if (board != null)
            {
                    engine = new Engine(board);

            }
            else
            {
                    engine = new Engine();
            }

            String pieceColor = engine.GetPieceColorAt(sColumn, sRow).ToString();
            String moveColor = engine.WhoseMove.ToString();

            /*
             *  Checks the piece color with the move color if they are not the same throws and exception
             */
            if (!pieceColor.Equals(moveColor))
            {
                throw new System.ArgumentException("THE PIECE YOU ARE MOVING IS NOT YOUR COLOR PLEASE MOVE YOUR COLOR", "Chess");
            }

            /*
             *  Check to make sure the move is valid and make sure the FEN is valid
             */
            if (engine.IsValidMove(sColumn, sRow, dColumn, dRow))
            {
             /*
             *     Checks to make sure th move is complete
             */
                if (!engine.MovePiece(sColumn, sRow, dColumn, dRow))
                {
                    throw new System.ArgumentException("MOVED FAILED PLEASE RESEND", "Chess");
                }
            }
            else
            {
                throw new System.ArgumentException("Invalid Move or Malformed FEN", "Chess");
            }

            fen = Fen(false, engine.ChessBoard);
            return fen;
        }
Ejemplo n.º 2
0
 /*
      *Checks is the player is white return true if is.
      */
 public bool IsWhiteMove(String fn)
 {
     bool move = false;
     Engine Tengine = new Engine(fn);
     string whitemove = "White";
     if (whitemove.Equals(Tengine.ChessBoard.WhoseMove.ToString()))
     {
         move = true;
     }
     return move;
 }