static void Main(string[] args) { IBlackjackGame game = new BlackjackGame(); game.Setup(); game.Play(); }
static void Main(string[] args) { //BlackjackSettings settings = SaveDefaultSettings(); BlackjackSettings settings = LoadSettingsFromFile("settings.xml"); BlackjackGame game = new BlackjackGame(settings); //ConsoleBlackjackPlayer player = new ConsoleBlackjackPlayer() { Game = game }; var handsToPlay = 100000000L; var player = new BasicStrategyPlayer(handsToPlay); game.Play(new [] { player }); Console.WriteLine("Profit: {0}%", Math.Round((player.Profit / settings.MinimumBet / (decimal)handsToPlay) * 100m, 2)); }
static void Main(string[] args) { BlackjackSettings settings = LoadSettingsFromFile("settings.xml"); BlackjackGame game = new BlackjackGame(settings); var handsToPlay = 100000000L; //BasicStrategyPlayer basic = new BasicStrategyPlayer(handsToPlay); //var table = ActionTable.FromStrategy(basic); //var player = basic; //var player = new ConsoleBlackjackPlayer() { Game = game }; //var player = new WizardSimpleStrategy(handsToPlay); //var player = new ActionTablePlayer(table, handsToPlay) { Print = true }; var player = new SimpleFiveCountPlayer(handsToPlay); game.Play(new [] { player }); Console.WriteLine("Profit: {0:N2}%", player.Profit / settings.MinimumBet / (decimal)handsToPlay * 100m); }
static void Main(string[] args) { Console.WriteLine("Welcome to the Grand Hotel and Casino. Please tell me your name."); string playerName = Console.ReadLine(); if (playerName.ToLower() == "admin") { List <ExceptionEntity> Exceptions = ReadExceptions(); foreach (var exception in Exceptions) { Console.Write(exception.Id + " | "); Console.Write(exception.ExceptionType + " | "); Console.Write(exception.ExceptionMessage + " | "); Console.Write(exception.TimeStamp + " | "); Console.WriteLine(); } Console.ReadLine(); return; } bool valid = false; int bank = 0; while (!valid) { Console.WriteLine("What is your buy-in?"); valid = int.TryParse(Console.ReadLine(), out bank); if (!valid) { Console.WriteLine("Please enter a whole number using digits only."); Console.ReadLine(); } } Console.WriteLine("Blackjack table changing $" + bank + "!!!!"); Console.WriteLine("Hello, {0}. Shall we begin?", playerName); string answer = Console.ReadLine().ToLower(); if (answer == "yes" || answer == "yep" || answer == "sure" || answer == "yeah" || answer == "y") { Player player = new Player(playerName, bank); Game game = new BlackjackGame(); game += player; player.isActivelyPlaying = true; while (player.isActivelyPlaying && player.Balance > 0) { try { game.Play(); } catch (FraudException ex) { Console.WriteLine(ex.Message); UpdateDbWithException(ex); Console.ReadLine(); return; } catch (Exception ex) { Console.WriteLine("An error occurred, please contact your system administrator."); UpdateDbWithException(ex); Console.ReadLine(); return; } } game -= player; Console.WriteLine("Thank you for playing."); } Console.WriteLine("Feel free to look around the casino. Goodbye for now."); Console.ReadLine(); }
static void Main(string[] args) { //========== CASINO NAME const string casinoName = "Grand Hotel and Casino"; //========== LOG FILE string logDir = Directory.GetCurrentDirectory() + @"\logs"; string logFile = logDir + @"\log.txt"; if (!Directory.Exists(logDir)) { Directory.CreateDirectory(logDir); } string logTxt = string.Format("========== BLACKJACK LOG ==========\n{0}\n", DateTime.Now); File.WriteAllText(logFile, logTxt); //========== GAME SETUP Console.BackgroundColor = ConsoleColor.DarkGreen; Console.ForegroundColor = ConsoleColor.Yellow; Console.Clear(); Console.WriteLine("\n===================================================\n=====( Welcome to the {0} )=====\n===================================================\n", casinoName); Game game = new BlackjackGame(); //========== ADD PLAYERS const int maxPlayers = 7; bool addPlayers = true; string playerName; while (addPlayers && game.Players.Count < maxPlayers) { Console.WriteLine("\nPlayer, what is your name?"); playerName = Console.ReadLine(); playerName = playerName[0].ToString().ToUpper() + playerName.Substring(1); //===== ADMIN ENTRY if (playerName == "Admin") { List <ExceptionEntity> exceptions = ReadExceptions(); foreach (var e in exceptions) { Console.Write(e.Id + " | "); Console.Write(string.Format("{0} | ", e.ExceptionType)); Console.Write(string.Format("{0} | ", e.ExceptionMessage)); Console.WriteLine(string.Format("{0} \n", e.TimeStamp)); } Console.Read(); return; } //===== PLAYER ENTRY Player player = new Player(playerName); // asks for player bank if not provided if (player.Balance > 0) { Console.WriteLine("Hello {0}. Would you like to join a game of Blackjack right now?", playerName); if (Console.ReadLine().ToLower().Contains("y")) { game += player; Console.WriteLine("-->{0} added to game.", playerName); } } if (game.Players.Count < maxPlayers) { Console.WriteLine("\nIs someone else joining today?"); if (Console.ReadLine().ToLower().Contains("n")) { addPlayers = false; } } } //========== PLAY - continue to play rounds until NO players are actively playing or have a balance > 0 while (game.Players.Count > 0) { //----- Play game try { game.Play(); } catch (FraudException e) { UpdateDbException(e); Console.WriteLine("SECURITY! Throw this person out."); Console.ReadLine(); return; } catch (Exception e) { UpdateDbException(e); Console.WriteLine("ERROR. Please contact your system administrator."); Console.WriteLine("ERROR: " + e.Message); Console.ReadLine(); return; } //----- Player removal List <Player> removals = new List <Player>(); removals = game.Players.Where(x => !x.ActivelyPlaying || x.Balance == 0).ToList(); foreach (Player player in removals) { game -= player; } } //========== GAME OVER Console.WriteLine("\n===Thank you for playing."); Console.WriteLine("Feel free to look aroung the casino. Bye for now."); //========== TESTS ========== //string str1 = "Here is some text.\nMore on a new line.\tHere is some after a tab."; //File.WriteAllText(logFile, str1); //string txt = File.ReadAllText(logFile); //Console.WriteLine(txt); //===== CREATE DECK //Deck deck = new Deck(); //===== SHUFFLE DECK //deck.Shuffle(times: 4, true); //===== lambda functions //int count = deck.Cards.Count(x => x.Face == Face.Ace); //Console.WriteLine(count); //List<Card> newList = deck.Cards.Where(x => x.Face == Face.Ace).ToList(); //foreach (Card card in newList) { Console.WriteLine(card.Face); } //List<int> numList = new List<int>() { 1,2,3,535,342,23 }; //int sum = numList.Sum(); //Console.WriteLine(sum); //int sumPlus = numList.Sum(x => x + 1); //Console.WriteLine(sumPlus); //int max = numList.Max(); //Console.WriteLine(max); //int min = numList.Min(); //Console.WriteLine(min); //int sumBig = numList.Where(x => x > 100).Sum(); //Console.WriteLine(sumBig); //Console.WriteLine(numList.Where(x => x > 100).Sum()); //===== Overloaded operator //Game game = new BlackjackGame() { Name = "BlackJack", Dealer = "Doc Holliday", Players = new List<Player>() }; //Player p1 = new Player() { Name = "Wyatt Earp" }; //Player p2 = new Player() { Name = "Jesse James" }; //game = game + p1 + p2; //game.ListPlayers(); //game = game - p2; //game.ListPlayers(); //deck.ListCards(loop: "foreach"); //Dealer dealer = new Dealer(); //dealer.Name = "Alex"; //Console.WriteLine(dealer.Name); // can get/set public properties when base class is not explicitly public //Game game2 = new Game(); // can't create a new object based on an abstract class //===== HOLD OPEN - till enter is pressed Console.ReadLine(); }
static void Main() { // Welcome message Console.WriteLine("LET'S PLAY BLACKJACK!\n"); // Get player name Console.WriteLine("Please Enter Your Name:"); string playerName = Console.ReadLine(); if (playerName.ToLower() == "admin") { List <ExceptionEntity> Exceptions = ReadExceptions(); foreach (var exception in Exceptions) { Console.Write(exception.Id + " | "); Console.Write(exception.ExceptionType + " | "); Console.Write(exception.ExceptionMessage + " | "); Console.Write(exception.TimeStamp + " | "); Console.WriteLine(); } Console.Read(); return; } // Get player starting amount bool validAnswer = false; int purse = 0; while (!validAnswer) { Console.WriteLine("\nHow much money are you starting with?"); Console.Write("$"); validAnswer = int.TryParse(Console.ReadLine(), out purse); if (!validAnswer) { Console.WriteLine("Please enter a whole number"); } } // Ask to start game Console.WriteLine("\nHello, {0}! \nReady to get started? (y or n)", playerName); string ready = Console.ReadLine().ToLower(); // Initialize game if player is ready if (ready == "yes" || ready == "y") { // Create new player object Player player = new Player(playerName, purse); player.ID = Guid.NewGuid(); using (StreamWriter file = new StreamWriter(@"C:\Users\daved\Desktop\log.txt", true)) { file.WriteLine(player.ID); } //Create new game object Game game = new BlackjackGame(); // Add player to list of game players game += player; // Set player's playing status to "Active" player.IsActive = true; // Skip a line for presentation Console.WriteLine(); // Start game loop and continue until player quits or runs out of money while (player.IsActive && player.Balance > 0) { try { game.Play(); } catch (FraudException ex) { Console.WriteLine(ex.Message); UpdateDbWithException(ex); return; } catch (Exception ex) { Console.WriteLine("Something went wrong."); UpdateDbWithException(ex); return; } } // Remove player from list of game players when done game -= player; // Ending message Console.WriteLine("Thanks for playing!"); } // Goodbye message and end of program Console.WriteLine("Please come back when you are ready to play."); Console.Read(); }