Exemplo n.º 1
0
        public FieldProcessor(int width, int height, DnaProcessor dnaProcessor)
        {
            _dnaProcessor = dnaProcessor;
            _creatures    = dnaProcessor.GetCreatures();
            _random       = dnaProcessor.Random;
            _field        = new Field(width, height);

            _foodBuffer = 10000;

            foreach (var creature in _creatures)
            {
                int x;
                int y;
                do
                {
                    x = _random.Next(width);
                    y = _random.Next(height);
                } while (_field[x, y] != null);

                creature.X         = x;
                creature.Y         = y;
                creature.Rotation  = _random.Next(4) * 2;
                creature.FoodValue = 20;
                _field[x, y]       = creature;
                _foodBuffer       -= creature.FoodValue + Creature.CreatureSkinFoodValue;
            }

            FillFood();
            _creatureProcessor = new DnaInterpreter(_field);
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            SafeFileHandle h    = CreateFile("CONOUT$", 0x40000000, 2, IntPtr.Zero, FileMode.Open, 0, IntPtr.Zero);
            SmallRect      rect = new SmallRect {
                Left = 0, Top = 0, Right = Width, Bottom = Height
            };

            if (!h.IsInvalid)
            {
                using var storageController = new StorageController();
                while (true)
                {
                    DnaProcessor dnaProcessor = new DnaProcessor(storageController);
                    var          processor    = new FieldProcessor(Width, Height, dnaProcessor);
                    bool         nextStep     = true;
                    while (nextStep)
                    {
                        var field = processor.Field;

                        CharInfo[] buf = new CharInfo[Width * Height];

                        for (int i = 0; i < field.Length; i++)
                        {
                            switch (field[i])
                            {
                            case 1:
                                buf[i].Char.AsciiChar = 254;
                                buf[i].Attributes     = 2;
                                break;

                            case 2:
                                buf[i].Char.AsciiChar = 215;
                                buf[i].Attributes     = 3;
                                break;

                            default:
                                buf[i].Char.AsciiChar = 46;
                                buf[i].Attributes     = 5;
                                break;
                            }
                        }

                        WriteConsoleOutput(h, buf,
                                           new Coord(Width, Height),
                                           new Coord(0, 0),
                                           ref rect);
                        nextStep = processor.Step();
                    }
                }
            }
        }