Exemplo n.º 1
0
        public static AppleField ReadFieldFromStrings(string source)
        {
            var field = new AppleField();
            var lines = Regex.Split(source, "\r\n|\r|\n");

            int height = lines.Length;
            int width = width = lines.Max(x => x.Length);

            field.FieldHeight = height;
            field.FieldWidth = width;
            field._field = new bool[width, height];
            field.FoodCount = 0;

            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    field._field[i, j] = (lines[j][i] == '*');

                    if (field._field[i, j])
                        field.FoodCount++;
                }
            }

            return field;
        }
Exemplo n.º 2
0
        public static AppleField ReadFieldFromStrings(string source)
        {
            var field = new AppleField();
            var lines = Regex.Split(source, "\r\n|\r|\n");

            int height = lines.Length;
            int width  = width = lines.Max(x => x.Length);

            field.FieldHeight = height;
            field.FieldWidth  = width;
            field._field      = new bool[width, height];
            field.FoodCount   = 0;

            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    field._field[i, j] = (lines[j][i] == '*');

                    if (field._field[i, j])
                    {
                        field.FoodCount++;
                    }
                }
            }

            return(field);
        }
Exemplo n.º 3
0
        public void Restart()
        {
            CurrentDirection = Direction.Right;
            CurrentCell      = new Cell(0, 0);

            _currentState = Ant.InitialState;
            _currentField = _originalField.Clone();
        }
Exemplo n.º 4
0
 public AntMover(FiniteAutomaton automation, AppleField field)
 {
     Ant = automation;
     _originalField = field;
     Restart();
 }
Exemplo n.º 5
0
        public void Restart()
        {
            CurrentDirection = Direction.Right;
            CurrentCell = new Cell(0, 0);

            _currentState = Ant.InitialState;
            _currentField = _originalField.Clone();
        }
Exemplo n.º 6
0
 public AntMover(FiniteAutomaton automation, AppleField field)
 {
     Ant            = automation;
     _originalField = field;
     Restart();
 }