public bool TryHit(Location location)
        {
            if (location.X < 0 || location.X >= _mapConfiguration.Width)
            {
                throw new InvalidOperationException("X coorinate is out of range.");
            }

            if (location.Y < 0 || location.Y >= _mapConfiguration.Height)
            {
                throw new InvalidOperationException("X coorinate is out of range.");
            }

            if (GetMapCellStatus(location.X, location.Y) != MapCellStatus.Default)
            {
                throw new InvalidOperationException("This cell has already been chosen.");
            }

            var isHit = Ships.Any(ship => ship.TryHit(location));

            if (isHit)
            {
                Hits.Add(location);
            }
            else
            {
                Misses.Add(location);
            }

            return(isHit);
        }
        public void Run(IProgress <BuddhabrotReportProgress> progress = null)
        {
            long previousTotalHits = 0;

            do
            {
                float cx    = XMin + (float)Rand.NextDouble() * (XMax - XMin);
                float cy    = YMin + (float)Rand.NextDouble() * (Ymax - YMin);
                var   point = new BuddhabrotPoint(cx, cy, MaxIteration);
                Hits.Add(point);
                if ((TotalHits - previousTotalHits * 1d) / HitsMax > 1 / 100d)
                {
                    previousTotalHits = TotalHits;
                    if (progress != null)
                    {
                        //progress.Report(new BuddhabrotReportProgress(this));
                    }
                }
            }while (Hits.Count < HitsMax);

            Completed = true;
            if (progress != null)
            {
                // progress.Report(new BuddhabrotReportProgress(this, true));
            }
        }
示例#3
0
        public CodeCoverageTracer(List <CodeCoveragePoint> points)
        {
            _debug     = Environment.GetEnvironmentVariable("PESTER_CC_DEBUG") == "1";
            _debugFile = Environment.GetEnvironmentVariable("PESTER_CC_DEBUG_FILE") ?? "CoverageTestFile";
            foreach (var point in points)
            {
                var key = $"{point.Line}:{point.Column}";
                if (!Hits.ContainsKey(point.Path))
                {
                    var lineColumn = new Dictionary <string, List <CodeCoveragePoint> > (StringComparer.OrdinalIgnoreCase)
                    {
                        [key] = new List <CodeCoveragePoint> {
                            point
                        }
                    };
                    Hits.Add(point.Path, lineColumn);
                    continue;
                }

                var hits = Hits[point.Path];
                if (!hits.ContainsKey(key))
                {
                    hits.Add(key, new List <CodeCoveragePoint> {
                        point
                    });
                    continue;
                }
                else
                {
                    var pointsOnLineAndColumn = hits[key];
                    pointsOnLineAndColumn.Add(point);
                }
            }
        }
示例#4
0
        /// <summary>
        /// If Boat is hit, return true and add hit to Boat
        /// </summary>
        /// <param name="position">Hit position (Position)</param>
        /// <returns>Validate result (bool)</returns>
        public bool IsItAHit(Position position)
        {
            if (AreYouHere(position))
            {
                Hits.Add(position);
                return(true);
            }

            return(false);
        }
示例#5
0
 public void UpdateLogs(Fighter fighter)
 {
     Hits.Add(fighter.Hits);
     Health.Add(fighter.HealthPoints);
     DealtDamage.Add(fighter.DealtDamage);
     Rounds.Add(fighter.Rounds);
     if (!fighter.IsAlive())
     {
         Deaths++;
     }
 }
示例#6
0
        protected override void UpdateCast()
        {
            var   position       = CachedTransform.position;
            var   rotation       = CachedTransform.eulerAngles;
            var   scale          = CachedTransform.lossyScale;
            float angleIncrement = 0f;

            if (Amount > 1)
            {
                angleIncrement = Spread / (Amount - 1);
                rotation.z    -= Spread / 2f;
            }

            for (int i = 0; i < Amount; i++)
            {
                Vector2 direction = Quaternion.Euler(rotation) * Vector2.right;
                direction.Scale(scale);

                RaycastHit2D hit;

                if (Draw && Application.isEditor)
                {
                    Debug.DrawRay(position, direction * Distance, Color.green);
                }

                switch (HitMode)
                {
                case RaycastHitModes.First:
                    hit = Physics2D.Raycast(position, direction, Distance, Mask);

                    if (hit.collider != null)
                    {
                        Hits.Add(hit);
                        return;
                    }
                    break;

                case RaycastHitModes.FirstOfEach:
                    hit = Physics2D.Raycast(position, direction, Distance, Mask);

                    if (hit.collider != null)
                    {
                        Hits.Add(hit);
                    }
                    break;

                case RaycastHitModes.All:
                    Hits.AddRange(Physics2D.RaycastAll(position, direction, Distance, Mask));
                    break;
                }

                rotation.z += angleIncrement;
            }
        }
示例#7
0
        public void updateHitsAndPushPins(Hit item)
        {
            Pushpin  pin          = new Pushpin();
            Location tempLocation = new Location();

            Hits.Add(item);
            tempLocation.Latitude  = item.Latitude;
            tempLocation.Longitude = item.Longitude;
            pin.Location           = tempLocation;
            pin.Background         = new SolidColorBrush(ToMediaColor(System.Drawing.Color.FromName("Red")));
            pushpins.Add(pin);
        }
示例#8
0
    public override void OnHit()
    {
        foreach (CharacterAction_Effect hit in Data.hit)
        {
            CharacterAction_Effect new_hit = hit.Clone(Data, self);
            new_hit.time = PlaybackTime;
            new_hit.Play(false, 0f);
            new_hit.Update(PlaybackTime);

            Hits.Add(new_hit);
        }
    }
示例#9
0
        public override void Initialize(Vector2 Position)
        {
            texPath = "AntiBody";

            Mass        = 0.5f;
            Restitution = 1f;
            Damping     = 0.97f;
            Hits.Add(new Hitbox(new Vector2(Position.X, Position.Y + 3), 16, 6, 45, this));
            Hits.Add(new Hitbox(new Vector2(Position.X + 16, Position.Y + 3), 16, 6, -45, this));
            Hits.Add(new Hitbox(new Vector2(Position.X + 12, Position.Y + 16), 4, 16, 0, this));
            base.Initialize(Position);
        }
示例#10
0
        public bool IsHit(float x, float y, float spriteWidth)
        {
            bool hit = false;

            foreach (Brick b in Bricks)
            {
                if (Collision(new PointF(b.Location.X + Brick.Width / 2, b.Location.Y + Brick.Width / 2), new PointF(x + spriteWidth / 2, y + spriteWidth / 2)))
                {
                    Hits.Add(b.Id); hit = true;
                }
            }
            return(hit);
        }
示例#11
0
        internal void UpdateList(PazPar2Show pp2Show)
        {
            LastMergeCount = pp2Show.merged;
            LastUpdateTime = DateTime.Now;
            List <Hit> sList = pp2Show.Hits;

            Hits.RemoveAll();
            foreach (Hit hit in pp2Show.Hits)
            {
                Hits.Add(hit);
            }

            Pici.Log.debug(typeof(Page), "FireListUpdated for page " + Index);
            Hits.FireListUpdated();

            //bool isUpdated = false;
            //ItemList<Hit> tList = Hits;
            ////remove items not in current list
            //IEnumerable<Hit> toRemove = from sHit in sList where !tList.Contains<Hit>(sHit) select sHit;
            //foreach (var item in toRemove.ToList())
            //{
            //    isUpdated = isUpdated || tList.Remove(item);
            //}

            ////insert missing items
            //for (int idx = 0; idx < sList.Count; idx++)
            //{
            //    Hit sItem = sList.ElementAt(idx);
            //    if (tList.Count <= idx || !sItem.Equals(tList.ElementAt(idx)))
            //    {
            //        tList.Insert(idx, sItem);
            //        isUpdated = true;
            //        //Task t = await  PP2_Record(sItem));
            //    }
            //}

            ////remove 'tail' of sourceList (items which moved up in position are inserted before and the old instance is still at the end of the list)
            //while (tList.Count > sList.Count)
            //{
            //    tList.RemoveAt(sList.Count);
            //    isUpdated = true;
            //}

            //if (isUpdated)
            //{
            //    Pici.Log.debug(typeof(Page), "FireListUpdated for page " + Index);
            //    tList.FireListUpdated();
            //}
        }
示例#12
0
        private async Task SelectedChangedAsync(Event _event)
        {
            if (SelectedEvents.All(e => e != _event))
            {
                foreach (var report in Reports.ToArray())
                {
                    if (report.Event.Id == _event.Id)
                    {
                        Reports.Remove(report);
                    }
                }
                foreach (var Hit in Hits.ToArray())
                {
                    if (Hit.Event.Id == _event.Id)
                    {
                        Hits.Remove(Hit);
                    }
                }
            }
            else
            {
                var reports = await MapModel.GetReports(_event.Id);

                var hits = await MapModel.GetHits(_event.Id);

                foreach (var report in reports)
                {
                    Reports.Add(report);
                }
                foreach (var hit in hits)
                {
                    Hits.Add(hit);
                }
            }
            OnPropertyChanged(nameof(LocationList));
        }
 public HitResult(Hit hit)
     : this()
 {
     Hits.Add(hit);
 }
 /// <summary>
 /// Adds the specified row.
 /// </summary>
 /// <param name="row">The row.</param>
 internal void Add(ISearchQueryRow row)
 {
     Hits.Add(row);
 }
示例#15
0
        public IEnumerable <Hit> Search(params string[] terms)
        {
            var locker = new Object();

            Terms = terms.Select(t => Formatter.Format(t)).ToList();
            var revList = Terms.Select(t => Reverse(t)).ToArray();

            Terms.AddRange(revList);
            Limit = Terms.OrderByDescending(t => t.Length).FirstOrDefault().Length;
            var hitCache = new List <int>();

            for (var pos = Start; pos < Stop; pos++)
            {
                var args = new ProgressUpdatedEventArgs(pos + 1);
                OnProgressUpdated(args);
                if (args.Cancel)
                {
                    break;
                }
                var length = Stop - pos;

                Parallel.For(FromSkip, ToSkip, new ParallelOptions
                {
                    MaxDegreeOfParallelism = ToSkip - FromSkip
                }, skip =>
                {
                    var text = Range(Text, pos, Stop);
                    var size = (int)Math.Ceiling((double)(length / skip));
                    if (size < Limit)
                    {
                        return;
                    }
                    var sequence = Sequence(text, skip);

                    foreach (var term in Terms)
                    {
                        var indices = IndicesOf(sequence, term);
                        if (indices.Length == 0)
                        {
                            continue;
                        }

                        foreach (var index in indices)
                        {
                            var hindex = ((index * skip) + pos);

                            if (!hitCache.Contains(hindex))
                            {
                                lock (locker)
                                {
                                    hitCache.Add(hindex);
                                    Hits.Add(new Hit(term, hindex, pos, skip));
                                }
                            }
                        }
                    }
                });
            }

            hitCache.Clear();

            if (Proximity != -1)
            {
                Hits = GetProximalHits(Proximity).ToList();
            }

            Grid = OffsetHitsToGrid(Hits);
            return(Hits);
        }
示例#16
0
        private void GoOneStep(DirectionData directionData, DirectionData otherSide, Hits hits, DirectionData startSide, bool stopAsap)
        {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            if (!directionData.HasNext())
            {
                // We can not go any deeper from this direction. Possibly disconnected nodes.
                otherSide.FinishCurrentLayerThenStop = true;
                return;
            }
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            Node      nextNode     = directionData.Next();
            LevelData otherSideHit = otherSide.VisitedNodes[nextNode];

            if (otherSideHit != null)
            {
                // This is a hit
                int depth = directionData.CurrentDepth + otherSideHit.Depth;

                if (directionData.SharedFrozenDepth.intValue() == Null)
                {
                    directionData.SharedFrozenDepth.Value = depth;
                }
                if (depth <= directionData.SharedFrozenDepth.intValue())
                {
                    directionData.HaveFoundSomething = true;
                    if (depth < directionData.SharedFrozenDepth.intValue())
                    {
                        directionData.SharedFrozenDepth.Value = depth;
                        // TODO Is it really ok to just stop the other side here?
                        // I'm basing that decision on that it was the other side
                        // which found the deeper paths (correct assumption?)
                        otherSide.Stop = true;
                    }
                    // Add it to the list of hits
                    DirectionData startSideData = directionData == startSide ? directionData : otherSide;
                    DirectionData endSideData   = directionData == startSide ? otherSide : directionData;
                    Hit           hit           = new Hit(startSideData, endSideData, nextNode);
                    Node          start         = startSide.StartNode;
                    Node          end           = (startSide == directionData) ? otherSide.StartNode : directionData.StartNode;
                    MonitorData(startSide, (otherSide == startSide) ? directionData : otherSide, nextNode);
                    // NOTE: Applying the filter-condition could give the wrong results with allShortestPaths,
                    // so only use it for singleShortestPath
                    if (!stopAsap || FilterPaths(HitToPaths(hit, start, end, stopAsap)).Count > 0)
                    {
                        if (hits.Add(hit, depth) >= _maxResultCount)
                        {
                            directionData.Stop = true;
                            otherSide.Stop     = true;
                            _lastMetadata.paths++;
                        }
                        else if (stopAsap)
                        {                                   // This side found a hit, but wait for the other side to complete its current depth
                            // to see if it finds a shorter path. (i.e. stop this side and freeze the depth).
                            // but only if the other side has not stopped, otherwise we might miss shorter paths
                            if (otherSide.Stop)
                            {
                                return;
                            }
                            directionData.Stop = true;
                        }
                    }
                    else
                    {
                        directionData.HaveFoundSomething      = false;
                        directionData.SharedFrozenDepth.Value = Null;
                        otherSide.Stop = false;
                    }
                }
            }
        }