Example #1
0
        public bool Move(string movement)
        {
            //return to bool eventually

            /*
             * piece.move() pass x and y for new space
             */
            if (movement.Length == 5)
            {
                int currentFile = CharToInt(movement[0]);
                int currentRank = int.Parse(movement[1].ToString()) - 1;
                int newFile     = CharToInt(movement[3]);
                int newRank     = int.Parse(movement[4].ToString()) - 1;
                if (boardSpaces[currentRank, currentFile].HasPiece())
                {
                    Piece movingPiece = boardSpaces[currentRank, currentFile].GetPiece();
                    if (movingPiece.Move(movingPiece.GetPieceType(), currentRank, currentFile, newRank, newFile))
                    {
                        string pieceString = movingPiece.GetPieceString();
                        boardSpaces[newRank, newFile].AddPiece(pieceString[1], pieceString[0]);
                        boardSpaces[currentRank, currentFile].RemovePiece();
                        return(true);
                    }
                    else
                    {
                        Parser.PrintInfo(movement, "This is an invalid move.\n");
                        return(false);
                    }
                }
                else
                {
                    Parser.PrintInfo(movement, "The stating space does not contain a piece to move.\n");
                    return(false);
                }
            }
            else
            {
                string firstMove  = string.Concat(movement[0], movement[1], movement[3], movement[4]);
                string secondMove = string.Concat(movement[6], movement[7], movement[9], movement[10]);
                if (Move(firstMove) && Move(secondMove))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }