private static void DisplayWinningGame() { Console.WriteLine("----------------------------"); Console.WriteLine("Deck Layout (Back to Front)"); Console.WriteLine("----------------------------"); Deck deck = Solitaire.GetWinningGame(); foreach (Card c in deck) { Console.WriteLine(" - " + c.ToString()); } }
public static Deck GetWinningGame(int rows = 7, int pick = 1) { Deck deck = new Deck(); bool winnable; do { deck.Shuffle(); Solitaire solitaire = new Solitaire(deck); solitaire.Setup(rows, pick); winnable = solitaire.CanWin(); } while (!winnable); return(deck); }
public static void Main(string[] args) { Console.WriteLine("============================"); Console.WriteLine("=== Solitaire Calculator ==="); Console.WriteLine("============================"); int numGames = 1000; string outputFile = "solitaire.csv"; Console.WriteLine("Generating " + numGames + " winning games of solitaire > " + outputFile); using (Stream s = File.Open(outputFile, FileMode.Create, FileAccess.ReadWrite, FileShare.Read)) using (StreamWriter sw = new StreamWriter(s)) { for (int i = 0; i < numGames; i++) { Deck deck = Solitaire.GetWinningGame(); for (int j = 0; j < deck.Count; j++) { Card c = deck[j]; sw.Write(c.CodeName); //sw.Write(c); if (j < deck.Count - 1) { sw.Write(","); } } sw.WriteLine(); Thread.Sleep(1); } } Console.WriteLine("Press any key to continue..."); Console.ReadKey(); }