Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8631699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:15:13+00:00 2026-06-12T09:15:13+00:00

Anyone know a simple algorithm to implement in C# to detect monster groups in

  • 0

Anyone know a simple algorithm to implement in C# to detect monster groups in a 2D game.

EX:
100 Range around the char there are monsters. I want to detect which monsters are within range 2 of each other, and if there is at-least 5 together, use the Area of Effect skill on that location. Otherwise use the single-target skill.

A link to an implementation would be great, C# preferably. I just get lost reading the Wikipedia articles.

EDIT:
“your question is incomplete. what do you want to do exactly? do you want to find all groups? the biggest group? any group, if there are groups, none otherwise? please be more specific.” -gilad hoch

I want to find all groups within 100 units of range around the main character. The groups should be formed if there are at-least 5 or more monsters all within 2 range of each other, or maybe within 10 range from the center monster.

So the result should be probably a new List of groups or a List of potential target locations.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T09:15:14+00:00Added an answer on June 12, 2026 at 9:15 am

    I recently implemented the algorithm given in this paper by Efraty, which solves the problem by considering the intersections of circles of radius 2 centered at each given point. In simple terms, if you order the points in which two circles intersect in clockwise order, then you can do something similar to a line sweep to figure out the point in which a bomb (or AoE spell) needs to be launched to hit the most enemies. The implementation is this:

    #include <stdio.h>
    #include <cmath>
    #include <algorithm>
    
    using namespace std;
    
    #define INF 1e16
    #define eps 1e-8
    #define MAXN 210
    #define RADIUS 2
    
    struct point {
        double x,y;
    
        point() {}
        point(double xx, double yy) : x(xx), y(yy) {}
    
        point operator*(double ot) {
            return point(x*ot, y*ot);
        }
    
        point operator+(point ot) {
            return point(x+ot.x, y+ot.y);
        }
    
        point operator-(point ot) {
            return point(x-ot.x, y-ot.y);
        }
    
        point operator/(double ot) {
            return point(x/ot, y/ot);
        }
    };
    
    struct inter {
        double x,y;
        bool entry;
        double comp;
    
        bool operator< (inter ot) const {
            return comp < ot.comp;
        }
    };
    
    double dist(point a, point b) {
        double dx = a.x-b.x;
        double dy = a.y-b.y;
        return sqrt(dx*dx+dy*dy);
    }
    
    int N,K;
    point p[MAXN];
    inter it[2*MAXN];
    
    
    struct distst {
        int id, dst;
        bool operator<(distst ot) const {return dst<ot.dst;}
    };
    
    distst dst[200][200];
    point best_point;
    
    double calc_depth(double r, int i) {
        int left_inter = 0;
    
        point left = p[i];
        left.y -= r;
        best_point = left;
    
        int tam = 0;
    
        for (int k = 0; k < N; k++) {
            int j = dst[i][k].id;
            if (i==j) continue;
    
            double d = dist(p[i], p[j]);
    
            if (d > 2*r + eps) break;
            if (fabs(d)<eps) {
                left_inter++;
                continue;
            }
    
            bool is_left = dist(p[j], left) < r+eps;
            if (is_left) {
                left_inter++;
            }
    
            double a = (d*d) / (2*d);
    
            point diff = p[j] - p[i];
            point p2 = p[i] + (diff * a) / d;
    
            double h = sqrt(r*r - a*a);
    
            it[tam].x = p2.x + h*( p[j].y - p[i].y ) / d;
            it[tam].y = p2.y - h*( p[j].x - p[i].x ) / d;  
    
            it[tam+1].x = p2.x - h*( p[j].y - p[i].y ) / d;
            it[tam+1].y = p2.y + h*( p[j].x - p[i].x ) / d; 
    
            it[tam].x -= p[i].x;
            it[tam].y -= p[i].y;
            it[tam+1].x -= p[i].x;
            it[tam+1].y -= p[i].y;
    
            it[tam].comp = atan2(it[tam].x, it[tam].y);
            it[tam+1].comp = atan2(it[tam+1].x, it[tam+1].y);
    
            if (it[tam] < it[tam+1]) {
                it[tam].entry = true;
                it[tam+1].entry = false;
            }
            else {
                it[tam].entry = false;
                it[tam+1].entry = true;
            }
    
            if (is_left) {
                swap(it[tam].entry, it[tam+1].entry);
            }
    
            tam+=2;
        }
    
        int curr,best;
        curr = best = left_inter;
    
        sort(it,it+tam);
    
        for (int j = 0; j < tam; j++) {
            if (it[j].entry) curr++;
            else curr--;
    
            if (curr > best) {
                best = curr;
                best_point = point(it[j].x, it[j].y);
            }
        }
    
        return best;
    }
    
    int main() {
        scanf("%d", &N);
        for (int i = 0; i < N; i++) {
            scanf("%lf %lf", &p[i].x, &p[i].y);
        }
    
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                dst[i][j].id = j;
                dst[i][j].dst = dist(p[i],p[j]);
            }
            sort(dst[i],dst[i]+N);
        }
    
        int best = 0;
        point target = p[0];
        for (int i = 0; i < N; i++) {
            int depth = calc_depth(RADIUS, i);
            if (depth > best) {
                best = depth;
                target = best_point;
            }
        }
    
        printf("A bomb at (%lf, %lf) will hit %d target(s).\n", target.x, target.y, best+1);
    }
    

    Sample usage:

    2 (number of points) 
    0 0
    3 0
    A bomb at (1.500000, 1.322876) will hit 2 targets.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: PHP: Script for generating Crossword game? Does anyone know any PHP-based simple
Does anyone know a simple algorithm to check if a Sudoku-Configuration is valid? The
Does anyone know of a simple HTML5/CSS3 framework which applies a minimum of formatting
Does anyone know of a simple way to set a selected index or item
Does anyone know of some (very) simple tutorials on line on the WCF? Basically
Does anyone know of any tools to provide simple, fast queries of flat files
Does anyone know where I may find a really simple easy jQuery and PHP
Does anyone know if there is an sample code for using Visual Basic to
Does anyone know of a simple gmtime or ctime implementation without consideration for timezone,
I've been looking around for a simple algorithm to get and set the brightness

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.