public void TestPrintResult(GameState state, string expectedResult)
        {
            var printer = new GameStatePrinter(new SpaceStateToStringConvertor());
            var result  = printer.Print(state);

            Assert.AreEqual(result, expectedResult);
        }
Пример #2
0
        static void Main()
        {
            //==============================================
            ScreenCoordinates.SetScreenSize(2560, 1440);
            //==============================================

            Console.Title = "SHENZHEN IO Bot";

            Console.WriteLine("Press ENTER when the field can be extracted!");
            Console.Read();

            while (true)
            {
                Console.WriteLine("Grabbing field...");
                PlayingField field = ScreenExtractor.ExtractField();

                Player    p          = new Player(field);
                GameState finalState = p.FindSolution();

                if (finalState != null)
                {
                    Console.WriteLine($"Solution has {finalState.PathLength} steps!");
                    GameState[] moves = GameState.Linearize(finalState);
                    GameExecuter.FocusWindow();

                    for (int i = 0; i < moves.Length; i++)
                    {
                        GameStatePrinter.Print(moves[i]);

                        if (i > 0)
                        {
                            GameExecuter.ExecuteState(moves[i]);
                        }
                    }
                }
                else
                {
                    Console.WriteLine("No Solution found!");
                }

                Console.WriteLine("Sleping for 10sec...");
                Thread.Sleep(10000);

                GameExecuter.FocusWindow();
                GameExecuter.NewGame();
            }
        }
        public void Print_CallsStringConverterForEverySpace(int width, int height)
        {
            int convertorCount = 0;
            var convertorMock  = new Mock <ISpaceStateToStringConvertor>();
            var stateMock      = new Mock <IGameState>();

            stateMock.Setup(state => state.FieldWidth)
            .Returns(width);
            stateMock.Setup(state => state.FieldHeight)
            .Returns(height);
            convertorMock.Setup(convertor => convertor.Convert(It.IsAny <GameSpaceState>()))
            .Returns(".")
            .Callback(() => convertorCount += 1);
            var printer = new GameStatePrinter(convertorMock.Object);

            printer.Print(stateMock.Object);

            Assert.AreEqual(width * height, convertorCount);
        }