Ejemplo n.º 1
0
        public static MoveStack MoveStack(string input, Board board, Color color)
        {
            int file = 0;
            int rank = 0;

            var counter = 0;

            int howManyToTake = 1;
            var first         = input[counter];

            if (char.IsNumber(input[counter]))
            {
                howManyToTake = int.Parse(input[counter].ToString());
                counter++;

                if (howManyToTake > board.Dimension)
                {
                    throw new InvalidOperationException($"Cannot take more than Board dimension # of pieces ({board.Dimension})");
                }
            }

            //file@
            file = Board.Files.IndexOf(input[counter].ToString().ToUpper()[0]); //get the index from the letter of the file
            counter++;

            //rank
            rank = int.Parse(input[counter].ToString()) - 1;
            counter++;

            //driection
            var direction = input[counter];

            counter++;

            //drop values
            var remainder = input.Substring(counter);

            var dropValues = remainder.Trim().Select(x => int.Parse(x.ToString().Trim())).ToList();

            if (!dropValues.Any()) // if no number specified, assume one
            {
                dropValues.Add(1);
            }

            if (howManyToTake != dropValues.Sum())
            {
                throw new InvalidOperationException("Not accounting for each stone taken");
            }

            //now build the move sets based on this.
            var moveDrops = new List <MoveDrop>();

            var sourceSquare = board.GetSquare(file, rank);

            foreach (var drop in dropValues)
            {
                moveDrops.Add(MoveInDirection(ref file, ref rank, direction, drop));
            }

            var(bottom, top) = StoneStack.Split(sourceSquare.Pieces, howManyToTake);
            var ret = new MoveStack(top, board, moveDrops);

            return(ret);
        }