Example #1
0
        /// <summary>
        /// Find weakest neighbouring Micromon
        /// </summary>
        /// <param name="attacker">Attacking Micromon</param>
        /// <returns>The attack results on the weakest neighbouring Micromon, if all neighbours are of the same type, the default value is passed</returns>
        private ProbeResults FindWeakestNeighbour(Micromon attacker)
        {
            //Get all four potential targets
            Micromon[] targets = new Micromon[4];
            targets[0] = this[Utils.Clamp(0, this.Size, attacker.X - 1), attacker.Y];
            targets[1] = this[Utils.Clamp(0, this.Size, attacker.X + 1), attacker.Y];
            targets[2] = this[attacker.X, Utils.Clamp(0, this.Size, attacker.Y - 1)];
            targets[3] = this[attacker.X, Utils.Clamp(0, this.Size, attacker.Y + 1)];

            //Filter out invalid targets
            List <Micromon> valid = new List <Micromon>(targets.Where(m => attacker.Pair != m.Pair));

            //If no valid targets available, return default value
            if (valid.Count == 0)
            {
                return(new ProbeResults());
            }

            //Find the valid target with the highest possible damage
            ProbeResults highest = CalculateDamage(attacker, valid[0]);

            for (int i = 1; i < valid.Count; i++)
            {
                ProbeResults current = CalculateDamage(attacker, valid[i]);
                if (current.damage > highest.damage)
                {
                    highest = current;
                }
            }

            //Return the highest damage
            return(highest);
        }
        //Analyse the assemblies
        public bool Probe(string[] assemblyNames)
        {
            bool usesPI = false;

            this.LoadAssemblies(assemblyNames);
            this.resultsDoc = new ProbeResults();

            XmlElement assembliesElement = this.resultsDoc.AddAssembliesElement();

            usesPI = ProbeAssemblies(assembliesElement);
            this.resultsDoc.AddUsesPiAttribute(assembliesElement, usesPI);

            return(usesPI);
        }
Example #3
0
        /// <summary>
        /// Simulates a full round of attack and defending throughout the whole simulation Grid
        /// </summary>
        /// <param name="worker">BackgroundWorker to report the progress to</param>
        public void Simulate(BackgroundWorker worker)
        {
            //Loop through the full list
            for (LinkedListNode <Micromon> n = this.attackList.First; n != null; n = n.Next)
            {
                Micromon attacker = n.Value;

                //Find weakest neighbouring Micromon to attack
                ProbeResults result = FindWeakestNeighbour(attacker);
                Micromon     target = result.target;

                //If there is a potential target, attack it, if it succumbs, take over it's spot
                if (target != null && !target.Defend(result.damage))
                {
                    n = target.TakenOver(attacker);
                }

                //Report progress (increment bar)
                worker.ReportProgress(0);
            }
        }
Example #4
0
 private void Send(bool status)
 {
     ProbeResults.OnNext(status);
     _lastStatus = status;
 }