/// <summary>
        /// Starts the game and runs the bot
        /// </summary>
        public void Run()
        {
            // Bot's setup
            simpleBot.Setup();

            // Connecting to the game
            api.CreateGame();

            if (api.errored == false)
            {
                // Opens up a game view
                if (showGame)
                {
                    new Thread(delegate() {
                        string userName = WindowsIdentity.GetCurrent().Name;
                        if (String.Compare(userName, @"coveo\clechasseur", true) == 0)
                        {
                            System.Diagnostics.Process.Start("chrome.exe", api.viewURL);
                        }
                        else
                        {
                            System.Diagnostics.Process.Start(api.viewURL);
                        }
                    }).Start();
                }

                // While the game is running, we ask the bot for his next move and
                // we send that to the server
                while (api.gameState.finished == false && api.errored == false)
                {
                    try {
                        string direction  = Direction.Stay;
                        Thread moveThread = new Thread(() => direction = simpleBot.Move(api.gameState));
                        moveThread.Start();
                        moveThread.Join(800);
                        api.MoveHero(direction);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                        api.MoveHero(Direction.Stay);
                    }
                }
            }

            // Bot's shutdown step
            simpleBot.Shutdown();
        }
Пример #2
0
        /// <summary>
        /// Starts the game and runs the bot
        /// </summary>
        public void Run()
        {
            // Bot's setup
            simpleBot.Setup();

            // Connecting to the game
            api.CreateGame();

            if (api.errored == false)
            {
                // Opens up a game view
                if (showGame)
                {
                    new Thread(delegate() {
                        System.Diagnostics.Process.Start(api.viewURL);
                    }).Start();
                }

                // While the game is running, we ask the bot for his next move and
                // we send that to the server
                while (api.gameState.finished == false && api.errored == false)
                {
                    api.MoveHero(simpleBot.Move(api.gameState));
                    //try
                    //{
                    //    api.MoveHero(simpleBot.Move(api.gameState));
                    //}
                    //catch (Exception ex)
                    //{
                    //    Console.WriteLine(ex.Message);
                    //}
                }
            }

            // Bot's shutdown step
            simpleBot.Shutdown();
        }