Esempio n. 1
0
        public void PlaceBeginPattern(BeginPattern beginPattern)
        {
            Pos pos;

            switch (beginPattern)
            {
            case (BeginPattern.CrosswisePattern):
                pos = new Pos(Width / 2 - 1, Height / 2 - 1);
                PutPoint(pos);
                pos.X++;
                PutPoint(pos);
                pos.Y++;
                PutPoint(pos);
                pos.X--;
                PutPoint(pos);
                break;

            case (BeginPattern.SquarePattern):
                pos = new Pos(Width / 2 - 1, Height / 2 - 1);
                PutPoint(pos);
                pos.X++;
                PutPoint(pos);
                pos.Y++;
                pos.X--;
                PutPoint(pos);
                pos.X++;
                PutPoint(pos);
                break;
            }
        }
Esempio n. 2
0
 public void Init(int width, int height, SurroundCond surCond, BeginPattern beginPattern)
 {
     if (_handle != IntPtr.Zero)
     {
         Final();
     }
     _handle = DllInit(width, height, new IntPtr(78526081));
 }
Esempio n. 3
0
 public void Init(int width, int height, SurroundCond surCond, BeginPattern beginPattern, Action initSuccess = null)
 {
     if (_error)
     {
         return;
     }
     _actions.Enqueue(() =>
     {
         _bot.Init(width, height, surCond, beginPattern);
         if (initSuccess != null)
         {
             initSuccess();
         }
     });
     ExecuteNext();
 }
Esempio n. 4
0
        private void PlaceBeginPattern(BeginPattern beginPattern)
        {
            // Отключаем звуки.
            var sounds = _preferences.Sounds;

            _preferences.Sounds = false;

            Pos pos;

            switch (beginPattern)
            {
            case (BeginPattern.CrosswisePattern):
                pos = new Pos(Preferences.Width / 2 - 1, Preferences.Height / 2 - 1);
                PutPoint(pos);
                pos.X++;
                PutPoint(pos);
                pos.Y++;
                PutPoint(pos);
                pos.X--;
                PutPoint(pos);
                break;

            case (BeginPattern.SquarePattern):
                pos = new Pos(Preferences.Width / 2 - 1, Preferences.Height / 2 - 1);
                PutPoint(pos);
                pos.X++;
                PutPoint(pos);
                pos.Y++;
                pos.X--;
                PutPoint(pos);
                pos.X++;
                PutPoint(pos);
                break;
            }

            _preferences.Sounds = sounds;
        }
Esempio n. 5
0
        public void Init(int width, int height, SurroundCond surCond, BeginPattern beginPattern)
        {
            if (_bot != null)
            {
                Final();
            }
            _random   = new Random();
            _commands = new HashSet <string>();
            _bot      = new Process
            {
                EnableRaisingEvents = false,
                StartInfo           =
                {
                    UseShellExecute        = false,
                    RedirectStandardInput  = true,
                    RedirectStandardOutput = true,
                    RedirectStandardError  = true,
                    CreateNoWindow         = true,
                    FileName               = BotName
                }
            };
            if (!_bot.Start())
            {
                throw new Exception("Error while starting.");
            }
            _bot.PriorityClass = ProcessPriorityClass.Idle;
            // list_commands
            var id = _random.Next();

            _bot.StandardInput.WriteLine("{0} list_commands", id);
            var answer = _bot.StandardOutput.ReadLine();

            if (answer == null)
            {
                throw new Exception("list_commands: Answer is null.");
            }
            var splittedAnswer = answer.Split();

            if (splittedAnswer.Length == 3 && splittedAnswer[0] == "?" && splittedAnswer[1] == id.ToString() && splittedAnswer[2] == "list_commands")
            {
                throw new Exception("list_commands: Error while executing.");
            }
            if (splittedAnswer.Length < 4 || splittedAnswer[0] != "=" || splittedAnswer[1] != id.ToString() || splittedAnswer[2] != "list_commands")
            {
                throw new Exception("list_commands: Invalid answer.");
            }
            for (var i = 3; i < splittedAnswer.Length; i++)
            {
                _commands.Add(splittedAnswer[i]);
            }
            // init.
            if (!_commands.Contains("init"))
            {
                throw new Exception("init: Not supported.");
            }
            id = _random.Next();
            _bot.StandardInput.WriteLine("{0} init {1} {2} {3}", id, width, height, 78526081);
            answer = _bot.StandardOutput.ReadLine();
            if (answer == null)
            {
                throw new Exception("init: Answer is null.");
            }
            splittedAnswer = answer.Split();
            if (splittedAnswer.Length == 3 && splittedAnswer[0] == "?" && splittedAnswer[1] == id.ToString() && splittedAnswer[2] == "init")
            {
                throw new Exception("init: Error while executing.");
            }
            if (splittedAnswer.Length != 3 || splittedAnswer[0] != "=" || splittedAnswer[1] != id.ToString() || splittedAnswer[2] != "init")
            {
                throw new Exception("init: Invalid answer.");
            }
        }