//Check if the enemy has tower on his defendlane private bool DoesEnemyHaveTowers(TowerHurtMap hurtMap) { int hurt = hurtMap.ReturnWholeHurtMapValue(hurtMap.enemyTowerHurtMap); if (hurt == 0) { return(true); } return(false); }
/* * This move method is a mere copy of the base movement method. */ public override void move() { soldier_xPos = posX; soldier_yPos = posY; unitHurtMap = new TowerHurtMap(lane); unitHurtMap.enemyTowerHurtMap = unitHurtMap.GenerateHurtMap(); //Check if the enemy lane has any towers, if so, alter the movement strategy to be most efficient if (DoesEnemyHaveTowers(unitHurtMap)) { moveTo(posX, Math.Clamp(posY + 1, 0, PlayerLane.HEIGHT)); } //Otherwise check for a few conditions: //TurnCounter.turnCounter < 250 && // 1. There were no walls detected // 2. The strategy is considered efficient // 3. Or my backup strategy is not active //Then move according to weighted A* pathfinding else if (!EvaluateScore.backUpStrategy) { if (!unitHurtMap.DetectWalls(unitHurtMap.enemyTowerPositions) || EvaluateScore.efficientOne || EvaluateScore.efficientTwo) { //XmlWriter xmlWriter = XmlWriter.Create("paths.xml"); //Because A* is usually used to get the path to 1 goal, I have to generate a path to each of the goals (X:0-6|Y:19) to find the best one for (int i = 0; i < PlayerLane.WIDTH; i++) { pathFinding.FindPath(posX, posY, i, 19, unitHurtMap.enemyTowerHurtMap); allPaths[i] = pathFinding.foundPath; } //WritePathsToXML(xmlWriter); //After that, calculate which path results in the last damage taken pathFinding.foundPath = EvaluatePath(); //If a path was found, remove the first node (unit's current position) and move towards the next node if (pathFinding.foundPath.Count > 0) { pathFinding.foundPath.RemoveAt(0); moveTo(pathFinding.foundPath[0].xPos, pathFinding.foundPath[0].yPos); } } } //In case my backup strategy is active else { moveTo(posX, Math.Clamp(posY + 1, 0, PlayerLane.HEIGHT)); } }
public override void DeployTowers() { //Start my own TurnCounter TurnCounter.IncrementTurn(); //Only want the efficient bools to be set once if (!setUpBools) { setUpBools = true; EvaluateScore.SetBools(); } //Check for breached units = behind my first towerlane List <Unit> breachedUnits = new List <Unit>(); for (int i = 0; i < PlayerLane.WIDTH; i++) { for (int k = 2; k < PlayerLane.HEIGHT; k++) { Cell cell = defendLane.GetCellAt(i, k); if (cell.Unit != null && cell.Unit.GetType() == typeof(Soldier)) { breachedUnits.Add(cell.Unit); } } } // If more than two lanes full of soldiers get through my initial defense // Consider my defense as breached and fall back to second defense line if (breachedUnits.Count >= 14) { defenseBreached = true; } //Generate a heatmap for later use hurtMap = new TowerHurtMap(attackLane); hurtMap.enemyTowerHurtMap = hurtMap.GenerateHurtMap(); //Personally I think this is the best tower placement: Counters f.e. pooling soldiers out of range of my towers and engaging then //Therefore this is rather static if (!defenseBreached) { for (int i = 0; i < 3; i++) { Tower tower = player.BuyTower(defendLane, i, 2); } for (int i = 4; i < 7; i++) { Tower newTower = player.BuyTower(defendLane, i, 2); } for (int i = 1; i < 7; i += 2) { Tower newerTower = player.BuyTower(defendLane, i, 3); } } else { for (int j = PlayerLane.HEIGHT - 2; j <= PlayerLane.HEIGHT; j++) { for (int i = 0; i < 3; i++) { Tower tower = player.BuyTower(defendLane, i, j); } for (int i = 6; i > 2; i--) { Tower newTower = player.BuyTower(defendLane, i, j); } } } }