Пример #1
0
        public static RepairAction ReadFrom(System.IO.BinaryReader reader)
        {
            var result = new RepairAction();

            result.Target = reader.ReadInt32();
            return(result);
        }
Пример #2
0
        private void CommandUnitsWorkers()
        {
            foreach (var builderUnit in Around.MyUnitsWorkers) // All goes get spice milange because SPICE MUST FLOW
            {
                var nearestNotBusySpice = Around.GetNearestNotBusySpice(builderUnit.Position);

                var moveAction   = new MoveAction(nearestNotBusySpice.Position, true, false);
                var attackAction = new AttackAction(nearestNotBusySpice.Id, null);

                var action = new EntityAction(moveAction, null, attackAction, null);

                actions.Add(builderUnit.Id, action);
            }

            if (Around.RepairNeeds)
            {
                foreach (var brokenBuilding in Around.MyBuildingsBroken)
                {
                    var nearestBuilder = Around.GetNearestWorker(brokenBuilding.Position);
                    actions.Remove(nearestBuilder.Id);

                    var moveAction   = new MoveAction(brokenBuilding.Position, true, false);
                    var repairAction = new RepairAction(brokenBuilding.Id);
                    actions.Add(nearestBuilder.Id, new EntityAction(moveAction, null, null, repairAction));

                    // var hasBigDamage = brokenBuilding.Health <= View.EntityProperties.Single(ep => ep.Key == brokenBuilding.EntityType).Value.MaxHealth / 2;
                    // if (hasBigDamage)
                    // {
                    //     var nearestBuilder2 = Around.GetNearestWorker(brokenBuilding.Position);
                    //     actions.Remove(nearestBuilder2.Id);
                    //
                    //     moveAction = new MoveAction(brokenBuilding.Position, true, false);
                    //     repairAction = new RepairAction(brokenBuilding.Id);
                    //     actions.Add(nearestBuilder2.Id, new EntityAction(moveAction, null, null, repairAction));
                    // }
                }
            }

            if (Around.NeedBuildBuildingWorkers)
            {
                SendWorkerToBuild(EntityType.BuilderBase);
            }
            else if (Around.NeedBuildBuildingRanged)
            {
                SendWorkerToBuild(EntityType.RangedBase);
            }
            else if (Around.NeedBuildHouse)
            {
                SendWorkerToBuild(EntityType.House);
            }
        }
        public static void SetRepair(PlayerView playerView, Entity entity, Dictionary <int, EntityAction> entityActions)
        {
            if (entityActions.ContainsKey(entity.Id))
            {
                return;
            }

            if (ScoreMap.Get(entity.Position).AllDamage > 0)
            {
                return;
            }

            Entity?builder      = null;
            Entity?repairEntity = null;
            int    maxHealth    = int.MinValue;

            var neighbors = entity.Position.Neighbors();

            foreach (var target in neighbors)
            {
                var targetEntity = ScoreMap.Get(target).Entity;
                if (targetEntity == null)
                {
                    continue;
                }

                var entityProperties = playerView.EntityProperties[targetEntity.Value.EntityType];
                if (targetEntity.Value.PlayerId == ScoreMap.MyId &&
                    targetEntity.Value.Health < entityProperties.MaxHealth &&
                    (targetEntity.Value.EntityType == EntityType.BuilderBase ||
                     targetEntity.Value.EntityType == EntityType.MeleeBase ||
                     targetEntity.Value.EntityType == EntityType.RangedBase ||
                     targetEntity.Value.EntityType == EntityType.House ||
                     targetEntity.Value.EntityType == EntityType.Turret))
                {
                    if (targetEntity.Value.Health > maxHealth)
                    {
                        builder      = entity;
                        repairEntity = targetEntity;
                        maxHealth    = targetEntity.Value.Health;
                    }
                }
            }

            if (builder != null && repairEntity != null)
            {
                var repairAction = new RepairAction(repairEntity.Value.Id);
                entityActions.Add(builder.Value.Id, new EntityAction(null, null, null, repairAction));
            }
        }
Пример #4
0
        void repairLookup_EditValueChanged(object sender, EventArgs e)
        {
            LookUpEdit edit = (LookUpEdit)sender;

            RepairAction action =
                (RepairAction)
                edit.Properties.GetDataSourceRowByKeyValue(edit.EditValue);

            if (action == null)
            {
                return;
            }

            if ((action != RepairAction.None))
            {
                AddReplacementComponents();
            }
        }
Пример #5
0
    private void RPC_AddAction(string data, PhotonMessageInfo info)
    {
        string[] actionData      = data.Split(',');
        Action   actionToPerform = new Action(this);

        switch (actionData[1])
        {
        case "hitShip":
            actionToPerform = new HitShipAction(this);
            break;

        case "move":
            actionToPerform = new MoveAction(this);
            break;

        case "search":
            actionToPerform = new SearchAction(this);
            break;

        case "repair":
            actionToPerform = new RepairAction(this);
            break;

        case "heal":
            actionToPerform = new HealAction(this);
            break;

        case "boostShields":
            actionToPerform = new BoostShieldsAction(this);
            break;

        case "share":
            actionToPerform = new ShareAction(this);
            break;

        case "suffocate":
            actionToPerform = new SuffocateAction(this);
            break;
        }

        actionToPerform.Deserialize(actionData);
        actions.Add(int.Parse(actionData[0]), actionToPerform);
    }
Пример #6
0
        public void BatchRepair(string casesFilesDir, BatchPlanner planner, double overhead, int maxNumOfDiag)
        {
            Console.WriteLine(planner.Type() + " o=" + overhead);
            Stopwatch stopwatch = new Stopwatch();
            CSVExport myExport  = new CSVExport();
            List <PhysioCaseInstance> physioCases = new List <PhysioCaseInstance>();
            List <string>             files       = Directory.GetFiles(casesFilesDir).ToList();

            foreach (string file in files)
            {
                PhysioCaseInstance physioCase = caseParser.ParseCase(file);
                if (physioCase != null)
                {
                    physioCases.Add(physioCase);
                }
            }
            foreach (PhysioCaseInstance physioCase in physioCases)
            {
                if (physioCase.Diagnoses.Count < 2 || (physioCase.Diagnoses.Count > maxNumOfDiag && maxNumOfDiag > 0))//!!
                {
                    continue;
                }
                // Console.WriteLine(physioCase.Id); //!!
                int         iterationCounter = 0;
                double      totalCost        = 0;
                int         numberOfFixed    = 0;
                int         expanded         = 0;
                bool        foundOpt         = true;
                bool        finished         = false;
                List <Comp> toRepair         = new List <Comp>(physioCase.RealDiagnosis.Diag);
                SystemState currSystemState  = new SystemState(physioCase.Diagnoses.Components);
                currSystemState.Diagnoses = physioCase.Diagnoses; //!! check for bug
                stopwatch.Start();
                while (!finished)
                {
                    RepairAction action = planner.Plan(currSystemState);
                    if (action == null)
                    {
                        break; //!!
                    }
                    iterationCounter++;
                    totalCost     += overhead;
                    numberOfFixed += action.Count;
                    foreach (Comp comp in action.R)
                    {
                        totalCost += comp.Cost;
                        if (toRepair.Contains(comp))
                        {
                            toRepair.Remove(comp);
                        }
                    }
                    if (toRepair.Count > 0)
                    {
                        currSystemState.SetNextState(action);
                    }
                    else
                    {
                        finished = true;
                    }
                    if (iterationCounter == 1)
                    {
                        expanded = planner.IterationDetails.NumOfExpanded;
                        foundOpt = planner.IterationDetails.FoundOpt;
                    }
                    planner.ExportIterationDetails("1", physioCase.Id, iterationCounter, finished);
                }
                if (!finished)//!!
                {
                    continue;
                }
                stopwatch.Stop();
                int time = stopwatch.Elapsed.Milliseconds;
                stopwatch.Reset();
                myExport.AddRow();
                //myExport["System"] = model.Id;
                myExport["Algorithm"] = planner.Algorithm();
                if (planner.Bounded)
                {
                    myExport["Bound"] = planner.Bound;
                }
                else
                {
                    myExport["Bound"] = "No Bound";
                }
                myExport["Objective Function"] = planner.ObjectiveFunction();
                myExport["Overhead"]           = overhead;
                myExport["Observation"]        = physioCase.Id;
                myExport["# Diagnoses"]        = physioCase.Diagnoses.Count;
                myExport["Runtime(ms)"]        = time;
                myExport["# Iterations"]       = iterationCounter;
                myExport["Cost"] = totalCost;
                myExport["# Fixed Components"]            = numberOfFixed;
                myExport["# Expanded In First Iteration"] = expanded;
                myExport["Found Opt"] = foundOpt;
            }
            string fileName = "Physiotherapy " + planner.Type() + "_o=" + overhead;

            if (maxNumOfDiag > 0)
            {
                fileName += "_MaxDiag" + maxNumOfDiag;
            }
            myExport.ExportToFile(fileName + ".csv");
            planner.CreateIterationDetailsFile(fileName + "_IterationDetails");
        }