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

  • Home
  • SEARCH
  • 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 6742861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:53:35+00:00 2026-05-26T11:53:35+00:00

I am making a rogue-like game and I am using a random walk within

  • 0

I am making a rogue-like game and I am using a random walk within a grid to form a ‘cave’ system. However, the random walk I have came up with gets stuck– in particular when the walker is near the edge of the grid and is surrounded with ‘holes.’

This isn’t the exact code I am using in my project, I cannot access my code from work. However, I re-wrote a sample of the same algorithm I am using at home.

Essentially, I took a 20×20 grid of integers and filled it with 1’s. As I walk I punch a 0 on each step I take.

void walk(int grid[][20]){
  int x = rand() % 10 + 9;
  int y = rand() % 10 + 9;

  int walk_count;

  for(walk_count = rand() % 1000 + 500; walk_count >= 0; walk_count--){
    switch(rand() % 4){
      case 0: if(grid[x][y - 1] == 1 && y - 1 >= 1){ y--; grid[x][y] = 0;} break;
      case 1: if(grid[x][y + 1] == 1 && y + 1 < 20){ y++; grid[x][y] = 0;} break;
      case 2: if(grid[x - 1][y] == 1 && x - 1 >= 1){ x--; grid[x][y] = 0;} break;
      case 3: if(grid[x + 1][y] == 1 && x + 1 < 20){ x++; grid[x][y] = 0;} break;
      default: break;
    }
  }
}
  • 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-05-26T11:53:36+00:00Added an answer on May 26, 2026 at 11:53 am

    First, explain the asymmetry in your code. In case 1, you have && y + 1 < 20. In case 3, you have && x + 1 >= 1, which I would expect to be && x + 1 < 20.

    I’m going to chalk that up as a transcription error / typo and not the source of your problem. As I understand it, your problem is that you have a random walker who paints the floor and is painting itself into a corner. This behavior is expected, isn’t it?

    The problem is that you are simply doing a random walk and expecting a behavior that is more intelligent than random. If you want to avoid painting yourself into a corner, put that into your algorithm. Assuming these random walkers want to be able to reach the player, just check that each direction, if filled, would still have a path to the player. Then randomly choose from the directions where that holds true.

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

Sidebar

Related Questions

Making game of life I need to a have a grid that is 30x20
making a thumbnail from video using the picker is straight forward. However, when I
Making a new class in VS10 gives me using System; using System.Collections.Generic; using System.Linq;
Making a game using Blender for 3D models and Unity for the game engine.
Making a ship game because I am incredibly original.. With that aside, I have
Making a simple program which will generate a multiple choice form. I have an
Making my first steps with NHibernate, I'm trying to have it creating my Tables
When making changes using SubmitChanges() , LINQ sometimes dies with a ChangeConflictException exception with
When making software, specially games, those resources like graphics and sounds are something freaky
Making a mobile friendly site, I have a single field and a submit button.

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.