public override IEnumerable<SingleGameResult> SimulateGames(Assembly firstAssembly, Assembly secondAssembly, int count) { // TODO: Decorate with time and memory limit // TODO: What if someone crashes? var firstPlayer = this.LoadPlayer<IPlayer>(firstAssembly); var secondPlayer = this.LoadPlayer<IPlayer>(secondAssembly); var gameResults = new List<SingleGameResult>(); for (var i = 0; i < count; i++) { var game = new SantaseGame(firstPlayer, secondPlayer); var firstToPlay = i % 2 == 0 ? PlayerPosition.FirstPlayer : PlayerPosition.SecondPlayer; var stopwatch = Stopwatch.StartNew(); var gameWinner = game.Start(firstToPlay); var elapsed = stopwatch.Elapsed; var report = $"First: {firstToPlay}; Result: {game.FirstPlayerTotalPoints} - {game.SecondPlayerTotalPoints} (in {game.RoundsPlayed} rounds) Time: {elapsed}"; var gameResult = new SingleGameResult( gameWinner == PlayerPosition.FirstPlayer ? BattleGameWinner.First : BattleGameWinner.Second, report); gameResults.Add(gameResult); } return gameResults; }
private int SimulateGamesAndGetSmartPlayerWins(int gamesToSimulate) { var smartPlayer = new SmartPlayer(); var smartPlayerWins = 0; var dummyPlayer = new DummyPlayer(); var game = new SantaseGame(smartPlayer, dummyPlayer); for (var i = 0; i < gamesToSimulate; i++) { var winner = game.Start(i % 2 == 0 ? PlayerPosition.FirstPlayer : PlayerPosition.SecondPlayer); if (winner == PlayerPosition.FirstPlayer) { smartPlayerWins++; } } // Console.WriteLine(smartPlayerWins); return smartPlayerWins; }
public void WinnersShouldBeEquallyDistributed() { const int GamesToPlay = 200; var firstPlayer = new ValidPlayerWithMethodsCallCounting(); var secondPlayer = new ValidPlayerWithMethodsCallCounting(); var firstPlayerWinner = 0; var secondPlayerWinner = 0; for (var i = 0; i < GamesToPlay; i++) { var firstToPlay = i % 2 == 0 ? PlayerPosition.FirstPlayer : PlayerPosition.SecondPlayer; var game = new SantaseGame(firstPlayer, secondPlayer); var winner = game.Start(firstToPlay); if (winner == PlayerPosition.FirstPlayer) { firstPlayerWinner++; } else if (winner == PlayerPosition.SecondPlayer) { secondPlayerWinner++; } } Assert.AreEqual(GamesToPlay, firstPlayerWinner + secondPlayerWinner); Assert.IsTrue(Math.Abs(firstPlayerWinner - secondPlayerWinner) < 150); }
protected override ISantaseGame CreateGame() { IPlayer firstPlayer = new HelionPlayer(); IPlayer secondPlayer = new SmartPlayer(); ISantaseGame game = new SantaseGame(firstPlayer, secondPlayer); return game; }
protected override ISantaseGame CreateGame() { IPlayer firstPlayer = new DummyPlayer("First Dummy Player"); IPlayer secondPlayer = new DummyPlayer("Second Dummy Player"); ISantaseGame game = new SantaseGame(firstPlayer, secondPlayer); // new ConsoleLogger("[game] ")); return(game); }
// ReSharper disable once UnusedMember.Local private static ISantaseGame CreateGameVersusBot() { IPlayer firstPlayer = new ConsolePlayer(5, 10); IPlayer secondPlayer = new SmartPlayer(); ISantaseGame game = new SantaseGame(firstPlayer, secondPlayer); return(game); }
// ReSharper disable once UnusedMember.Local private static ISantaseGame CreateTwoPlayerGame() { IPlayer firstPlayer = new ConsolePlayer(5, 10); IPlayer secondPlayer = new ConsolePlayer(10, 10); ISantaseGame game = new SantaseGame(firstPlayer, secondPlayer); return(game); }
protected override ISantaseGame CreateGame() { IPlayer firstPlayer = new SmartPlayer(); IPlayer secondPlayer = new DummyPlayerChangingTrump(); ISantaseGame game = new SantaseGame(firstPlayer, secondPlayer); // new ConsoleLogger("[game] ")); return(game); }
protected override ISantaseGame CreateGame() { IPlayer firstPlayer = new TFirstPlayer(); IPlayer secondPlayer = new TSecondPlayer(); ISantaseGame game = new SantaseGame(firstPlayer, secondPlayer); return(game); }
protected override ISantaseGame CreateGame() { IPlayer firstPlayer = new SmartPlayer(); // new PlayerWithLoggerDecorator(new SmartPlayer(), new ConsoleLogger("[-]")) IPlayer secondPlayer = new SantiagoPlayer(); ISantaseGame game = new SantaseGame(firstPlayer, secondPlayer); // new ConsoleLogger("[game] ")); return(game); }
public void StartGameShouldReturnOneOfThePlayersAsWinner() { var firstPlayer = new ValidPlayerWithMethodsCallCounting(); var secondPlayer = new ValidPlayerWithMethodsCallCounting(); var game = new SantaseGame(firstPlayer, secondPlayer); var winner = game.Start(); Assert.IsTrue(winner != PlayerPosition.NoOne); }
// ReSharper disable once UnusedMember.Local private static ISantaseGame CreateGameVersusBot() { Console.BufferHeight = Console.WindowHeight = 17; Console.BufferWidth = Console.WindowWidth = 50; IPlayer firstPlayer = new SmartPlayer(); IPlayer secondPlayer = new SmartPlayer(); ISantaseGame game = new SantaseGame(firstPlayer, secondPlayer); return game; }
// ReSharper disable once UnusedMember.Local private static ISantaseGame CreateTwoPlayerGame() { Console.BufferHeight = Console.WindowHeight = 17; Console.BufferWidth = Console.WindowWidth = 50; IPlayer firstPlayer = new ConsolePlayer(5, 10); IPlayer secondPlayer = new ConsolePlayer(10, 10); ISantaseGame game = new SantaseGame(firstPlayer, secondPlayer); return game; }
// ReSharper disable once UnusedMember.Local private static ISantaseGame CreateGameVersusBot() { Console.BufferHeight = Console.WindowHeight = 17; Console.BufferWidth = Console.WindowWidth = 50; IPlayer firstPlayer = new ConsolePlayer(5, 10); IPlayer secondPlayer = new ELRumDrinkingCapitanPlayer(); ISantaseGame game = new SantaseGame(firstPlayer, secondPlayer); return game; }
// ReSharper disable once UnusedMember.Local private static ISantaseGame CreateGameVersusBot() { Console.BufferHeight = Console.WindowHeight = 17; Console.BufferWidth = Console.WindowWidth = 50; IPlayer firstPlayer = new ConsolePlayer(5, 10); IPlayer secondPlayer = new SantiagoPlayer(); ISantaseGame game = new SantaseGame(firstPlayer, secondPlayer); return(game); }
public void PlayersMethodsShouldBeCalledCorrectNumberOfTimes() { const int GamesToPlay = 200; var firstPlayer = new ValidPlayerWithMethodsCallCounting(); var secondPlayer = new ValidPlayerWithMethodsCallCounting(); for (var i = 0; i < GamesToPlay; i++) { var firstToPlay = i % 2 == 0 ? PlayerPosition.FirstPlayer : PlayerPosition.SecondPlayer; var game = new SantaseGame(firstPlayer, secondPlayer); game.Start(firstToPlay); } // StartGame() Assert.AreEqual(GamesToPlay, firstPlayer.StartGameCalledCount); Assert.AreEqual(GamesToPlay, secondPlayer.StartGameCalledCount); // EndGame() Assert.AreEqual(GamesToPlay, firstPlayer.EndGameCalledCount); Assert.AreEqual(GamesToPlay, secondPlayer.EndGameCalledCount); // StartRound() Assert.GreaterOrEqual( firstPlayer.StartRoundCalledCount, 4 * GamesToPlay, "Not started at least 4 rounds per game for the first player"); Assert.GreaterOrEqual( secondPlayer.StartRoundCalledCount, 4 * GamesToPlay, "Not started at least 4 rounds per game for the second player"); // EndRound() Assert.GreaterOrEqual( firstPlayer.EndRoundCalledCount, GamesToPlay * 4, "Not ended at least 4 rounds per game for the first player"); Assert.GreaterOrEqual( secondPlayer.EndRoundCalledCount, GamesToPlay * 4, "Not ended at least 4 rounds per game for the second player"); // GetTurn() and EndTurn() Assert.IsTrue(firstPlayer.GetTurnWhenFirst > GamesToPlay * 10); Assert.IsTrue(firstPlayer.GetTurnWhenSecond > GamesToPlay * 10); Assert.IsTrue(firstPlayer.EndTurnCalledCount > GamesToPlay * 10); Assert.IsTrue(secondPlayer.GetTurnWhenFirst > GamesToPlay * 10); Assert.IsTrue(secondPlayer.GetTurnWhenSecond > GamesToPlay * 10); Assert.IsTrue(secondPlayer.EndTurnCalledCount > GamesToPlay * 10); }
public MainPage() { this.InitializeComponent(); if (AnalyticsInfo.VersionInfo.DeviceFamily == "Windows.Desktop") { this.AdRow.Height = new GridLength(90); // this.AdMediator_2D55AF.Height = 90; // this.AdMediator_2D55AF.Width = 768; } else { this.AdRow.Height = new GridLength(80); // this.AdMediator_2D55AF.Height = 80; // this.AdMediator_2D55AF.Width = 480; } this.playerCardControls = new[] { this.PlayerCard1, this.PlayerCard2, this.PlayerCard3, this.PlayerCard4, this.PlayerCard5, this.PlayerCard6 }; this.uiPlayer = new UiPlayer(); this.uiPlayer.RedrawCards += this.UiPlayerRedrawCards; this.uiPlayer.RedrawTrumpCard += this.UiPlayerRedrawTrumpCard; this.uiPlayer.RedrawNumberOfCardsLeftInDeck += this.UiPlayerOnRedrawNumberOfCardsLeftInDeck; this.uiPlayer.RedrawPlayerPlayedCard += this.UiPlayerOnRedrawPlayerPlayedCard; this.uiPlayer.RedrawOtherPlayerPlayedCard += this.UiPlayerOnRedrawOtherPlayerPlayedCard; this.uiPlayer.RedrawCurrentAndOtherPlayerRoundPoints += this.UiPlayerOnRedrawCurrentAndOtherPlayerRoundPoints; this.uiPlayer.RedrawCurrentAndOtherPlayerTotalPoints += this.UiPlayerOnRedrawCurrentAndOtherPlayerTotalPoints; this.uiPlayer.RedrawPlayedCards += this.UiPlayerOnRedrawPlayedCards; this.uiPlayer.GameClosed += this.UiPlayerOnGameClosed; this.uiPlayer.GameEnded += this.UiPlayerOnGameEnded; IPlayer smartPlayer = new SmartPlayer(); this.game = new SantaseGame(this.uiPlayer, smartPlayer); this.PlayerCard.Transparent(); this.OldPlayerCard.Transparent(); this.OtherPlayerCard.Transparent(); this.OldOtherPlayerCard.Transparent(); Task.Run(() => this.game.Start()); }
public static void Main() { Console.BufferHeight = Console.WindowHeight = 17; Console.BufferWidth = Console.WindowWidth = 50; ISantaseGame game = new SantaseGame( new ConsolePlayer(5, 10), new ConsolePlayer(10, 10), PlayerPosition.FirstPlayer); game.Start(); Console.WriteLine("Game finished!"); Console.WriteLine("{0} - {1}", game.FirstPlayerTotalPoints, game.SecondPlayerTotalPoints); Console.WriteLine("Round: {0}", game.RoundsPlayed); }
public MainPage() { this.InitializeComponent(); this.ProgramVersion.Text = "Santase v2.0"; this.InitializeAdControl(); this.resultPersister = new TotalResultPersister(); this.TotalResult.Text = $"{this.resultPersister.PlayerScore}-{this.resultPersister.OtherPlayerScore}"; this.playerCardControls = new[] { this.PlayerCard1, this.PlayerCard2, this.PlayerCard3, this.PlayerCard4, this.PlayerCard5, this.PlayerCard6, }; this.uiPlayer = new UiPlayer(); this.uiPlayer.RedrawCards += this.UiPlayerRedrawCards; this.uiPlayer.RedrawTrumpCard += this.UiPlayerRedrawTrumpCard; this.uiPlayer.RedrawNumberOfCardsLeftInDeck += this.UiPlayerOnRedrawNumberOfCardsLeftInDeck; this.uiPlayer.RedrawPlayerPlayedCard += this.UiPlayerOnRedrawPlayerPlayedCard; this.uiPlayer.RedrawOtherPlayerPlayedCard += this.UiPlayerOnRedrawOtherPlayerPlayedCard; this.uiPlayer.RedrawCurrentAndOtherPlayerRoundPoints += this.UiPlayerOnRedrawCurrentAndOtherPlayerRoundPoints; this.uiPlayer.RedrawCurrentAndOtherPlayerTotalPoints += this.UiPlayerOnRedrawCurrentAndOtherPlayerTotalPoints; this.uiPlayer.RedrawPlayedCards += this.UiPlayerOnRedrawPlayedCards; this.uiPlayer.GameClosed += this.UiPlayerOnGameClosed; this.uiPlayer.GameEnded += this.UiPlayerOnGameEnded; IPlayer smartPlayer = new SmartPlayer(); this.game = new SantaseGame(this.uiPlayer, smartPlayer); this.PlayerCard.Transparent(); this.OldPlayerCard.Transparent(); this.OtherPlayerCard.Transparent(); this.OldOtherPlayerCard.Transparent(); Task.Run(() => this.game.Start()); }
public void StartingGameShouldRestartTheGameToReuseGameInstance() { const int GamesToPlay = 20; var firstPlayer = new ValidPlayerWithMethodsCallCounting(); var secondPlayer = new ValidPlayerWithMethodsCallCounting(); var game = new SantaseGame(firstPlayer, secondPlayer, GameRulesProvider.Santase, new NoLogger()); for (var i = 0; i < GamesToPlay; i++) { game.Start(i % 2 == 0 ? PlayerPosition.FirstPlayer : PlayerPosition.SecondPlayer); } Assert.True( firstPlayer.StartRoundCalledCount >= 4 * GamesToPlay, "Not started at least 4 rounds per game for the first player"); Assert.True( secondPlayer.StartRoundCalledCount >= 4 * GamesToPlay, "Not started at least 4 rounds per game for the second player"); }
public static void Main() { Console.BufferHeight = Console.WindowHeight = 16; Console.BufferWidth = Console.WindowWidth = 60; ISantaseGame game = new SantaseGame( new ConsolePlayer(5, 10), new ConsolePlayer(10, 10), PlayerPosition.FirstPlayer); game.Start(); Console.WriteLine("Game over!"); Console.WriteLine("{0} - {1} in {2} rounds", game.FirstPlayerTotalPoints, game.SecondPlayerTotalPoints, game.RoundsPlayed); Console.ReadLine(); }
private int SimulateGamesAndGetSmartPlayerWins(int gamesToSimulate) { var smartPlayer = new SmartPlayer(); var smartPlayerWins = 0; var dummyPlayer = new DummyPlayer(); var game = new SantaseGame(smartPlayer, dummyPlayer); for (var i = 0; i < gamesToSimulate; i++) { var winner = game.Start(i % 2 == 0 ? PlayerPosition.FirstPlayer : PlayerPosition.SecondPlayer); if (winner == PlayerPosition.FirstPlayer) { smartPlayerWins++; } } // Console.WriteLine(smartPlayerWins); return(smartPlayerWins); }