Beispiel #1
0
 public static void UpdateSeeArea(bool[,] seeArea, IEnumerable <IUnit> myUnits)
 {
     foreach (var unit in myUnits)
     {
         UpdateSeeArea(seeArea, unit.Point, GameConstant.GetViewRange(unit.Type));
     }
 }
Beispiel #2
0
        // @magicnumber
        private bool NeedToBuildWorker()
        {
            var workers      = myUnits.Values.Where(unit => unit.Type == UnitType.Worker);
            int workersCount = workers.Count();

            if (workersCount < ThinkLeastWorkerNum())
            {
                return(true);
            }

            if (workers.Where(unit => unit.IsFree).Count() > 0)
            {
                return(false);
            }

            var warriors      = myUnits.Values.Where(unit => GameConstant.IsWarrior(unit.Type));
            int warriorsCount = warriors.Count();

            // @magicnumber
            if (warriorsCount < workersCount * 2)
            {
                return(false);
            }

            if (workers.Count() < ThinkMaxControlledResourceNum() * 5)
            {
                return(true);
            }

            return(false);
        }
Beispiel #3
0
        private void ThinkWarrior()
        {
            {
                var freeWarrior = myUnits.Values.Where(unit => unit.IsFree && GameConstant.IsWarrior(unit.Type));
                var move        = freeWarrior.OrderBy(unit => Game.Manhattan(unit.Point, myCastle.Point)).Take(9);
                foreach (var unit in move)
                {
                    unit.MoveTo = myCastle.Point;
                }
            }

            var candidates = SortResourcePriority().Take(ThinkMaxControlledResourceNum());

            foreach (var point in candidates)
            {
                var freeWarrior = myUnits.Values.Where(unit => unit.IsFree && GameConstant.IsWarrior(unit.Type));
                var move        = freeWarrior.OrderBy(unit => Game.Manhattan(unit.Point, point)).Take(5);
                foreach (var unit in move)
                {
                    unit.MoveTo = point;
                }
            }

            Point p = enCastle.IsDiscovered ? enCastle.Point : SearchEnemyCastle();

            foreach (var unit in myUnits.Values)
            {
                if (unit.IsFree && unit.IsWarrior)
                {
                    unit.MoveTo = p;
                }
            }
        }
Beispiel #4
0
	public int getScoreByGameLevel(){
		gameConstant = getGameConstant();
		switch(gameLevel){
		case GameLevel.EASY : return gameConstant.getEasyScore();
		case GameLevel.NORMAL : return gameConstant.getNormalScore();
		case GameLevel.HARD : return gameConstant.getHardScore();
		default :return 0;
		}
	}
Beispiel #5
0
        private void ThinkBuild()
        {
            int canUse = currentResource;

            if (NeedToBuildVillage())
            {
                canUse -= GameConstant.GetCost(UnitType.Village);
            }

            if (NeedToBuildFactory())
            {
                canUse -= GameConstant.GetCost(UnitType.Factory);
            }

            foreach (var unit in myUnits.Values)
            {
                if (unit.Type == UnitType.Castle || unit.Type == UnitType.Village)
                {
                    if (canUse >= GameConstant.GetCost(UnitType.Worker))
                    {
                        if (NeedToBuildWorker())
                        {
                            canUse      -= GameConstant.GetCost(UnitType.Worker);
                            unit.Produce = UnitType.Worker;
                        }
                    }
                }
            }

            foreach (var unit in myUnits.Values)
            {
                if (unit.Type == UnitType.Factory)
                {
                    UnitType unitType;
                    int      rnd = GameConstant.Random.Next(100);
                    if (rnd < 33)
                    {
                        unitType = UnitType.Knight;
                    }
                    else if (rnd < 66)
                    {
                        unitType = UnitType.Fighter;
                    }
                    else
                    {
                        unitType = UnitType.Assassin;
                    }

                    if (canUse >= GameConstant.GetCost(unitType))
                    {
                        canUse      -= GameConstant.GetCost(unitType);
                        unit.Produce = unitType;
                    }
                }
            }
        }
Beispiel #6
0
    void Awake()
    {
        //Singleton safe used
        if(instance == null)
            instance = this;
        else if (instance != this)
            Destroy(gameObject);
        DontDestroyOnLoad(instance);

        CreateNewGame();
        print("Awake");
    }
Beispiel #7
0
        private void ThinkSearcher()
        {
            bool[,] seeArea2 = new bool[GameConstant.FieldSize, GameConstant.FieldSize];
            for (int x = 0; x < GameConstant.FieldSize; x++)
            {
                for (int y = 0; y < GameConstant.FieldSize; y++)
                {
                    seeArea2[x, y] = seeArea[x, y];
                }
            }

            if (NeedToSearch())
            {
                var searchersList = new[] {
                    myUnits.Values.Where(unit => GameConstant.IsWarrior(unit.Type)),
                    myUnits.Values.Where(unit => unit.Type == UnitType.Worker)
                };

                int searcherNum = ThinkSearcherNum();
                int k           = 0;

                foreach (var searchers in searchersList)
                {
                    while (k < searcherNum)
                    {
                        if (NeedToSearch() == false)
                        {
                            break;
                        }

                        MyUnit u = null;
                        Point  p = null;
                        SearchBestFreeSearcher(seeArea2, searchers, out u, out p);

                        if (u != null)
                        {
                            u.MoveTo = p;
                            // ここでdを+1とか+2とかしても良いかもしれない
                            // @magicnumber
                            UpdateSeeArea(seeArea2, p, GameConstant.GetViewRange(u.Type) * 2);
                            ++k;
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }
        }
Beispiel #8
0
        private int[,] CountNumWarriors()
        {
            int[,] numWarriors = new int[100, 100];
            var myWarriors = myUnits.Values.Where(unit => GameConstant.IsWarrior(unit.Type));

            foreach (var unit in myWarriors)
            {
                if (unit.IsMoving && resource[unit.MoveTo.X, unit.MoveTo.Y])
                {
                    numWarriors[unit.MoveTo.X, unit.MoveTo.Y]++;
                }
            }

            return(numWarriors);
        }
Beispiel #9
0
    private IEnumerator SetPlatformConfig()
    {
        if (null == serverVersionConfig)
        {
            yield break;
        }

        currentPlatform = serverVersionConfig.GetPlatformConfig(SDKManager.Instance.Platform);
        if (null == currentPlatform)
        {
            Logger.LogError("get current platform config failed platform = " + SDKManager.Instance.Platform);
            yield break;
        }
        GameConstant.RedirectLoginUrl(currentPlatform.LoginUrlRedirect);
        GameConstant.SetAppType(currentPlatform.AppType);

        yield return(StartCoroutine(CheckApkUpdate()));
    }
Beispiel #10
0
    private Emotion GetChoiceEmotionParameter(Dialogue.Choice choice)
    {
        var emotion = GameLogicManager.currentCharacter.emotion;

        if (choice.userData != null)
        {
            var parametersData = this.GetChoiceParameters(choice);
            var parameters     = parametersData.Split(' ');
            foreach (var parameter in parameters)
            {
                if (parameter.StartsWith("E:"))
                {
                    var trimParameter = parameter.TrimStart('E', ':');
                    if (GameConstant.StringToEmotion(trimParameter) != Emotion.none)
                    {
                        emotion = GameConstant.StringToEmotion(trimParameter);
                    }
                }
            }
        }
        return(emotion);
    }
Beispiel #11
0
 public static void UpdateSeeArea(bool[,] seeArea, Point p, UnitType unitType)
 {
     UpdateSeeArea(seeArea, p, GameConstant.GetViewRange(unitType));
 }
 public Game() //Keeps track of stuff between scenes for us. Will have to use "Game.current = new Game();" when exiting title screen so this all tracks.
 {
     trackingGame = new GameConstant();
 }
Beispiel #13
0
        private void ThinkWorker()
        {
            #region 村の建設
            //if (NeedToBuildVillage() && currentResource >= GameConstant.GetCost(UnitType.Village))
            //{
            //    var resourcePoints = GetResourcePoints(resource);

            //    // 現在判明している資源の位置への距離の和が最小となる点
            //    // 重み付けしてもよいかも
            //    Point p = FieldIter
            //        .MinBy(point =>
            //            resourcePoints
            //            .OrderBy(r => Game.Manhattan(r, myCastle.Point))
            //            .Take(3)
            //            .Sum(resourcePoint =>
            //                Game.Manhattan(point, resourcePoint)));

            //    var freeWorker = myUnits.Values
            //        .Where(unit => unit.IsFree && unit.Type == UnitType.Worker);

            //    if (freeWorker.Count() > 0)
            //    {
            //        MyUnit u = freeWorker.MinBy(unit => Game.Manhattan(unit.Point, p));

            //        // @magicnumber
            //        if (Game.Manhattan(u.Point, p) <= 10)
            //        {
            //            // @magicnumber
            //            u.Produce = UnitType.Village;
            //        }
            //        else
            //        {
            //            u.MoveTo = p;
            //        }
            //    }

            //}
            #endregion

            #region 拠点の建設
            if (NeedToBuildFactory() && currentResource >= GameConstant.GetCost(UnitType.Factory))
            {
                var resourcePoints = GetResourcePoints(resource);
                // 現在判明している資源の位置への距離の和が最小となる点
                // 重み付けしてもよいかも
                Point p = FieldIter
                          .MinBy(point =>
                                 resourcePoints
                                 .OrderBy(r => Game.Manhattan(r, myCastle.Point))
                                 .Take(3)
                                 .Sum(resourcePoint =>
                                      Game.Manhattan(point, resourcePoint)));

                if (MyFreeWorkers.Count() > 0)
                {
                    MyUnit u = MyFreeWorkers.MinBy(unit => Game.Manhattan(unit.Point, p));

                    if (Game.Manhattan(u.Point, p) == 0)
                    {
                        u.Produce = UnitType.Factory;
                    }
                    else
                    {
                        u.MoveTo = p;
                    }
                }
            }
            #endregion

            var candidates = SortResourcePriority().Take(ThinkMaxControlledResourceNum());
            foreach (var point in candidates)
            {
                var move = MyFreeWorkers.OrderBy(unit => Game.Manhattan(unit.Point, point)).Take(5);
                foreach (var unit in move)
                {
                    unit.MoveTo = point;
                }
            }

            foreach (var worker in MyFreeWorkers)
            {
                worker.MoveTo = myCastle.Point;
            }
        }
Beispiel #14
0
 public Unit(UnitType type, int id, Point point)
     : this(type, id, point, GameConstant.GetDefaultHp(type))
 {
 }
Beispiel #15
0
	public GameConstant getGameConstant(){
		if(gameConstant==null){
			gameConstant=new GameConstant();
		}
		return gameConstant;
	}
Beispiel #16
0
 public void GetViewRangeTest()
 {
     Assert.AreEqual(10, GameConstant.GetViewRange(UnitType.Castle));
     Assert.AreEqual(4, GameConstant.GetViewRange(UnitType.Worker));
 }
Beispiel #17
0
    private IEnumerator StartRequestResource()
    {
        TextAsset text = Resources.Load <TextAsset>("version");

        if (null == text)
        {
            Logger.LogError("load versoin text failed!!!");
            yield break;
        }
        else
        {
            clientVersionConfig = Pathfinding.Serialization.JsonFx.JsonReader.Deserialize <ClientVersionConfig>(text.text);
            if (null == clientVersionConfig)
            {
                Logger.LogError("deserialize client version text failed!!!");
                yield break;
            }
        }

        DeviceInfo.SetGameVersion(clientVersionConfig.GameVersion);
        string versionFileName = string.Format("version_{0}.json", DeviceInfo.GameVersion);

        for (int index = 0; index < clientVersionConfig.ResourceUrls.Count; ++index)
        {
            ResourceItem item          = clientVersionConfig.ResourceUrls[index];
            string       requestUrl    = string.Format("{0}{1}/{2}/{3}", item.Url, GameConstant.PlatformDirectory, DeviceInfo.GameVersion.ToLower(), versionFileName);
            string       platformInfos = string.Empty;
            AssetBundleManager.Instance.DownloadAssetAsync(requestUrl, null, (abInfo) =>
            {
                platformInfos = abInfo.text;
            });
            float startTime = Time.realtimeSinceStartup;
            while (Time.realtimeSinceStartup - startTime < item.Timeout)
            {
                if (!string.IsNullOrEmpty(platformInfos))
                {
                    try
                    {
                        serverVersionConfig = Pathfinding.Serialization.JsonFx.JsonReader.Deserialize <ServerVersionConfig>(platformInfos);
                        if (null != serverVersionConfig)
                        {
                            GameConstant.SetResourceUrl(item.Url);
                            break;
                        }
                    }
                    catch
                    {
                        Logger.LogError("deserialize server version config failed!!!");
                    }
                }
                yield return(null);
            }

            if (null != serverVersionConfig)
            {
                break;
            }
        }

        yield return(StartCoroutine(SetPlatformConfig()));
    }
Beispiel #18
0
        public IOrder CreateOrder()
        {
            Debug.Assert(this.Id != -1);

            if (IsProducing)
            {
                Debug.Assert(
                    this.Type == UnitType.Worker ||
                    this.Type == UnitType.Castle ||
                    this.Type == UnitType.Village ||
                    this.Type == UnitType.Factory
                    );
#if DEBUG
                switch (this.Type)
                {
                case UnitType.Worker:
                    Debug.Assert(Produce == UnitType.Village || Produce == UnitType.Factory);
                    break;

                case UnitType.Castle:
                    Debug.Assert(Produce == UnitType.Worker);
                    break;

                case UnitType.Village:
                    Debug.Assert(Produce == UnitType.Worker);
                    break;

                case UnitType.Factory:
                    Debug.Assert(Produce == UnitType.Knight || Produce == UnitType.Fighter || Produce == UnitType.Assassin);
                    break;
                }
#endif
                return(new Order(this.Id, GameConstant.Build(Produce.Value)));
            }

            if (IsMoving)
            {
                Debug.Assert(this.Point != null);
                Debug.Assert(this.Type == UnitType.Worker || this.Type == UnitType.Knight || this.Type == UnitType.Fighter || this.Type == UnitType.Assassin);

                int dx = Math.Abs(Point.X - MoveTo.X);
                int dy = Math.Abs(Point.Y - MoveTo.Y);
                if (dx + dy > 0)
                {
                    if (dy <= dx)
                    {
                        if (Point.X < MoveTo.X)
                        {
                            return(new Order(this.Id, OrderType.MoveR));
                        }

                        if (Point.X > MoveTo.X)
                        {
                            return(new Order(this.Id, OrderType.MoveL));
                        }
                    }
                    else
                    {
                        if (Point.Y < MoveTo.Y)
                        {
                            return(new Order(this.Id, OrderType.MoveD));
                        }

                        if (Point.Y > MoveTo.Y)
                        {
                            return(new Order(this.Id, OrderType.MoveU));
                        }
                    }
                }
            }

            return(null);
        }