public double GetDesirablity(IPlayer attacker, IHexa hexa) { if (map.GetPlayerOthers().Count == 0) return 0.0f; if (hexa.GetCapturedIPlayer() == attacker) return 0.0f; int enemySum = 0; int attackerSum = hexa.GetNormalProductivity(attacker); foreach (IPlayer player in map.GetPlayerOthers()) { if (player == attacker) { enemySum += hexa.GetNormalProductivity(map.GetPlayerMe()); } else enemySum += hexa.GetNormalProductivity(player); } if (hexa.GetCaptured() && hexa.GetCapturedIPlayer() != attacker) { return (enemySum + attackerSum) / 144.0f; } return (enemySum) / 144.0f; }
public static float GetFitness(IHexa hexa) { if (hexa == null) return 0.0f; float fitness; fitness = hexa.GetStartSource() / 24.0f; /* * Ore and stone is more useful than other sources */ if (hexa.GetKind() != HexaKind.Mountains && hexa.GetKind() != HexaKind.Stone) { fitness *= 0.85f; } /* * Better than water */ if (hexa.GetKind() == HexaKind.Desert) fitness = 0.15f; return fitness; }
public FortCaptureHexa(IMapController map, int k, int depth) : base(map, depth, "Capture hexa") { kPoints = k / 1000.0f; kCapture = 1 - kPoints; bestHexa = null; bestHexaIDs = new List<int>(); }
public ActiveState() { activeLicenceKind = LicenceKind.SecondLicence; activeRoad = null; activeTown = null; activeHexa = null; activeTownPos = 255; activeSourceKind = SourceKind.Count; activeUpgradeKind = UpgradeKind.SecondUpgrade; activeSourceBuildingKind = SourceBuildingKind.Count; activePlayer = null; }
public override double GetDesirability() { if(map.IsBanAction(PlayerAction.FortCaptureHexa)) return 0.0f; IPlayer me = map.GetPlayerMe(); List<IFort> forts = me.GetFort(); IHexa hexa; IHexa hexaNeighbour; double tempDesirability; double bestDesirability = 0.0; foreach (IFort fort in forts) { hexa = map.GetIHexaByID(fort.GetHexaID()); if (hexa == null) continue; for (int loop1 = 0; loop1 < 6; loop1++) { hexaNeighbour = hexa.GetIHexaNeighbour((RoadPos)loop1); if (hexaNeighbour == null) continue; int count = 0; foreach (int i in bestHexaIDs) { if (i == hexaNeighbour.GetID()) count++; } if(count > 1) // dont fight about hexa continue; tempDesirability = GetDesirablity(me, hexaNeighbour); if (tempDesirability > bestDesirability) { bestDesirability = tempDesirability; bestHexa = hexa.GetIHexaNeighbour((RoadPos)loop1); } } } return bestDesirability; }
public double GetDesirability(IHexa hexa) { double kindCoef = 1.0; int points = 0; int myPoints = 0; switch (hexa.GetKind()) { case HexaKind.Desert : case HexaKind.Water : return 0.0f; case HexaKind.Cornfield : kindCoef = 0.9; points = map.GetActionPoints(PlayerPoints.Mill); myPoints = map.GetPlayerMe().GetPoints()[(int)PlayerPoints.Mill]; break; case HexaKind.Forest: kindCoef = 0.8; points = map.GetActionPoints(PlayerPoints.Saw); myPoints = map.GetPlayerMe().GetPoints()[(int)PlayerPoints.Saw]; break; case HexaKind.Mountains: kindCoef = 1.2; points = map.GetActionPoints(PlayerPoints.Mine); myPoints = map.GetPlayerMe().GetPoints()[(int)PlayerPoints.Mine]; break; case HexaKind.Pasture: kindCoef = 0.9; points = map.GetActionPoints(PlayerPoints.Stepherd); myPoints = map.GetPlayerMe().GetPoints()[(int)PlayerPoints.Stepherd]; break; case HexaKind.Stone: kindCoef = 1.2; points = map.GetActionPoints(PlayerPoints.Quarry); myPoints = map.GetPlayerMe().GetPoints()[(int)PlayerPoints.Quarry]; break; } int startSource = hexa.GetStartSource(); //if (myPoints < points) // return ThinkGoal.ONE_POINT_REMAIN_FITNESS; double desirability = (startSource / 24.0 * kindCoef) * kBuildingItself + Desirability.GetHasSources(hexa.GetSourceBuildingCost()) * kHasSources + ((points > 0) ? 1.0 : 0.0) * kPoints; return desirability; }
public FortCaptureHexa(IMapController map, int depth) : base(map, depth, "Capture hexa") { bestHexa = null; bestHexaIDs = new List<int>(); }
public override void Init() { if (bestHexa == null) GetDesirability(); AddSubgoal(new RaiseSources(map, PriceKind.ACaptureHexa, depth + 1)); AddSubgoal(new FortCaptureHexaAtom(map, bestHexa, depth + 1)); bestHexaIDs.Add(bestHexa.GetID()); bestHexa = null; }
private double GetFitness(IHexa hexa) { if (hexa == null || hexa.GetKind() == HexaKind.Water) return 0.0f; double fitness; fitness = hexa.GetStartSource() / 24.0; /* * Ore and stone is more useful than other sources */ if (hexa.GetKind() != HexaKind.Mountains && hexa.GetKind() != HexaKind.Stone) { if (hexa.GetKind() == HexaKind.Forest) { fitness *= 0.6; } else fitness *= 0.75; } /* * Better than water */ if (hexa.GetKind() == HexaKind.Desert) fitness = 0.15; return fitness; }
public FortCaptureHexaAtom(IMapController map, IHexa hexa, int depth) : base(map, depth, "Capture hexa") { this.hexa = hexa; }
public CaptureHexaError CanCaptureHexa(IHexa hexa) { if (Settings.banFortCaptureHexa) return CaptureHexaError.Ban; if (hexa == null) return CaptureHexaError.InvalidHexaID; List<IFort> forts = GetPlayerMe().GetFort(); CaptureHexaError error; foreach (IFort fort in forts) { HexaModel.SetHexaFort(fort); error = CanCaptureHexa(hexa.GetID(), fort); if (error == CaptureHexaError.TooFarFromFort) continue; return error; } return CaptureHexaError.TooFarFromFort; }
public double GetDesirablity(IPlayer attacker, IHexa hexa) { if (map.GetPlayerOthers().Count == 0) return 0.0f; if (hexa.GetCapturedIPlayer() == attacker) return 0.0f; int enemySum = 0; int attackerSum = hexa.GetNormalProductivity(attacker); foreach (IPlayer player in map.GetPlayerOthers()) { if (player == attacker) { enemySum += hexa.GetNormalProductivity(map.GetPlayerMe()); } else enemySum += hexa.GetNormalProductivity(player); } if (hexa.GetKind() == HexaKind.Mountains || hexa.GetKind() == HexaKind.Stone) enemySum = (int)(enemySum * 1.05); else if (hexa.GetKind() == HexaKind.Forest) enemySum = (int)(enemySum * 0.8); else if (hexa.GetKind() == HexaKind.Desert) return 0.0; if (hexa.GetCaptured() && hexa.GetCapturedIPlayer() != attacker) { return (enemySum + attackerSum) / 144.0f; } return (enemySum) / 144.0f; }
internal bool ExistHexaWithFitnessMore(float limit, IHexa hexa) { IMapController map = mapController; if (map.GetPlayerOthers().Count == 0) return false; IPlayer me = map.GetPlayerMe(); IPlayer someone = map.GetPlayerOthers()[0]; IHexa hexaNeighbour; for (int loop1 = 0; loop1 < 6; loop1++) { hexaNeighbour = hexa.GetIHexaNeighbour((RoadPos)loop1); if (hexaNeighbour == null) continue; if (Fitness.GetFitness(me, hexaNeighbour) > limit || Fitness.GetFitness(someone, hexaNeighbour) > limit) return true; } return false; }
internal bool ActionCaptureHexa(IHexa hexa) { if (mapController.CaptureHexa(hexa)) return true; if (mapController.CanCaptureHexa(hexa) == CaptureHexaError.Ban) return false; throw new Exception("Should capture hexa. " + mapController.GetLastError()); }
public bool CaptureHexa(IHexa hexa) { List<IFort> forts = GetPlayerMe().GetFort(); CaptureHexaError error; foreach (IFort fort in forts) { HexaModel.SetHexaFort(fort); error = CanCaptureHexa(hexa.GetID(), fort); if (error == CaptureHexaError.OK) return CaptureHexa(hexa.GetID(), fort); } return false; }
public override double GetDesirability() { IPlayer me = map.GetPlayerMe(); List<IFort> forts = me.GetFort(); if (forts.Count == 0) return 0.0f; IHexa hexa; IHexa hexa1Neighbour; IHexa hexaNeighbour; double tempDesirability; double bestDesirability = 0.0; foreach (IFort fort in forts) { hexa = map.GetIHexaByID(fort.GetHexaID()); if (hexa == null) continue; for (int loop1 = 0; loop1 < 6; loop1++) { hexa1Neighbour = hexa.GetIHexaNeighbour((RoadPos)loop1); if (hexa1Neighbour == null) continue; for (int loop2 = 0; loop2 < 6; loop2++) { hexaNeighbour = hexa1Neighbour.GetIHexaNeighbour((RoadPos) loop2); if (hexaNeighbour == null || hexaNeighbour.GetKind() == HexaKind.Desert || hexaNeighbour.GetKind() == HexaKind.Water || hexaNeighbour.GetKind() == HexaKind.Null) continue; if (map.CanCaptureHexa(hexaNeighbour) == CaptureHexaError.TooFarFromFort) continue; int count = 0; foreach (int i in bestHexaIDs) { if (i == hexaNeighbour.GetID()) count++; } if (count > 1) // dont fight about hexa continue; tempDesirability = GetDesirablity(me, hexaNeighbour); if (tempDesirability > bestDesirability) { bestDesirability = tempDesirability; bestHexa = hexaNeighbour; } } } } if (bestHexa == null) return 0.0f; double points = (map.GetActionPoints(PlayerPoints.FortCaptureHexa) > 0) ? 1.0 : 0.0; return bestDesirability * kCapture + points * kPoints; }
private double GetFitness(IHexa hexa) { if (hexa == null || hexa.GetKind() == HexaKind.Water) return 0.0f; return buildingGoal.GetDesirability(hexa); }
internal void SetActiveObject(IHexa hexa) { activeState.activeHexa = hexa; }