public Point GetTarget(ref Pac pac) { Point target = null; Pac enemyPac = PacController.GetClosestEnemy(pac); //Pac enemyPac = PacController.GetClosestVisibleEnemy(pac, true); int distanceToEnemy; if (enemyPac != null) { distanceToEnemy = pac.origin.GetDistanceTo(enemyPac.origin); PacType strongerThanMe = Common.GetStrongerPacType(pac.pacType); PacType strongerThanHim = Common.GetStrongerPacType(enemyPac.pacType); Console.Error.WriteLine("ATTACK! pacType" + pac.pacType.ToString() + " strongerThanHim:" + strongerThanHim.ToString() + " distance:" + distanceToEnemy.ToString()); if (pac.pacType == strongerThanHim && distanceToEnemy <= 6) { pac.shouldActivateSpeed = true; pac.inPursuit = true; target = enemyPac.origin; } else { if (pac.cooldown > (enemyPac.speedTurnsLeft > 0 ? distanceToEnemy / 2 : distanceToEnemy)) { //Bezanija!!! //Level.GetClosestJunctionInDirection(); } } } Console.Error.WriteLine("PacId:" + pac.id + " Strategy: Attack " + ((target == null) ? "null" : target.ToString()) + " inPursuit:" + pac.inPursuit.ToString()); return(target); }
public static Pac GetClosestVisibleEnemy(Pac myPac, bool withOppositeDirection = false) { Console.Error.WriteLine("GetClosestVisibleEnemy start"); Pac result = null; int minDistance = int.MaxValue; int distanceToEnemy = int.MaxValue; if (enemyPacs.Count == 0) { Console.Error.WriteLine("No enemies!"); return(null); } List <Pac> enemies = new List <Pac>(); foreach (Pac enemy in enemyPacs) { Console.Error.WriteLine("GetClosestVisibleEnemy enemy: " + enemy.origin.ToString()); //foreach (Point tile in Level.GetTilesVisibleFrom(myPac.origin)) //{ // Console.Error.WriteLine("GetClosestVisibleEnemy visible: " + tile.ToString()); //} if (Level.GetTilesVisibleFrom(myPac.origin).Contains(enemy.origin)) { Console.Error.WriteLine("GetClosestVisibleEnemy match found! opositeDirection:" + withOppositeDirection.ToString()); distanceToEnemy = myPac.origin.GetDistanceTo(enemy.origin); if (withOppositeDirection) { if (PacController.HaveOppositeDirection(myPac, enemy, myPac.currentTarget)) { if (distanceToEnemy < minDistance) { result = enemy; minDistance = distanceToEnemy; } } } else { if (distanceToEnemy < minDistance) { result = enemy; minDistance = distanceToEnemy; } } } } if (result != null) { Console.Error.WriteLine("Found closest enemy!. myPac:" + myPac.id.ToString() + " enemy: " + result.id.ToString()); } return(result); }
public Point GetTarget(ref Pac pac) { Point target = null; double minDistance = Double.MaxValue; double distance; if (pac.currentTarget != null && pac.currentTarget.hasVisiblePellets) // && !PacController.GetCurrentTargets().Values.Contains(pac.currentTarget)) { Console.Error.WriteLine("Keeping current target:" + pac.currentTarget.ToString()); return(pac.currentTarget); } foreach (KeyValuePair <Point, int> junction in Level.junctions) { if (PacController.GetCurrentTargets().Values.Contains(junction.Key)) { Pac previousTargetOwner = PacController.GetPacWithCurrentTarget(junction.Key); if ((pac.origin.GetDistanceTo(junction.Key) < previousTargetOwner.origin.GetDistanceTo(junction.Key))) { Common.SwapPacTargets(ref previousTargetOwner, ref pac, junction.Key); } else { Console.Error.WriteLine("Junction to skip:" + junction.Key.ToString()); } continue; } if (junction.Key.hasVisiblePellets) { distance = pac.origin.GetDistanceTo(junction.Key); if ((distance < minDistance) && (distance > 0.1)) { minDistance = distance; target = junction.Key; Console.Error.WriteLine("Junction target:" + junction.Key.ToString() + " distance: " + distance.ToString()); } } } Console.Error.WriteLine("PacId:" + pac.id + " Strategy: Junctions " + ((target == null) ? "null" : target.ToString())); return(target); }
public Point GetTarget(ref Pac pac) { Console.Error.WriteLine("Mimic strategy start"); Point target = null; Pac enemyPac = PacController.GetClosestVisibleEnemy(pac, true); int distance = Common.minDistanceForSwitch; if (enemyPac != null) { if (enemyPac.speedTurnsLeft > 0) { if (pac.speedTurnsLeft > 0) { distance = distance + 2; } else { distance = distance + 1; } } } if (enemyPac != null && pac.origin.GetDistanceTo(enemyPac.origin) <= distance) { PacType strongerType = Common.GetStrongerPacType(enemyPac.pacType); if (pac.pacType != strongerType) { pac.shouldActivateSwitch = true; pac.switchTo = strongerType; } } else { return(null); } target = enemyPac.origin; Console.Error.WriteLine("PacId:" + pac.id + " Strategy: Mimic " + ((target == null) ? "null" : target.ToString())); return(target); }
public Point GetTarget(ref Pac pac) { if (pac.currentTarget != null && PelletController.ExistsAtPosition(pac.currentTarget)) // && !PacController.GetCurrentTargets().Values.Contains(pac.currentTarget)) { return(pac.currentTarget); } Point target = null; double minDistance = Double.MaxValue; double distance; if (PelletController.BigPellets.Count > 0) { foreach (Point bigPellet in PelletController.BigPellets) { if (PacController.GetCurrentTargets().Values.Contains(bigPellet)) { Pac previousTargetOwner = PacController.GetPacWithCurrentTarget(bigPellet); if ((pac.origin.GetDistanceTo(bigPellet) < previousTargetOwner.origin.GetDistanceTo(bigPellet))) { Common.SwapPacTargets(ref previousTargetOwner, ref pac, bigPellet); } else { Console.Error.WriteLine("Pellet to skip:" + bigPellet.ToString()); } continue; } distance = bigPellet.GetDistanceTo(pac.origin); if (distance < minDistance) { minDistance = distance; target = new Point(bigPellet); } } } Console.Error.WriteLine("PacId:" + pac.id + " Strategy: Greedy" + ((target == null) ? "null" : target.ToString())); return(target); }
//Not thread safe public static List <Point> MarkObstacles(Pac pac, Point target) { List <Point> result = new List <Point>(); Point pacDirection = PacController.GetDirectionSigns(pac.origin, target); foreach (Pac otherPac in PacController.myPacs) { if (pac.id == otherPac.id || !otherPac.isAlive || otherPac.previousOrigin == null) { continue; } Point otherPacDirection = PacController.GetDirectionSigns(otherPac.previousOrigin, otherPac.origin); if (PacController.HaveOppositeDirection(pac, otherPac, target)) { Console.Error.WriteLine("Obstacle found:" + otherPac.origin.ToString()); result.Add(otherPac.origin); Level.map[otherPac.origin.y, otherPac.origin.x] = -1; } } return(result); }
static void Main(string[] args) { string[] inputs; inputs = Console.ReadLine().Split(' '); int width = int.Parse(inputs[0]); // size of the grid int height = int.Parse(inputs[1]); // top left corner is (x=0, y=0) string[] levelRows = new string[height]; for (int i = 0; i < height; i++) { string row = Console.ReadLine(); // one line of the grid: space " " is floor, pound "#" is wall levelRows[i] = row; } Level.InitializeLevel(width, height); Level.StringsToMatrix(levelRows); Level.CalculateJunctions(); //Level.PrintJunctions(); // game loop while (true) { Common.CurrentTurn++; //PacController.ClearCurrentTargets(); //Common.currentTargets.Clear(); inputs = Console.ReadLine().Split(' '); int myScore = int.Parse(inputs[0]); int opponentScore = int.Parse(inputs[1]); int visiblePacCount = int.Parse(Console.ReadLine()); // all your pacs and enemy pacs in sight PacController.ClearPacs(); for (int i = 0; i < visiblePacCount; i++) { inputs = Console.ReadLine().Split(' '); int pacId = int.Parse(inputs[0]); // pac number (unique within a team) bool mine = inputs[1] != "0"; // true if this pac is yours int x = int.Parse(inputs[2]); // position in the grid int y = int.Parse(inputs[3]); // position in the grid string typeId = inputs[4]; // unused in wood leagues int speedTurnsLeft = int.Parse(inputs[5]); // unused in wood leagues int abilityCooldown = int.Parse(inputs[6]); // unused in wood leagues PacController.AddPac(pacId, x, y, typeId, mine, speedTurnsLeft, abilityCooldown); } PacController.SyncPacs(); //PacController.DetectCollisions(); PelletController.ClearPellets(); int visiblePelletCount = int.Parse(Console.ReadLine()); // all pellets in sight Console.Error.WriteLine("Visible pellets: " + visiblePelletCount.ToString()); if (visiblePelletCount == 0) { Logic.MarkEmptyTiles(); } for (int i = 0; i < visiblePelletCount; i++) { inputs = Console.ReadLine().Split(' '); int x = int.Parse(inputs[0]); int y = int.Parse(inputs[1]); int value = int.Parse(inputs[2]); // amount of points this pellet is worth if (value > 1) { PelletController.AddBigPellet(x, y); } else { PelletController.AddPellet(x, y); } } Logic.SetTargets(); Logic.FindPaths(); List <Point> targets = new List <Point>(); string output = ""; for (int i = 0; i < PacController.myPacs.Count; i++) { Pac pac = PacController.myPacs[i]; if (!pac.isAlive) { continue; } Point target; if (pac.isOnPath) { Console.Error.WriteLine("Pac on path: id: " + pac.id.ToString() + " index:" + pac.indexOnPath + " target:" + pac.currentTarget.ToString() + " distance:" + pac.distanceToTarget.ToString()); target = pac.path[pac.indexOnPath]; } else { target = pac.currentTarget; } if (targets.Contains(target)) { Pac otherPac = PacController.GetPacWithCurrentTarget(target); if (otherPac != null && PacController.myPacs[i].origin.GetDistanceTo(otherPac.origin) <= 2) { target = PacController.myPacs[i].previousTarget; } } else { targets.Add(target); } string command = ""; if (pac.cooldown == 0 && pac.shouldActivateSwitch) { command = "SWITCH " + pac.id.ToString() + " " + pac.switchTo.ToString(); } else { if (pac.cooldown == 0)// && pac.shouldActivateSpeed) { command = "SPEED " + pac.id.ToString(); } else { if (target != null) { command = "MOVE " + pac.id.ToString() + " " + target.ToString(); } } } output += (output == "") ? "" : "|"; output += command; } Console.WriteLine(output); } }