示例#1
0
 public static IGameAIHost GetGameHost()
 {
     return(GameHostFactory.GetGameHost(
                GetGameRules(),
                GetGameResolver(),
                PlayerFactoryParserJson.NewJsonPlayer(InputJson),
                logger));
 }
示例#2
0
        public void TestGameRuler_Semaphore()
        {
            var log = new Mock <ILogger>();

            log.Setup(l => l.AddLogItem(It.IsAny <string>(), It.IsAny <object[]>()))
            .Callback <string, object[]>((fmt, args) => { { Log(fmt, args); } });

            try
            {
                using (var gr = GameHostFactory.GetGameHost(
                           GetGameRules(),
                           GetGameResolver(),
                           PlayerFactoryParserJson.NewJsonPlayer(InputJson),
                           log.Object))
                {
                    gr.StartGame();

                    Log("=============================================");
                    Assert.IsTrue(gr.TotalAttemptsCount <= MaxAttempts);
                    Assert.IsTrue(gr.TotalAttemptsCount > 0);
                    Log("Total attempts count: {0}", gr.TotalAttemptsCount);

                    var go = gr.GameOutput;
                    Log("Winner player {0}", go.WinnerPlayer.Name);
                    Log("Number of attempts {0}", go.NumberOfAttempts);
                    Log("Winner's best guess {0}", go.WinnersBestGuess);
                    Log("Secret value {0}", go.SecretValue);
                }
            }
            catch (OperationCanceledException) { }
            catch (Exception e)
            {
                var ex = e;
                while (ex != null)
                {
                    Log(ex.Message, ex.StackTrace);
                    ex = ex.InnerException;
                }
                Assert.Fail();
            }
        }