示例#1
0
            public void Update()
            {
                Units.Clear();
                Buildings.Clear();

                MyPositions.Clear();
                OpponentPositions.Clear();
                NeutralPositions.Clear();

                Output.Clear();
                PreviousState.Clear();

                // --------------------------------------

                MyGold         = int.Parse(Console.ReadLine());
                MyIncome       = int.Parse(Console.ReadLine());
                OpponentGold   = int.Parse(Console.ReadLine());
                OpponentIncome = int.Parse(Console.ReadLine());

                // Read Map
                for (var y = 0; y < HEIGHT; y++)
                {
                    var line = Console.ReadLine();
                    for (var x = 0; x < WIDTH; x++)
                    {
                        var c = line[x] + "";
                        Map[x, y].IsWall      = c == "#";
                        Map[x, y].Active      = "OX".Contains(c);
                        Map[x, y].Owner       = c.ToLower() == "o" ? ME : c.ToLower() == "x" ? OPPONENT : NEUTRAL;
                        Map[x, y].HasMineSpot = MineSpots.Count(spot => spot == (x, y)) > 0;

                        Position p = (x, y);
                        if (Map[x, y].IsOwned)
                        {
                            MyPositions.Add(p);
                        }
                        else if (Map[x, y].IsOpponent)
                        {
                            OpponentPositions.Add(p);
                        }
                        else if (!Map[x, y].IsWall)
                        {
                            NeutralPositions.Add(p);
                        }
                    }
                }

                // Read Buildings
                var buildingCount = int.Parse(Console.ReadLine());

                for (var i = 0; i < buildingCount; i++)
                {
                    var inputs = Console.ReadLine().Split(' ');
                    Buildings.Add(new Building
                    {
                        Owner    = int.Parse(inputs[0]),
                        Type     = (BuildingType)int.Parse(inputs[1]),
                        Position = (int.Parse(inputs[2]), int.Parse(inputs[3]))
                    });
        /// <summary>
        /// For a system
        /// \f$
        /// \frac{\partial U}{dt} + F(U) = 0,
        /// \f$
        /// evaluates
        /// \f$
        /// || \frac{U_1 - U_0}{\Delta t} + F(U_1) ||
        /// \f$
        /// in the associated relative residuals in L2 and the Linf norm.
        /// </summary>
        /// <param name="timeStepNumber"></param>
        /// <param name="dt"></param>
        /// <param name="phystime">not used</param>
        public override IDictionary <string, double> LogTimeStep(int timeStepNumber, double dt, double phystime)
        {
            Dictionary <string, double> result = new Dictionary <string, double>();

            if (residualInterval < 1)
            {
                return(result);
            }

            if (this.ShouldLog(timeStepNumber, residualInterval))
            {
                double beta;
                if (dt == 0.0)
                {
                    // r = F(u1)
                    beta = 0.0;
                    PreviousState.Clear();
                }
                else
                {
                    // r = (u1-u0)/dt + F(u1)
                    beta = -1.0 / dt;
                    for (int i = 0; i < CurrentState.Dim; i++)
                    {
                        PreviousState[i].Acc(-1.0, CurrentState[i]);
                    }
                }

                CoordinateVector resultVector = new CoordinateVector(
                    new CoordinateMapping(PreviousState.ToArray()));
                evaluator.Evaluate(1.0, beta, resultVector);

                for (int i = 0; i < CurrentState.Dim; i++)
                {
                    double abs = PreviousState[i].L2Norm();
                    double rel = abs / CurrentState[i].L2Norm();

                    result.Add("rigorous_L2_abs_" + CurrentState[i].Identification, abs);

                    baseLogger.CustomValue(abs, "residual_abs_" + CurrentState[i].Identification);
                    baseLogger.CustomValue(rel, "residual_rel_" + CurrentState[i].Identification);
                }
            }

            // If residuals will be calculated in next time-step
            if ((timeStepNumber + 1) % residualInterval == 0 &&
                dt != 0.0)
            {
                PreviousState = CurrentState.CloneAs();
            }

            return(result);
        }