Exemple #1
0
        static void Main(string[] args)
        {
            //Console.SetWindowSize(maxCol + 10, maxRow + 10);
            //Console.SetWindowPosition(0, 0);

            var field = new Cell[maxCol, maxRow];
            Init(field);

            int[,] payoffMatrix = { { -25, 50 }, { 0, 15 } };

            var cellfinder = new RandomCellFinder(field);

            var evolution = new Evolution(field, cellfinder, payoffMatrix);
            for (int i = 0; i < 5000; i++)
            {
                Stopwatch sw = new Stopwatch();
                sw.Start();

                //DrawField(field);
                Console.CursorLeft = 0;
                Console.CursorTop = 0;

                PrintInfo(evolution);
                evolution.Tick();
                sw.Stop();
                Console.WriteLine("Ms per tick: " + sw.ElapsedMilliseconds);
                Console.WriteLine("Iteration nr: " + i);
            }
        }
Exemple #2
0
        public override void PickWithoutAgent(Cell[,] field, Coordinate coordinate, out Coordinate newCoordinate)
        {
            var neighbours = GetNeighboursWithoutAgent(coordinate).ToArray();

            if (neighbours.Length == 0)
            {
                newCoordinate = Coordinate.Empty;
                return;
            }
            newCoordinate = PickRandom(neighbours);
        }
Exemple #3
0
        public Evolution(Cell[,] field, Cellfinder cellFinder,
            int[,] hawkAndDovePayoffMatrix, int breedThreshold = 1000, int initialFitness = 0)
        {
            World = new World(field);
            _cellFinder = cellFinder;

            _payoffMatrix = hawkAndDovePayoffMatrix;

            _breedThreshold = breedThreshold;

            SetInitialFitness(initialFitness);
        }
Exemple #4
0
        private static void DrawField(Cell[,] field)
        {
            Console.CursorLeft = 0;
            Console.CursorTop = 0;

            for (int y = 0; y < maxRow; y++)
            {
                for (int x = 0; x < maxCol; x++)
                {
                    var agent = field[x, y].Agent;
                    Console.Write(agent == null ? ' ' : agent is Hawk ? 'H' : 'D');
                }

                Console.WriteLine();
            }
        }
Exemple #5
0
        private static void Init(Cell[,] field)
        {
            for (int y = 0; y < maxRow; y++)
                for (int x = 0; x < maxCol; x++)
                    field[x, y] = new Cell();


            // Initialize
            int startX = maxCol / 2;
            int startY = maxRow / 2;
            // cross
            //for (int x = 0; x < maxCol; x++)
            //{
            //    field[x, startY] = new Cell(new Hawk());
            //}
            //for (int y = 0; y < maxRow; y++)
            //{
            //    field[startX, y] = new Cell(new Dove());
            //}

            // 2x2 block 
            //field[startX, startY] = new Cell(new Hawk());
            //field[startX + 1, startY] = new Cell(new Dove());
            //field[startX, startY + 1] = new Cell(new Hawk());
            //field[startX + 1, startY + 1] = new Cell(new Dove());

            // Random
            var random = new Random((int)DateTime.Now.Ticks);
            for (int y = 0; y < maxRow; y++)
                for (int x = 0; x < maxCol; x++)
                {
                    var next = random.Next(0, 10);
                    Cell cell = new Cell();
                    if (next == 1) cell = new Cell(new Hawk());
                    else if (next == 2) cell = new Cell(new Dove());
                    field[x, y] = cell;
                }
        }
Exemple #6
0
 private static Evolution CreateEvolution(Cell[,] field, int breedThreshold = 100)
 {
     return new Evolution(field, new RandomCellFinder(field), PayoffMatrix, breedThreshold, initialFitness: 0);
 }
Exemple #7
0
 public RandomCellFinder(Cell[,] field) : base(field)
 {
 }
Exemple #8
0
        public override void Pick(Cell[,] field, Coordinate coordinate, out Coordinate newCoordinate)
        {
            var neighbours = GetAllNeighbouringCells(coordinate).ToArray();

            newCoordinate = PickRandom(neighbours);
        }
Exemple #9
0
 public override void PickWithoutAgent(Cell[,] field, Coordinate coordinate, out Coordinate newCoordinate)
 {
     throw new System.NotImplementedException();
 }
Exemple #10
0
            public TestableCellFinder(Cell[,] field) : base(field)
            {

            }
Exemple #11
0
 protected Cellfinder(Cell[,] field)
 {
     this.field = field;
 }
Exemple #12
0
 public abstract void PickWithoutAgent(Cell[,] field, Coordinate coordinate, out Coordinate newCoordinate);
Exemple #13
0
 public abstract void Pick(Cell[,] field, Coordinate coordinate, out Coordinate newCoordinate);