Beispiel #1
0
 public void CopyUpPiles(Tableau other)
 {
     for (int column = 0; column < NumberOfPiles; column++)
     {
         upPiles[column].Copy(other.upPiles[column]);
     }
     Refresh();
 }
Beispiel #2
0
 public void BlockDownPiles(Tableau other)
 {
     for (int column = 0; column < NumberOfPiles; column++)
     {
         if (other.downPiles[column].Count != 0)
         {
             downPiles[column].Add(Card.Empty);
         }
     }
 }
Beispiel #3
0
 public void Copy(Tableau other)
 {
     Clear();
     discardPiles.Copy(other.discardPiles);
     for (int column = 0; column < NumberOfPiles; column++)
     {
         upPiles[column].Copy(other.upPiles[column]);
     }
     for (int column = 0; column < NumberOfPiles; column++)
     {
         downPiles[column].Copy(other.downPiles[column]);
     }
     stockPile.Copy(other.stockPile);
     Refresh();
 }
Beispiel #4
0
 public void FromTableau(Tableau tableau)
 {
     Tableau.Variation = tableau.Variation;
     Tableau.Clear();
     foreach (Pile pile in tableau.DiscardPiles)
     {
         Tableau.DiscardPiles.Add(pile);
     }
     for (int column = 0; column < Tableau.NumberOfPiles; column++)
     {
         Tableau.DownPiles[column].Copy((tableau.DownPiles[column]));
     }
     for (int column = 0; column < Tableau.NumberOfPiles; column++)
     {
         Tableau.UpPiles[column].Copy((tableau.UpPiles[column]));
     }
     Tableau.StockPile.Copy((tableau.StockPile));
     Tableau.Refresh();
 }
Beispiel #5
0
        public static string ToPrettyString(Tableau tableau)
        {
            string s = Environment.NewLine;

            s += "   Spider";
            s += Environment.NewLine;
            s += "--------------------------------";
            s += Environment.NewLine;
            Pile discardRow = new Pile();

            for (int i = 0; i < tableau.DiscardPiles.Count; i++)
            {
                Pile discardPile = tableau.DiscardPiles[i];
                discardRow.Add(discardPile[discardPile.Count - 1]);
            }
            s += ToPrettyString(-1, discardRow);
            s += Environment.NewLine;
            s += ToPrettyString(tableau.DownPiles);
            s += Environment.NewLine;
            s += "    " + ColumnHeadings(tableau.NumberOfPiles);
            s += Environment.NewLine;
            s += ToPrettyString(tableau.UpPiles);
            s += Environment.NewLine;
            int  rowIndex = 0;
            Pile row      = new Pile();

            for (int index = tableau.StockPile.Count - 1; index >= 0; index--)
            {
                row.Add(tableau.StockPile[index]);
                if (row.Count == tableau.NumberOfPiles)
                {
                    s += ToPrettyString(rowIndex++, row);
                    row.Clear();
                }
            }
            if (row.Count != 0)
            {
                s += ToPrettyString(rowIndex, row);
            }

            return(s);
        }
Beispiel #6
0
        public static void PrintSideBySide(Tableau tableau1, Tableau tableau2)
        {
            string[] v1  = TableauInputOutput.ToPrettyString(tableau1).Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
            string[] v2  = TableauInputOutput.ToPrettyString(tableau2).Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
            int      max = 0;

            for (int i = 0; i < v1.Length; i++)
            {
                max = Math.Max(max, v1[i].Length);
            }
            string text = "";

            for (int i = 0; i < v1.Length || i < v2.Length; i++)
            {
                string s1 = i < v1.Length ? v1[i] : "";
                string s2 = i < v2.Length ? v2[i] : "";
                text += s1.PadRight(max + 1) + s2 + Environment.NewLine;
            }
            Utils.ColorizeToConsole(text);
        }
Beispiel #7
0
        public static string ToAsciiString(Tableau tableau)
        {
            Pile discardRow = new Pile();

            for (int i = 0; i < tableau.DiscardPiles.Count; i++)
            {
                Pile discardPile = tableau.DiscardPiles[i];
                discardRow.Add(discardPile[discardPile.Count - 1]);
            }

            string s = "";

            s += Fence;
            s += tableau.Variation.ToAsciiString() + PrimarySeparator;
            s += ToAsciiString(discardRow) + PrimarySeparator;
            s += ToAsciiString(tableau.DownPiles) + PrimarySeparator;
            s += ToAsciiString(tableau.UpPiles) + PrimarySeparator;
            s += ToAsciiString(tableau.StockPile);
            s += Fence;

            return(WrapString(s, 60));
        }
Beispiel #8
0
 public static void Print(Tableau tableau)
 {
     Utils.ColorizeToConsole(TableauInputOutput.ToPrettyString(tableau));
 }
Beispiel #9
0
        public void Find(Tableau tableau)
        {
            this.tableau = tableau;

            int n = tableau.NumberOfPiles;

            for (int column = 0; column < n; column++)
            {
                Pile     pile     = tableau[column];
                PileInfo pileInfo = pileInfoArray[column];
                int      m        = pile.Count;
                pileInfo.Count           = m;
                pileInfo.RunInfoArray[m] = new RunInfo(m, m, 0);
                if (m == 0)
                {
                    pileInfo.RunUpAnySuitStart  = 0;
                    pileInfo.RunUpAnySuitLength = 0;
                    continue;
                }
                if (m == 1)
                {
                    pileInfo.RunUpAnySuitStart  = 0;
                    pileInfo.RunUpAnySuitLength = 1;
                    pileInfo.RunInfoArray[0]    = new RunInfo(0, 1, 1);
                    continue;
                }

                RunInfo[] runInfoArray = pileInfo.RunInfoArray;
                int       startRow     = m - 1;
                int       endRow       = m;
                int       suits        = 1;
                Card      previousCard = pile[endRow - 1];
                for (int currentRow = m - 2; currentRow >= 0; currentRow--)
                {
                    Card currentCard = pile[currentRow];
                    if (!currentCard.IsTargetFor(previousCard))
                    {
                        break;
                    }
                    if (currentCard.Suit == previousCard.Suit)
                    {
                        startRow = currentRow;
                    }
                    else
                    {
                        RunInfo runInfo = new RunInfo(startRow, endRow, suits);
                        for (int row = startRow; row < endRow; row++)
                        {
                            runInfoArray[row] = runInfo;
                        }
                        startRow = currentRow;
                        endRow   = currentRow + 1;
                        suits++;
                    }
                    previousCard = currentCard;
                }
                {
                    RunInfo runInfo = new RunInfo(startRow, endRow, suits);
                    for (int row = startRow; row < endRow; row++)
                    {
                        runInfoArray[row] = runInfo;
                    }
                }
                pileInfo.RunUpAnySuitStart  = startRow;
                pileInfo.RunUpAnySuitLength = m - startRow;
            }
        }
Beispiel #10
0
 public void Update(Tableau tableau)
 {
     Update(tableau.UpPiles);
 }
Beispiel #11
0
 public TableauInputOutput(Tableau tableau)
 {
     Tableau = tableau;
 }
Beispiel #12
0
 public Tableau(Tableau other)
     : this()
 {
     Variation = other.Variation;
     Copy(other);
 }