public void InitializeReduction(ref board tb, ref card cNext) { int i, j = 13; tb.ReScoreBoard(); Stackables.Clear(); StackableIDs.Clear(); DoNotUse.Clear(); cNext = tb.SuitedSEQ[0].topCard; int suit = cNext.suit; foreach (series s in tb.SuitedSEQ) { DoNotUse.Add(s.iStack); // not a permanent placeholder till that card is moved (if it is moved) for (i = cNext.iCard; i <= s.bottom; i++) { column cCol = tb.ThisColumn[s.iStack]; Stackables.Add(cCol.Cards[i]); cCol.Cards[i].PartOfStackables = true; Debug.Assert(j == cCol.Cards[i].rank && suit == cCol.Cards[i].suit); j--; } cNext = s.AssemblyLink; // link to next card in "s" assembly if (cNext != null) { StackableIDs.Add(cNext.ID); } } cNext = tb.SuitedSEQ[0].topCard; }
private void ClearAnyBlocking(ref board tb, ref series s) { card cAbove; card JustMoved = s.topCard; card BottomCard = s.bottomCard; column cCol = tb.ThisColumn[JustMoved.iStack]; // we moved from here so use iStack, not fStack int iAbove = JustMoved.iCard - 1; if (iAbove < 0) { xEmpties.Add(JustMoved.iStack); } if (!BottomCard.PartOfStackables) { PlaceHolders.Add(BottomCard); // this has the updated fStack } cAbove = cCol.Cards[iAbove]; if (cAbove.PartOfStackables) { return; } if (PartOfMovables.Contains(cAbove.ID)) { return; } PlaceHolders.Add(cAbove); }
private void GetAdjacentStackables(ref card thisCard, ref column cCol, ref List <card> CardsAbove, ref List <card> CardsBelow) { int i, j; CardsBelow.Clear(); CardsAbove.Clear(); if (thisCard.iCard > cCol.top) { for (i = thisCard.iCard - 1; i >= cCol.top; i--) { for (j = 0; j < Stackables.Count; j++) { if (cCol.Cards[i] == Stackables[j]) { CardsAbove.Add(Stackables[j]); } } } } else if (thisCard.iCard != (cCol.Cards.Count - 1)) { for (i = thisCard.iCard + 1; i < cCol.Cards.Count; i++) { for (j = 0; j < Stackables.Count; j++) { if (cCol.Cards[i] == Stackables[j]) { CardsBelow.Add(Stackables[j]); } } } } }
// if true then this card (or the stack it is on) cannot be used to temporarily hold a card // during an unstack or temporary move. ie: it is either the target of the final move or is // already holding a card in an unstack operation public card(ref card oldCard, int iStack, int iCard) { ID = oldCard.ID; this.iStack = iStack; this.iCard = iCard; ExcludePlaceholder = false; }
public bool deal(int lBest, DateTime TimeOfLastDeal) { int i, n = ThisColumn[10].Cards.Count - 1; this.TimeOfLastDeal = TimeOfLastDeal; if (n < 0) { bOnLastDeal = true; return(false); } DealCounter++; utils.InitSuitCompletions(); for (i = 0; i < 10; i++) { card NewCard = new card(); NewCard = ThisColumn[10].Cards[n - i]; Debug.Assert(ThisColumn[i].Cards.Count > 0); ThisColumn[i].Cards.Add(NewCard); } ThisColumn[10].Cards.RemoveRange(n - 9, 10); bOnLastDeal = (ThisColumn[10].Cards.Count == 0); ReScoreBoard(); // replaced "lBest" with the local deal counter if (bOnLastDeal && NumEmptyColumns > 1) { score += GlobalClass.COL_WEIGHT; // nov2012 want to keep a few colums empty } MyMoves.AddMoveInfo(GlobalClass.DEALT_A_CARD, DealCountIndex, DealCounter); // 11nov2012 need to id the deal foreach (cSuitedStatus css in SuitStatus) { css.BonusExposes.Clear(); } return(true); }
private void RecoverPlaceholder(ref board tb, ref card CardExposed) { if (CardExposed != null && CardExposed.rank > 1) { PlaceHolder.Add(CardExposed); } }
public int NumUnstacksReq(card tc) { int iChange = ThisSeries.Count; // at least this many from top down // guesstimate additional change to be number of cards before the top // jys !!! return(iChange + top - tc.iCard); }
// free up a column by joining any SEQ that are joinable // or moves one suited sequence under another of proper rank // this only looks at the bottom card and tries to find an SEQ that can fit under it // of same suit public bool FreeSuitedSuits(ref board tb, ref List <card> LastSEQ) { bool bFound = false; column cCol; card Src = null; card Des = null; tb.AssignCompletedID(GlobalClass.TypeCompletedBy.ID_FSS); do { bFound = false; LastSEQ.Clear(); foreach (int e in tb.NonEmpties) { cCol = tb.ThisColumn[e]; LastSEQ.Add(cCol.ThisSeries.Last().topCard); } //LastSEQ.Sort(delegate(series s1, series s2) //{ // return Comparer<int>.Default.Compare(s1.topCard.rank, s2.topCard.rank); //}); // see if any suits can be combined foreach (card tm in tb.BottomMost) { foreach (card bm in LastSEQ) { if (tm.iStack == bm.iStack || tm.rank == 1) { continue; } if ((bm.rank + 1) == tm.rank && bm.suit == tm.suit) { bFound = true; Des = tm; Src = bm; break; } } if (bFound) { break; } } if (bFound) { tb.moveto(Src.iStack, Src.iCard, Des.iStack); tb.ReScoreBoard(); if (tb.NotifySuitJustCompleted) { tb.ExplainNoRescoreBoard("Free Suited Suits succeeded"); tb.NotifySuitJustCompleted = false; } } } while (bFound); tb.AssignCompletedID(); return(false); }
// find the sequence that contains the ExpectedRank. if more than one do the same analysis as the king private series sGetNext(ref board tb, ref List <series> SortedSEQ, int ExpectedRank, ref int cost) { series s1 = null, s2 = null; bool bFound1 = false, bFound2 = false; card c1 = null, c2 = null; column cCol; int cost1, cost2; foreach (series s in SortedSEQ) { if (s.topCard.rank >= ExpectedRank && ExpectedRank >= s.bottomCard.rank) { if (!bFound1) { s1 = s; bFound1 = true; cCol = tb.ThisColumn[s.iStack]; for (int i = s.top; i <= s.bottom; i++) { c1 = cCol.Cards[i]; if (c1.rank == ExpectedRank) { break; } } continue; } else { s2 = s; bFound2 = true; cCol = tb.ThisColumn[s.iStack]; for (int i = s.top; i <= s.bottom; i++) { c2 = cCol.Cards[i]; if (c2.rank == ExpectedRank) { break; } } break; } } } if (bFound1 && bFound2) { cost1 = s1.nEmptiesToUnstack - c1.next; cost2 = s2.nEmptiesToUnstack - c2.next; if (cost2 <= cost1) { s1 = s2; c1 = c2; } } cost = s1.nEmptiesToUnstack; s1.AssemblyLink = c1; return(s1); }
public static string ProperName(card c) { string suit = SuitNames[c.suit]; string name = CardNames[c.rank - 1] + "Of" + suit; if (c.ID > 51) { name += "1"; } return(name); }
private void RecoverPlaceholder(ref board tb, ref card CardExposed) { if (CardExposed != null && CardExposed.rank > 1) { if (!CardExposed.PartOfStackables) { PermanentPlaceHolders.Add(CardExposed); } PlaceHolders.Add(CardExposed); } }
public bool bCanDisassembleSOS(int nSubSeries, ref board tb, ref List <int> Empties, ref List <card> PlaceHolders, ref List <card> CardsToMove) { int i, j, k; int NumExpected = 0; int nEmpties = Empties.Count; for (i = DisStrategy.Count - 1; i >= 0; i--) { // going backwards we see the max empty columns before the ones requiring help if (DisStrategy[i].NumSeqSeries == nSubSeries) { if (nEmpties >= DisStrategy[i].nEmptyColumns) { // we may have sufficient resources to move the column List <int> Ranks = DisStrategy[i].Ranks; WhereStored.Clear(); NumExpected = Ranks.Count; if (NumExpected > 0) { // jys !!!! 14nov2012 I actually used j below and had two j's for (k = 0; k < Ranks.Count; k++) { int iReqFit = Ranks[k]; // the top card at the subseries iReqFit must have a place to stay card TryMove = CardsToMove[iReqFit]; for (j = 0; j < PlaceHolders.Count; j++) { if ((PlaceHolders[j].rank - 1) == TryMove.rank) { cWhereSeriesStored wss = new cWhereSeriesStored(); wss.StackNumber = PlaceHolders[j].iStack; wss.SeriesID = iReqFit; WhereStored.Add(wss); NumExpected--; if (NumExpected == 0) { return(FormMovesFromRules(i, ref tb, ref Empties, ref CardsToMove)); } } } } } else { return(FormMovesFromRules(i, ref tb, ref Empties, ref CardsToMove)); } } } } return(false); }
// if there is a card above ThisCard that is a member of the series we are trying to stack, then // ThisCard must be moved. Only king has this problem when stacking private bool bStackablesAbove(ref board tb, ref card ThisCard) { column cCol = tb.ThisColumn[ThisCard.iStack]; for (int i = ThisCard.iCard - 1; i >= cCol.top; i++) { if (cCol.Cards[i].PartOfStackables) { return(true); } } return(false); }
// remove cards in teh sCollapse series and put them all in one place, somewhere, if possible public bool TryExpose(ref series sCollapse, ref board tb) { int n = sCollapse.size; int i; card SCard = sCollapse.topCard; // this is the "S" Card with which we will be decrementing the iCard value as we move const string cstrInxVars = "ABCD"; // jys oct2012 added E string strInxvars, strPattern; column tCol = tb.ThisColumn[sCollapse.topCard.iStack]; if (n > 4) { return(false); } csosDisStrategy cds; strInxvars = cstrInxVars.Substring(0, n); AssemblePattern.Clear(); dictLookup.Clear(); //dictLookup.Add("S", SCard); // the above is not needed as we will unstack the pattern "BA" (B is actually S) to get A strPattern = AssemblePatternFrom(ref tb, ref sCollapse, strInxvars); n = strPattern.Length; if (n > 4) { return(false); // jys !!! have not created patterns bigger then 4 letters } // check first to see if we can use our empty columns for (i = 0; i < sosDisStrategy.Count; i++) { cds = sosDisStrategy[i]; if (n == cds.NumCards && cds.NumEmptyColumns <= tb.NumEmptyColumns) { if (cds.Pattern != strPattern) { continue; } if (!cds.bMustBeTop) { continue; } if (cds.Collapsible != null) { continue; // only want to use empties } sosUnstackE(ref tb, ref cds); return(true); } } return(false); }
private bool UnstackSeriesBelow(ref board tb, ref card cNext) { bool bSuccess = true; series sCollapse; column cCol = tb.ThisColumn[cNext.iStack]; int n = cCol.Cards.Count; int LastSeries = cCol.ThisSeries.Count - 1; Debug.Assert(LastSeries >= 0); if (cNext.WhichSEQSeries == LastSeries) { return(true); } // if only one to unstack then use a simple unstack if (cNext.WhichSEQSeries == (LastSeries - 1)) { series ts = cCol.ThisSeries[cNext.WhichSEQSeries]; bSuccess = UnstackOne(ref tb, ref ts); return(bSuccess); } // if more then one to unstack then try to move all of them using a pattern match sCollapse = new series(); sCollapse.bottomCard = cCol.Cards[n - 1]; sCollapse.topCard = cNext; sCollapse.tag = cNext.tag; // this is destination sCollapse.size = cCol.Cards.Count - cNext.iCard; sCollapse.iStack = cNext.iStack; if (utils.bRankable(ref sCollapse, ref tb)) { bSuccess = Disassemble.bCanUnstackCollapseable(ref sCollapse, ref tb, ref PermanentPlaceHolders); return(bSuccess); } // hmm - not rankable JYS !!! could try a simple move SOS assumeing all are sequential // if that worked then mode the ABCD pattern counf of 4 max to account for simple sequential move // and use FillDS instead of SOS // the following will work but is not optimum int TopOfSeries = cNext.WhichSEQSeries + 1; // start at bottom series, work upward for (int i = LastSeries; i >= TopOfSeries && bSuccess; i--) { series ts = cCol.ThisSeries[i]; bSuccess = UnstackOne(ref tb, ref ts); } return(bSuccess); }
public static int hasPlaceholder(ref card topCard, ref board tb, ref List <card> PlaceHolder) { foreach (card c in PlaceHolder) { if (c.ExcludePlaceholder) { continue; } if ((c.rank - 1) == topCard.rank) { c.ExcludePlaceholder = true; return(1); } } return(0); }
public card moveto(int FromStack, int FromLoc, int ToStack) { int n; card CardAbove = null; bool bWasUp = ThisColumn[FromStack].Cards[FromLoc].bFaceUp; Debug.Assert(bWasUp); n = ThisColumn[FromStack].Cards.Count - FromLoc; CardAbove = PerformMove(FromStack, FromLoc, ToStack, n); ThisColumn[FromStack].value = ThisColumn[FromStack].CalculateColumnValue(FromStack, NumEmptyColumns, BoardState()); ThisColumn[ToStack].value = ThisColumn[ToStack].CalculateColumnValue(ToStack, NumEmptyColumns, BoardState()); CalcBoardScore(); return(CardAbove); }
public List <int> PartOfMovables; // if a card is part of the movables then it cannot // be used as a placeholder until it has moved. After it has // has moved then fStack must be used, not iStack private bool IsTopMost(ref card thisCard, ref column cCol) { int i; if (thisCard.iCard == cCol.top) { return(true); } for (i = thisCard.iCard - 1; i >= cCol.top; i--) { foreach (card c in Stackables) { if (c == cCol.Cards[i]) { return(false); } } } return(true); }
// this looks for available spots to stuff a card and if it cannot find one it suggests an empty stack private int GetBestMove(ref card c, ref board tb) { int i, n; int iSameSuit = -1; int iAnySuit = -1; int ToStack = -1; List <card> PlaceHolder = PermanentPlaceHolders; if (c.PartOfStackables) { PlaceHolder = PlaceHolders; } n = PlaceHolder.Count; for (i = 0; i < n; i++) { if (PlaceHolder[i].rank - 1 == c.rank) { if (PlaceHolder[i].suit == c.suit) { iSameSuit = i; ToStack = PlaceHolder[i].iStack; PlaceHolder.RemoveAt(i); StackableIDs.Remove(c.ID); break; } iAnySuit = i; } } if (iAnySuit < 0 && iSameSuit < 0) { return(-1); // signal to use an empty column } if (iSameSuit >= 0) { return(ToStack); } ToStack = PlaceHolder[iAnySuit].iStack; PlaceHolder.RemoveAt(iAnySuit); return(ToStack); }
// note that PlaceHolders is modified: a card is removed // this looks for available spots to stuff a card and if it cannot find one it suggests an empty stack public static int GetBestMove(card c, ref board tb, ref List <card> PlaceHolder) { int i, n; int iSameSuit = -1; int iAnySuit = -1; int ToStack = -1; n = PlaceHolder.Count; for (i = 0; i < n; i++) { if (PlaceHolder[i].ExcludePlaceholder) { continue; // cannot use this } if (PlaceHolder[i].rank - 1 == c.rank) { if (PlaceHolder[i].suit == c.suit) { iSameSuit = i; ToStack = PlaceHolder[i].iStack; PlaceHolder.RemoveAt(i); break; } iAnySuit = i; } } if (iAnySuit < 0 && iSameSuit < 0) { return(-1); // signal to use an empty column } if (iSameSuit >= 0) { return(ToStack); } ToStack = PlaceHolder[iAnySuit].iStack; PlaceHolder.RemoveAt(iAnySuit); return(ToStack); }
public int RemoveCompletedSuit(int iCol) { column tc = ThisColumn[iCol]; int i, j, n = tc.ThisSeries.Count - 1; int suit = tc.ThisSeries[n].sSuit; Debug.Assert(n >= 0); j = tc.ThisSeries[n].bottom; // position of last card in last series Debug.Assert(j == tc.Cards.Count - 1); // should always be last card // instead of deleting 13 cards from location top // we will move 13 cards from the bottom of the stack to stack 11 (12th stack) for (i = 0; i < 13; i++) { card c = tc.Cards[j - i]; ThisColumn[11].Cards.Add(c); } tc.Cards.RemoveRange(tc.ThisSeries[n].top, 13); n = tc.Cards.Count - 1; if (n >= 0) { tc.Cards[n].bFaceUp = true; } return(suit); }
// this looks for available spots to stuff a card and if it cannot find one it suggests an empty stack // this is different than the one in strategy because it can use the default BottomMost. This is true // because we are leaving the list unchanged. private int GetBestMove(card c, ref board tb) { int i, n; int iSameSuit = -1; int iAnySuit = -1; int ToStack = -1; n = tb.BottomMost.Count; for (i = 0; i < n; i++) { if (tb.BottomMost[i].ExcludePlaceholder) { continue; // cannot use this } if (tb.BottomMost[i].rank - 1 == c.rank) { if (tb.BottomMost[i].suit == c.suit) { iSameSuit = i; ToStack = tb.BottomMost[i].iStack; break; } iAnySuit = i; } } if (iAnySuit < 0 && iSameSuit < 0) { return(-1); // signal to use an empty column } if (iSameSuit >= 0) { return(ToStack); } ToStack = tb.BottomMost[iAnySuit].iStack; return(ToStack); }
// same as above JSS but does not consume any empty columns // the ranks must be in order (rankable under the series) and the gap above both top cards must be 1 // this routine can be called at any time after building a sorted sequence (BuildSEQ) of any number of suits public bool JoinSuitedWhenRankable(ref board tb) { if (cSC.bTrigger) { Console.WriteLine(MethodBase.GetCurrentMethod().Name); } series sDes, sSrc; series uDes; // the unstacked part of the destination int PossibleCostReduction; int RankWanted, LowestRank, RankWantedLoc; PsuedoMoveList.Clear(); tb.BuildPlaceholders(ref PlaceHolder); //foreach (series s1 in tb.SortedSEQ) for (int i = 0; i < tb.SortedSEQ.Count - 1; i++) { sDes = tb.SortedSEQ[i]; // biggest is first in sorted order of ranks if (sDes.topCard.GapAbove != 1 || sDes.pattern == "") { continue; } // only want reversible moves for swapping purposes // and there must be a pattern of else the series is not rankable PossibleCostReduction = sDes.bRankable ? utils.hasPlaceholder(ref sDes.topCard, ref tb, ref PlaceHolder) : 0; //foreach (series s2 in tb.SortedSEQ) for (int j = i + 1; j < tb.SortedSEQ.Count; j++) { sSrc = tb.SortedSEQ[j]; if (sSrc.topCard.GapAbove != 1 || sSrc.pattern == "") { continue; } if (sSrc.sSuit != sDes.sSuit) { continue; // in event more then one suit is in the sorted list } PossibleCostReduction += sSrc.bRankable ? utils.hasPlaceholder(ref sSrc.topCard, ref tb, ref PlaceHolder) : 0; utils.FreeExcludedPlaceholders(ref PlaceHolder); // done with our PossibleCostReduction // the 0 below represents possibly a single available placeholder ie; we assume NONE here if (sDes.nEmptiesToUnstack + sSrc.nEmptiesToUnstack > (tb.NumEmptyColumns + PossibleCostReduction + 0)) { return(false); } if (sDes.iStack == sSrc.iStack) { continue; } // make s1 (bottom) the destination and s2 (top) the source (ranks must be different) if (sDes.topCard.rank == sSrc.topCard.rank) { continue; // nothing to join } // 9..6 could join to 6..3 by moveing only the 5..3 if it exists RankWanted = sDes.bottomCard.rank - 1; // find a card in source to be mvoed that is this rank LowestRank = sSrc.bottomCard.rank; if (!(RankWanted > LowestRank && sSrc.topCard.rank >= RankWanted)) { continue; } // figure out where that card is in the source to be moved RankWantedLoc = sSrc.top + (1 + sSrc.topCard.rank - sDes.bottomCard.rank); card cSrc = tb.ThisColumn[sSrc.iStack].Cards[RankWantedLoc]; Debug.Assert(RankWanted == cSrc.rank); sSrc.size -= (1 + sSrc.topCard.rank - sDes.bottomCard.rank); sSrc.topCard = cSrc; sSrc.top = cSrc.iCard; if (sSrc.nEmptiesToUnstack == 0 && sDes.nEmptiesToUnstack == 0) { tb.moveto(cSrc.iStack, cSrc.iCard, sDes.bottomCard.iStack); return(true); } //pseudoCard pCard = new pseudoCard(sDes.topCard.ID, sSrc.bottomCard.ID, true); //PsuedoMoveList.Insert(0, pCard); uDes = null; if (sDes.nEmptiesToUnstack > 0) { uDes = sDes.NextSeries; uDes.tag = sSrc.iStack; // after moveing sSrc put the unstack from Des where Src came from // the above works because the algorithm only moves rankables that are in order // so as to not consume a stack. the tag is not updated by any move card operation if (!MoveSeriesBelow(ref tb, ref sDes)) { return(false); } uDes.iStack = tb.tag; // series locations are NOT updated by any cards that are moved // uDes.iStack is where the unstacked stuff was stashed tb.tag = uDes.tag; // cannot use sSrc.iStack since Src was moved } tb.tag = sDes.iStack; bool bAny = cSC.Suitable.Disassemble.MoveCollapsible(ref sSrc, ref tb); if (!bAny) { return(false); } if (uDes == null) { return(true); } tb.tag = uDes.tag; bAny = cSC.Suitable.Disassemble.MoveCollapsible(ref uDes, ref tb); return(bAny); } } return(false); }
// dont call this unless it was sorted by rank // this does not handle card subsets that are in the same column public bool JoinAnyLikeSuits(ref board tb) { if (cSC.bTrigger) { Console.WriteLine(MethodBase.GetCurrentMethod().Name); } series sDes, sSrc; int PossibleCostReduction; int RankWanted, LowestRank, RankWantedLoc; PsuedoMoveList.Clear(); //foreach (series s1 in tb.SortedSEQ) for (int i = 0; i < tb.SortedSEQ.Count - 1; i++) { sDes = tb.SortedSEQ[i]; // biggest is first in sorted order of ranks PossibleCostReduction = sDes.bRankable ? 1 : 0; //foreach (series s2 in tb.SortedSEQ) for (int j = i + 1; j < tb.SortedSEQ.Count; j++) { sSrc = tb.SortedSEQ[j]; if (sSrc.sSuit != sDes.sSuit) { continue; // in event more then one suit is in the sorted list } PossibleCostReduction += sSrc.bRankable ? 1 : 0; // the 1 below represents possibly a single available placeholder if (sDes.nEmptiesToUnstack + sSrc.nEmptiesToUnstack > (tb.NumEmptyColumns + 1 + PossibleCostReduction)) { return(false); } if (sDes.iStack == sSrc.iStack) { continue; } // make s1 (bottom) the destination and s2 (top) the source (ranks must be different) if (sDes.topCard.rank == sSrc.topCard.rank) { continue; // nothing to join } // 9..6 could join to 6..3 by moveing only the 5..3 if it exists RankWanted = sDes.bottomCard.rank - 1; // find a card in source to be mvoed that is this rank LowestRank = sSrc.bottomCard.rank; if (!(RankWanted > LowestRank && sSrc.topCard.rank >= RankWanted)) { continue; } // figure out where that card is in the source to be moved RankWantedLoc = sSrc.top + (1 + sSrc.topCard.rank - sDes.bottomCard.rank); card cSrc = tb.ThisColumn[sSrc.iStack].Cards[RankWantedLoc]; Debug.Assert(RankWanted == cSrc.rank); sSrc.size -= (1 + sSrc.topCard.rank - sDes.bottomCard.rank); sSrc.topCard = cSrc; sSrc.top = cSrc.iCard; if (sSrc.nEmptiesToUnstack == 0 && sDes.nEmptiesToUnstack == 0) { tb.moveto(cSrc.iStack, cSrc.iCard, sSrc.bottomCard.iStack); return(true); } pseudoCard pCard = new pseudoCard(sDes.topCard.ID, sSrc.bottomCard.ID, true); PsuedoMoveList.Insert(0, pCard); if (sSrc.nEmptiesToUnstack > 0) { if (!UnstackBelow(ref sSrc)) { return(false); } } if (sDes.nEmptiesToUnstack > 0) { if (!UnstackBelow(ref sDes)) { return(false); } } return(JoinPsudos()); } } return(false); }
public cPotentialExpose(ref card cPlaceholder, ref card cCardBlocking) { Placeholder = cPlaceholder; CardBlocking = cCardBlocking; }
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); }
public cCardCountMoves(ref card nc, int nn) { c = nc; n = nn; }
public bool ReduceSuits(ref board oldtb) { bool bSuccess = true; card cNext = null; card ExposedCard = null; int e, CardID, LastID; card CardExposed; board tb = new board(ref oldtb); tb.AssignCompletedID(GlobalClass.TypeCompletedBy.ID_RSI); OnCounter++; InitializeReduction(ref tb, ref cNext); Debug.Assert(cNext.rank == 13); GetPlaceholders(ref tb, cNext.iStack); if (bStackablesAbove(ref tb, ref cNext)) { bSuccess = UnstackSeriesBelow(ref tb, ref cNext); if (bSuccess) { e = tb.Empties[0]; tb.Empties.RemoveAt(0); CardExposed = tb.moveto(cNext.iStack, cNext.iCard, e); // have to move the king RecoverPlaceholder(ref tb, ref CardExposed); tb.tag = e; InitializeReduction(ref tb, ref cNext); } else { tb.AssignCompletedID(); return(false); // jys !!! may want to try a second or lower ranked card } } else { tb.tag = cNext.iStack; GetPlaceholders(ref tb, tb.tag); } // unstack below the last card (cNext) and the next card while (bSuccess) { bSuccess = UnstackSeriesBelow(ref tb, ref cNext); if (bSuccess) { if (StackableIDs.Count > 0) { CardID = StackableIDs[0]; // next card to gather in StackableIDs.RemoveAt(0); LastID = cNext.ID; cNext = utils.FindCardFromID(ref tb, CardID); bSuccess = UnstackSeriesBelow(ref tb, ref cNext); if (bSuccess) { ExposedCard = tb.moveto(cNext.iStack, cNext.iCard, tb.tag); RecoverPlaceholder(ref tb, ref ExposedCard); } else { tb.AssignCompletedID(); return(false); } } else { tb.ReScoreBoard(); cSC.Suitable.PerformSuitabilityScreening(ref tb); if (tb.bIsCompletable) { cSC.NextBoardSeries.Add(tb); } else { cSC.ThisBoardSeries.Add(tb); } tb.AssignCompletedID(); return(true); } } else { tb.AssignCompletedID(); return(false); } } tb.AssignCompletedID(); return(false); }
public cAssemblePattern(ref card c, int index) { this.c = c; this.index = index; }
public cMoveOrder(ref card iFrom) { From = iFrom; }