Britbot

This function sais if it is ok for a given group to try and capture this isalnd considers all the other.

Parameters:
gthe group for which we test danger
Returns:
true if it is dangerous, false otherwise

Definition at line 403 of file SmartIsland.cs.

        {
            //Bot.Game.Debug("IsDangerousForGroup island: " + Id + " group " + g.Id);
            //calculate distance in turns till we reach the island
            int eta = Bot.Game.Distance(this.Loc, g.FindCenter(true));

            //find the distance of g from the island
            int distance = Bot.Game.Distance(this.Loc, g.FindCenter(true));


            //go over all the enemy groups approaching and their distances
            //TODO: maybe consider the actual firepower of the enemy
            foreach (KeyValuePair<EnemyGroup,bool> eGroupPair in this.approachingEnemies)
            {
                if (!eGroupPair.Value)
                    continue;

                EnemyGroup eGroup = eGroupPair.Key;
                //calculate this enemy groups time of arival
                double EnemyETA = eGroup.MinimalETATo(this.Loc);

                //read enemy force
                double enemyForce = eGroup.GetMaxFightPower();

                //We diffarentiate between two cases
                if (EnemyETA < distance) //case 1: Enemy is closer to the island then we are
                {
                    //check if we arrive before capture
                    if (distance < EnemyETA + this.RealTimeTillCapture(Consts.ENEMY))
                    {
                        //the enemy who are closer are at disaddvantage since they lose one pirate capturing the island
                        if (g.LiveCount() <= enemyForce - 1)
                            return true;
                    }
                }
                else //case 2: Enemy is farther away to the island then we are
                {
                    //if the enemy reaches us before we capture
                    if (EnemyETA < this.RealTimeTillCapture(Consts.ME) + distance)
                    {
                        //for the enemy who are farther, we are at a disaddvantage
                        if ((enemyForce != 0) && (g.LiveCount() - 1 < enemyForce))
                            return true;

                        //special case: Manuver 
                        if ((enemyForce != 0) && (g.LiveCount() - 1 == enemyForce))
                        {
                            //we would like to run from the island only when they are realy close so we will catch them
                            if (eGroup.MinimalSquaredDistanceTo(this.Loc) < Magic.ManeuverDistance)
                            {
                                return true;
                            }
                        }
                    }
                }
            }

            //if we are here then everything is ok
            return false;
        }