Esempio n. 1
0
        public static CastlingInfo FromString(string s)
        {
            CastlingInfo info = new CastlingInfo();

            string[] sArr = s.Split(':');
            if (sArr[0].Contains('K'))
            {
                info.whiteKing = true;
            }
            if (sArr[0].Contains('Q'))
            {
                info.whiteQueen = true;
            }
            if (sArr[0].Contains('k'))
            {
                info.blackKing = true;
            }
            if (sArr[0].Contains('q'))
            {
                info.blackQueen = true;
            }
            info.whiteLeftRook  = BoardPosition.FromString(sArr[1]);
            info.whiteRightRook = BoardPosition.FromString(sArr[2]);
            info.blackLeftRook  = BoardPosition.FromString(sArr[3]);
            info.blackRightRook = BoardPosition.FromString(sArr[4]);
            return(info);
        }
Esempio n. 2
0
 /// <summary>
 /// Construct a game state given all of its parameters
 /// </summary>
 /// <param name="board"></param>
 /// <param name="taken"></param>
 /// <param name="player"></param>
 /// <param name="castling"></param>
 /// <param name="enPassant"></param>
 /// <param name="halfmoveClock"></param>
 /// <param name="fullmoveClock"></param>
 /// <param name="gameType"></param>
 public GameState(Board board, List <Piece> taken, ChessColors player,
                  CastlingInfo castling, Nullable <BoardPosition> enPassant,
                  int halfmoveClock, int fullmoveClock, GameTypes gameType)
 {
     this.board         = board;
     this.taken         = taken;
     this.player        = player;
     this.castling      = castling;
     this.enPassant     = enPassant;
     this.halfmoveClock = halfmoveClock;
     this.fullmoveClock = fullmoveClock;
     this.gameType      = gameType;
 }
Esempio n. 3
0
 /// <summary>
 /// Construct a game state given only a board
 /// </summary>
 /// <param name="board">The game board</param>
 public GameState(Board board)
 {
     this.board    = board;
     this.taken    = new List <Piece>();
     this.player   = ChessColors.White;
     this.castling = new CastlingInfo {
         whiteKing  = true,
         whiteQueen = true,
         blackKing  = true,
         blackQueen = true
     };
     enPassant = null;
     gameType  = GameTypes.Normal;
 }
Esempio n. 4
0
        /// <summary>
        /// Convert a string to a game state
        /// </summary>
        /// <para>
        /// The string notation is very close to FEN,
        /// but modified to accomidate for skaktego rules.
        /// </para>
        /// <seealso cref="ToString"/>
        public static GameState FromString(string stateStr)
        {
            string[] splitStr     = stateStr.Split(' ');
            var      boardStr     = splitStr[0];
            var      takenStr     = splitStr[1];
            var      playerStr    = splitStr[2];
            var      castlingStr  = splitStr[3];
            var      enPassantStr = splitStr[4];
            var      halfmoveStr  = splitStr[5];
            var      fullmoveStr  = splitStr[6];
            var      gameTypeStr  = splitStr[7];

            // Construct all of the elements of the game state from the
            // string parts.
            Board board = Board.FromString(boardStr);

            List <Piece> taken = new List <Piece>();

            if (takenStr != "-")
            {
                foreach (char pieceChar in takenStr)
                {
                    Piece piece = Piece.FromChar(pieceChar);
                    taken.Add(piece);
                }
            }

            ChessColors  player   = ChessColorsMethods.FromChar(playerStr[0]);
            CastlingInfo castling = CastlingInfo.FromString(castlingStr);

            Nullable <BoardPosition> enPassant = null;

            if (enPassantStr != "-")
            {
                enPassant = BoardPosition.FromString(enPassantStr);
            }

            int halfmoveClock = int.Parse(halfmoveStr);
            int fullmoveClock = int.Parse(fullmoveStr);

            GameTypes gameType;

            switch (gameTypeStr)
            {
            case "s":
                gameType = GameTypes.Normal;
                break;

            case "st":
                gameType = GameTypes.Skaktego;
                break;

            case "stp":
                gameType = GameTypes.SkaktegoPrep;
                break;

            default:
                throw new ArgumentException("'" + gameTypeStr + "' is not a valid string");
            }

            return(new GameState(board, taken, player,
                                 castling, enPassant, halfmoveClock,
                                 fullmoveClock, gameType));
        }