Пример #1
0
    /// <summary>
    ///     FORMAT = [G : Pn;x,y;d;shot;health;coins;points : ... : Pn;x,y;d;shot;health;coins;points : x,y,damage; ...
    ///     ;x,y,damage#]
    /// </summary>
    /// <param name="command">Command.</param>
    private void GameUpdateExec(string command)
    {
        try {
            var data = command.Substring(2).Split(':');
            var consumedCoinPacks = new List <CoinPack>();
            var consumedLifePacks = new List <LifePack>();


            foreach (var d in data)
            {
                if (d [0] == 'P')
                {
                    // Tank Status Update [Pn;x,y;d;shot;health;coins;points]
                    var state = d.Split(';');
                    var tank  = tanks [int.Parse(state [0].Substring(1))];
                    tank.x         = int.Parse(state [1].Split(',') [0]);
                    tank.y         = int.Parse(state [1].Split(',') [1]);
                    tank.direction = (Direction)int.Parse(state [2]);
                    tank.isShot    = int.Parse(state [3]) == 1;
                    tank.health    = int.Parse(state [4]);
                    tank.coins     = int.Parse(state [5]);
                    tank.points    = int.Parse(state [6]);
                    consumedCoinPacks.AddRange(coinpacks.Where(p => p.x == tank.x && p.y == tank.y));
                    consumedLifePacks.AddRange(lifepacks.Where(p => p.x == tank.x && p.y == tank.y));
                }
                else
                {
                    // Cell status update [x,y,damage ; ... ; x,y,damage]
                    foreach (var locationupdate in d.Split(';'))
                    {
                        var info = locationupdate.Split(',');
                        var cell = cells.FirstOrDefault(c => c.x == int.Parse(info [0]) && c.y == int.Parse(info [1]));
                        if (cell != null)
                        {
                            cell.damage = (CellDamage)int.Parse(info [2]);
                        }
                    }
                }
            }

            // Generate all Tanks and Cells
            GenerateGameObjects.GetInstance().GenerateCells(cells);
            GenerateGameObjects.GetInstance().GenerateTanks(tanks);

            RemoveExpiredPacks();
            RemoveConsumedPacks(consumedCoinPacks, consumedLifePacks);

            ScoreManager.GetInstance().updateScore(tanks);

            var thread = new System.Threading.Thread(() =>
            {
                var nextMove = new AI(playerNo.Value, 2).GetNextBestMove(tanks, cells, lifepacks, coinpacks).ToString();
                Debug.LogWarning("Result for next Move - " + nextMove.ToString());
                ServerConnect.MakeC2SRequest(nextMove.ToString().ToUpper() + "#");
            });
            thread.Priority = System.Threading.ThreadPriority.Highest;
            thread.Start();
        } catch (Exception ex) {
            Debug.LogException(ex);
        }
    }