Beispiel #1
0
        public static float GetFitness(IRoad road)
        {
            if (road == null)
                return 0.0f;

            float fitness = 0.0f;
            IRoad tempRoad;
            bool con;

            foreach (ITown town1 in road.GetITown())
            {
                //
                if (town1.GetIOwner() != null)
                    continue;

                con = false;
                for (byte loop1 = 0; loop1 < 3; loop1++)
                {
                    tempRoad = town1.GetIRoad(loop1);
                    if (tempRoad != null &&
                        tempRoad.GetIOwner() == map.GetPlayerMe())
                    {
                        con = true;
                        break ;
                    }
                }
                if (con)
                    continue;

                if (town1.IsPossibleToBuildTown())
                    fitness += GetFitness(town1);

                for(byte loop1 = 0; loop1 < 3; loop1++)
                {
                    tempRoad = town1.GetIRoad(loop1);
                    if (tempRoad == null || tempRoad.GetIsBuild())
                        continue;

                    foreach(ITown town2 in tempRoad.GetITown())
                    {
                        if(town2 != town1 && town2.IsPossibleToBuildTown())
                            fitness += GetFitness(town2) / 2.5f;
                    }
                }
            }

            return fitness / 2.0f;
        }
Beispiel #2
0
        internal bool BuildRoad(IRoad activeRoad)
        {
            if (activeRoad == null)
                return false;

            if (activeRoad.Build() != null)
            {
                freeRoadPlaces.Remove(activeRoad);

                foreach (ITown town in activeRoad.GetITown())
                {
                    if (town.GetIOwner() != mapController.GetPlayerMe() && town.GetIOwner() != null)
                        continue;

                    for (byte loop1 = 0; loop1 < 3; loop1++)
                    {
                        IRoad road = town.GetIRoad(loop1);

                        if (road != null)
                        {
                            RoadBuildError tempError = road.CanBuildRoad();
                            if (tempError == RoadBuildError.OK ||
                                tempError == RoadBuildError.NoSources)
                            {
                                if (!freeRoadPlaces.Contains(road))
                                {
                                    freeRoadPlaces.Add(road);
                                }
                            }
                        }
                    }

                    if (town.IsPossibleToBuildTown())
                    {
                        freeTownPlaces.Remove(town);
                        freeTownPlaces.Add(town);
                    }
                }
                return true;
            }
            else
            {
                freeRoadPlaces.Remove(activeRoad);
                throw new Exception("Buidling road. " + mapController.GetLastError());
                //return false;
            }
        }