Beispiel #1
0
 public Turret(Team team, int radius, Grid domain, TurretSet allTurrets)
     : base("a turret", domain, 0)
 {
     Team       = team;
     Radius     = radius;
     Grid       = domain;
     AllTurrets = allTurrets;
 }
Beispiel #2
0
        /**
         * Draw the grid in the console.
         * Values stored in the grid and turrets are printed on the map.
         */
        public void Draw(TurretSet turrets)
        {
            string line = new string('-', Width + 2);

            Console.WriteLine(line);

            for (int i = 0; i < _data.Length; ++i)
            {
                if (i % Width == 0)
                {
                    Console.Write("|");
                }

                Turret turret = turrets.At(i);
                if (turret != null)
                {
                    Console.Write(turrets.GetIndex(turret));
                }
                else
                {
                    switch (_data[i])
                    {
                    case Team.ALLY:
                        Console.Write("A");
                        break;

                    case Team.ENEMY:
                        Console.Write("B");
                        break;

                    case Team.NONE:
                        Console.Write(" ");
                        break;
                    }
                }


                if (i % Width == Width - 1)
                {
                    Console.WriteLine('|');
                }
            }

            Console.WriteLine(line);
        }
Beispiel #3
0
        public void Run()
        {
            // Setup the scenario with the provided function
            int  numTurrets;
            int  radius;
            Grid grid;

            _setup(out numTurrets, out radius, out grid);

            var turrets = new TurretSet(numTurrets, Team.ALLY, radius, grid);

            var constraints = new List <TurretConstraint>
            {
                new InTerritory(turrets),
                //new ProtectOwnTiles(turrets),
                new NoOverlap(turrets),
                //new CloseToEnemy(turrets)
            };

            var objective = new Coverage();

            var solver = new Solver <Turret, TurretSet, TurretConstraint>(turrets, constraints, objective);

            solver.solve(100, 500);

            grid.Draw(turrets);

            for (int i = 0; i < turrets.GetNumberVariables(); ++i)
            {
                var t = turrets[i];
                Console.WriteLine("Turret " + i + " (radius " + t.Radius + ")");
                Console.WriteLine("    Protected allied tiles " + t.ProtectedTiles().Count());
                Console.WriteLine("    Protected allied tiles (unique) " + t.UniquelyProtectedTiles().Count());
                Console.WriteLine("    Covered enemy tiles " + t.CoveredEnemyTiles().Count());
                Console.WriteLine("    Covered enemy tiles (unique) " + t.UniquelyCoveredEnemyTiles().Count());
                Console.WriteLine("    Distance to enemy " + t.DistanceToClosestEnemyTerritory());
            }
            Console.WriteLine(turrets[0].CoveredEnemyTiles().Count());
        }
 public ProtectOwnTiles(TurretSet turrets)
     : base(turrets)
 {
 }
Beispiel #5
0
 public CloseToEnemy(TurretSet turrets)
     : base(turrets)
 {
 }
Beispiel #6
0
 public NoOverlap(TurretSet turrets, int distance = 0)
     : base(turrets)
 {
     _distance = distance;
 }
Beispiel #7
0
 public InTerritory(TurretSet turrets)
     : base(turrets)
 {
 }