public UnoBot(UnoGame game, UnoBehavior behavior, int index) { this.Hand = new List<UnoCard>(7); this.game = game; this.rand = new Random(); this.Index = index; this.behavior = behavior; }
public UnoBot(UnoGame game, UnoBehavior behavior, int index) { this.Hand = new List <UnoCard>(7); this.game = game; this.rand = new Random(); this.Index = index; this.behavior = behavior; }
public UnoGame(UnoBehavior[] behaviors) { int numOfPlayers = behaviors.Length; Random r = new Random(); this.deck = new UnoDeck(); this.players = new UnoBot[numOfPlayers]; this.currentTurn = r.Next(0, numOfPlayers); for (int i = 0; i < this.players.Length; i++) { this.players[i] = new UnoBot(this, behaviors[i], i); } this.DealHands(); }
public static string GetBehaviorString(UnoBehavior behavior) { string behaviorString = string.Empty; switch (behavior) { case UnoBehavior.Passive: behaviorString = "P"; break; case UnoBehavior.Aggressive: behaviorString = "A"; break; case UnoBehavior.Random: behaviorString = "R"; break; } return behaviorString; }
public static string GetBehaviorString(UnoBehavior behavior) { string behaviorString = string.Empty; switch (behavior) { case UnoBehavior.Passive: behaviorString = "P"; break; case UnoBehavior.Aggressive: behaviorString = "A"; break; case UnoBehavior.Random: behaviorString = "R"; break; } return(behaviorString); }
private static UnoBehavior[] GetPlayerBehaviors(int numOfPlayers) { UnoBehavior[] behaviors = new UnoBehavior[numOfPlayers]; System.Console.WriteLine("\n"); System.Console.WriteLine("Specify each player behavior (A = Aggressive, P = Passive, R = Random)\n"); for (int i = 0; i < behaviors.Length; i++) { System.Console.Write("Player " + i + " behavior: "); string input = Console.ReadLine().ToLower(); while (input != "a" && input != "p" && input != "r") { System.Console.WriteLine("Invalid option given!\n"); System.Console.Write("Player " + i + " behavior: "); input = Console.ReadLine().ToLower(); } switch (input) { case "a": behaviors[i] = UnoBehavior.Aggressive; break; case "p": behaviors[i] = UnoBehavior.Passive; break; case "r": behaviors[i] = UnoBehavior.Random; break; } System.Console.WriteLine(""); } return(behaviors); }
private static UnoBehavior[] GetPlayerBehaviors(int numOfPlayers) { UnoBehavior[] behaviors = new UnoBehavior[numOfPlayers]; System.Console.WriteLine("\n"); System.Console.WriteLine("Specify each player behavior (A = Aggressive, P = Passive, R = Random)\n"); for (int i = 0; i < behaviors.Length; i++) { System.Console.Write("Player " + i + " behavior: "); string input = Console.ReadLine().ToLower(); while (input != "a" && input != "p" && input != "r") { System.Console.WriteLine("Invalid option given!\n"); System.Console.Write("Player " + i + " behavior: "); input = Console.ReadLine().ToLower(); } switch(input) { case "a": behaviors[i] = UnoBehavior.Aggressive; break; case "p": behaviors[i] = UnoBehavior.Passive; break; case "r": behaviors[i] = UnoBehavior.Random; break; } System.Console.WriteLine(""); } return behaviors; }
private static void RunUnoBots(int numOfGames, UnoBehavior[] behaviors) { int numOfPlayers = behaviors.Length; int[] wins = new int[numOfPlayers]; int totalMoves = 0; long totalOfAllRunsMS = 0; Stopwatch allGamesSw = new Stopwatch(); Stopwatch eachGameSw = new Stopwatch(); allGamesSw.Start(); for (int i = 0; i < numOfGames; i++) { UnoGame game = new UnoGame(behaviors); eachGameSw.Restart(); int winner = game.Play(); eachGameSw.Stop(); wins[winner]++; totalOfAllRunsMS += eachGameSw.ElapsedMilliseconds; totalMoves += game.NumOfTurns; } allGamesSw.Stop(); System.Console.WriteLine("Total games: " + numOfGames + "\n"); Array.Sort(wins); for (int i = 0; i < wins.Length; i++) { double winRate = (double)wins[i] / (double)numOfGames; System.Console.WriteLine("Player (" + Utility.GetBehaviorString(behaviors[i]) + ") " + i + " wins: " + wins[i] + " | " + (winRate * 100) + "%"); } System.Console.WriteLine(); double avgMovesPerRound = (double)totalMoves / (double)numOfGames; double avgTimePerRound = (double)totalOfAllRunsMS / (double)numOfGames; System.Console.WriteLine("Avg moves per round: " + avgMovesPerRound); System.Console.WriteLine("Total time: " + allGamesSw.ElapsedMilliseconds + " ms"); System.Console.WriteLine("Avg time per round: " + avgTimePerRound + " ms\n"); }