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 8638675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:47:51+00:00 2026-06-12T10:47:51+00:00

This is not really a maze, but the idea is similar. I have this:

  • 0

This is not really a maze, but the idea is similar.

I have this:

enter image description here

The problem is where I circled in red. I need a way to get rid of rectangles that are not part of the rest of the puzzle.

I created a simple algorithm which works for a square:

The way this works is each element of the 2D array represents a vertex (graph node). Each graph node has a list of vertices it is connected to. The graph is drawn by drawing lines from each vertex to each of their connections.

private void removeDisconnectedSquare(int x, int y)
{
    GraphNode topLeft = getNodeAt(x, y);
    GraphNode topRight = getNodeAt(x + 1, y);
    GraphNode bottomLeft = getNodeAt(x, y + 1);
    GraphNode bottomRight = getNodeAt(x + 1, y + 1);

    if(topLeft != null &&
       topRight != null &&
       bottomLeft != null &&
       bottomRight != null &&
       !hasNodeToLeft(topLeft) && hasNodeToRight(topLeft) && 
       !hasNodeAbove(topLeft) && hasNodeBelow(topLeft) &&
       hasNodeToLeft(topRight) && !hasNodeToRight(topRight) && 
       !hasNodeAbove(topRight) && hasNodeBelow(topRight) &&
       !hasNodeToLeft(bottomLeft) && hasNodeToRight(bottomLeft) && 
       hasNodeAbove(bottomLeft) && !hasNodeBelow(bottomLeft) &&
       hasNodeToLeft(bottomRight) && !hasNodeToRight(bottomRight) && 
       hasNodeAbove(bottomRight) && !hasNodeBelow(bottomRight))
    {
        removeVertex(x, y);
        removeVertex(x + 1, y);
        removeVertex(x,  y + 1);
        removeVertex(x + 1, y + 1);
    }
}

Is there an algorithm or way I could detect if a path of verticies is not part of the big connected path of verticies? Sometimes this produces a small path.

Thanks

  • 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-12T10:47:53+00:00Added an answer on June 12, 2026 at 10:47 am

    I would recommend finding a good graph library. Then, represent each square as a node, and have an edge between squares if a direct path is open between them. Finally use a ‘connected nodes’ algorithm (provided by the graph library) starting from your ‘entrance node’. Finally, you can loop over all nodes that aren’t marked by the connectivity algorithm and deal with them appropriately.

    For example, if you were in C++, you could use the Boost Graph Library Connected Components algorithm. Other good graph libraries should have similar support.

    You could also roll-your-own version of such an algorithm; e.g., push unmarked neighbor nodes on a stack, mark the visited node, then pop a node off the stack until done. However, having a good graph library will be useful for other problems you’re likely to encounter in this sort of project, and IMO is preferable to rolling your own.

    It might also be worth noting that you could potentially change your maze generation algorithm to always generate a connected graph, thus preventing the need to clean up disconnected components after the fact.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is not really a problem I have, but more a question about good
This is not really a question because I just solved the problem, but I
I have a model that looks like this (well not really but it has
Well, this is not really a problem, but something really interests me. Normally we
This is not really a functional problem I'm having but more a strategic question.
I admit, this is not really a problem, but more an annoying thing: basically
This is not really a problem because I solved it. But, I wanted to
This is not really a question about addressing a specific problem but more a
I think this is not really possible but worth asking anyway. Say I have
This is not really a problem but more of a question. My question is

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.