示例#1
0
        public static (StoneStack bottom, StoneStack top) Split(StoneStack stack, int take)
        {
            var bottom = new StoneStack(stack.Take(stack.Count() - take));
            var top    = new StoneStack(stack.Take(take));

            return(bottom, top);
        }
示例#2
0
 public MoveStack(StoneStack stack, Board board, List <MoveDrop> moveDrops)
 {
     Stack = stack;
     Board = board;
     //From = from;
     //Destination = destination;
     MoveDrops = moveDrops;
 }
示例#3
0
        public StoneStack Copy()
        {
            var ret = new StoneStack();

            foreach (var item in this)
            {
                ret.Push(item);
            }
            return(ret);
        }
示例#4
0
        public StoneStack SplitStack(int take)
        {
            var tempStack = new StoneStack();

            for (int i = 0; i < take; i++)
            {
                tempStack.Push(Pop());
            }

            var newStack = new StoneStack();

            for (int i = 0; i < take; i++)
            {
                newStack.Push(tempStack.Pop());
            }

            return(newStack);
        }
示例#5
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);
        }