示例#1
0
        public Field(int width, int height, SurroundCond surCond)
        {
            Width             = width;
            Height            = height;
            SurCond           = surCond;
            CaptureCountRed   = 0;
            CaptureCountBlack = 0;
            CurPlayer         = PlayerColor.Red;

            Points    = new GamePoint[width + 2, height + 2];
            PointsSeq = new List <Pos>();
            MainState = new StateChange();

            // Помечаем граничные точки как невалидные.
            for (var i = 0; i < width + 2; i++)
            {
                Points[i, 0].Bad          = true;
                Points[i, height + 1].Bad = true;
            }
            for (var i = 0; i < height + 2; i++)
            {
                Points[0, i].Bad         = true;
                Points[width + 1, i].Bad = true;
            }
        }
示例#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));
 }
示例#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();
 }
示例#4
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.");
            }
        }