Exemplo n.º 1
0
        public bool FormMovesFromRules(int fptr, ref board tb, ref List <int> Empties, ref List <card> CardsToMove)
        {
            int           i, j, n;
            int           r1, r2;
            int           FromStack = 0, FromLoc = 0, ToStack = 0;
            string        strOper1, strOper2;
            card          TopCardToMove = CardsToMove[0];
            int           TopCardsDestination = tb.tag;
            int           SrcColumn = TopCardToMove.iStack;
            string        strSrc, strDes;
            List <cMoves> Moves = DisStrategy[fptr].Moves;

            n = Moves.Count;
            Debug.Assert(n % 2 == 0);   // must be an even number
            tb.ClearStacks();
            for (i = 0; i < n; i += 2)
            {
                strSrc = Moves[i].MoveID;
                r1     = GetOperands(strSrc, out strOper1);
                if (strOper1 == "SC")
                {
                    FromStack = SrcColumn;
                    FromLoc   = CardsToMove.Last().iCard;
                    CardsToMove.RemoveAt(CardsToMove.Count - 1);
                }
                else if (strOper1 == "E")
                {
                    FromStack = Empties[r1];
                    FromLoc   = tb.ThisColumn[FromStack].HoldMoves.Pop();
                }
                else if (strOper1 == "C")
                {
                    for (j = 0; j < WhereStored.Count; j++)
                    {
                        if (WhereStored[j].SeriesID == r1)
                        {
                            FromStack = WhereStored[j].StackNumber;
                            FromLoc   = tb.ThisColumn[FromStack].HoldMoves.Pop();
                        }
                    }
                }
                else
                {
                    Debug.Assert(false);
                    return(false);
                }


                strDes = Moves[i + 1].MoveID;
                r2     = GetOperands(strDes, out strOper2);

                if (strOper2 == "DC")
                {
                    ToStack = TopCardsDestination;
                }
                else if (strOper2 == "E")
                {
                    ToStack = Empties[r2];
                    tb.ThisColumn[ToStack].HoldMoves.Push(tb.ThisColumn[ToStack].Cards.Count);
                }
                else if (strOper2 == "C")
                {
                    for (j = 0; j < WhereStored.Count; j++)
                    {
                        if (WhereStored[j].SeriesID == r2)
                        {
                            ToStack = WhereStored[j].StackNumber;
                            tb.ThisColumn[ToStack].HoldMoves.Push(tb.ThisColumn[ToStack].Cards.Count);
                        }
                    }
                }
                else
                {
                    Debug.Assert(false);
                    return(false);
                }
                tb.moveto(FromStack, FromLoc, ToStack);
            }
            return(true);
        }