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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:17:46+00:00 2026-05-23T12:17:46+00:00

I am relatively new to javascript. I am trying to code my web version

  • 0

I am relatively new to javascript. I am trying to code my web version of minesweeper. Here is a recursive function I needed, and it looks to work fine until browser gives this “too much recursion” error. The problem is that i need that recursion. Is there any other way to code minesweeper? Here is the demo: http://altynachar.com/minesweeper/

I can post my php code if needed.

function recursive(id){
                var id = id;
                //Determine what kind of cell this is: Clean, Bomb or Adjasent to bomb
                if($("#"+id).hasClass("adj")== true)
                    var under = "adj";
                if($("#"+id).hasClass("bomb")==true)
                    var under = "bomb";
                if($("#"+id).hasClass("clean")==true)
                    var under = "clean";

                //open up the cell          
                $("#"+id).hide();
                $("#under_"+id).show(); 

                //if it is bomb, open up whole grid and button for restart
                if(under == 'bomb')
                {       
                    $(".cover").hide();
                    $(".under").show();
                    $("body").append("<br /><input type='button' value='restart' onClick='javascript:window.location.reload();' />");
                } else {        

                    //if it is clean cell       
                    if(under == "clean")
                    {
                        //get all the adjasent cell ids
                        var split = id.split('-');
                        var row = parseInt(split[0]);
                        var col = parseInt(split[1]);
                        var adjasent = new Array();
                        adjasent[0] = (row-1)+"-"+ (col+1);
                        adjasent[1] =  row +"-"+(col+1);
                        adjasent[2] = (row+1)+"-"+(col+1);
                        adjasent[3] = (row+1)+"-"+col;
                        adjasent[4] = (row+1)+"-"+(col-1);
                        adjasent[5] =  row+"-"+(col-1);
                        adjasent[6] = (row -1)+"-"+(col-1);
                        adjasent[7] = (row -1)+"-"+col;

                        //loop through adjasent cells
                        for(var i=0; i<adjasent.length; i++)
                        {
                            var split2 = adjasent[i].split('-');
                            var row2 = parseInt(split2[0]);
                            var col2 = parseInt(split2[1]);

                            //check if cell is existent
                            if(row2 > 0 && row2 < 17)
                            {
                                if(col2 > 0 && col2 < 17)
                                {
                                    //perform recursion
                                    var adj = adjasent[i];
                                    recursive(adj);
                                } 
                            }                               
                        }
                    }
                } 
            }           
  • 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-23T12:17:47+00:00Added an answer on May 23, 2026 at 12:17 pm

    My guess is that if you have 2 clean cells next to each other your code will get in an infinite recursion.

    Each iteration recurses to all adjacent cells. So say cell A and B are next to each other, and both are clean. A will call recurse to B, which will then recurse to A, which recurses to B, and so on.

    You can either try to clean up your recursion so that it doesn’t look at cells that were already seen, or remove the recursion. You can accomplish the same thing by adding any unseen clean cells to a queue, and just keep popping off the end of the queue until it’s empty. That might make it easier to avoid checking the same cell twice too.


    Also, please don’t build up strings just to split them into separate data later. Instead of:

    adjasent[0] = (row-1)+"-"+ (col+1);
    /* ... */
    var split2 = adjasent[i].split('-');
    var row2 = parseInt(split2[0]);
    var col2 = parseInt(split2[1]);
    

    just do

    adjacent[0] = { row: row-1, col: col+1 };
    /* ... */
    var row2 = adjacent[0].row
    var col2 = adjacent[0].col
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm relatively new to jquery and javascript and am trying to pass a unique
I'm relatively new to Javascript, and I'd like to run the piece of code
I'm relatively new to Javascript and was wondering if there's a quick way to
Relatively new to rails and trying to model a very simple family tree with
I am relatively new to web services and am wondering what the standard best
I'm relatively new to web application programming so I hope this question isn't too
I am very new to javascript and ajax/jquery and have been working on trying
I am relatively new to JavaScript and keep seeing .extend and .prototype in third
I am relatively new to javascript so please be patient if what i am
I'm relatively hopeless with JavaScript writing, and I'm trying to resize the default tumblr

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.