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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:05:22+00:00 2026-06-10T07:05:22+00:00

I am creating a little game where you need to move troops on a

  • 0

I am creating a little game where you need to move troops on a map. To detect if a movement can be done I must verify if there is a way between 2 squares.
So, recursively I start from one square and take the four squares (above, below, left and right) and following conditions I repeat the test recursively since I get only dead-ends or the destination square. All the squares must be under the control of the player.

There is my recursive code implement in my class Case :

public boolean isContiguJoueur(Case case_origine, Case case_destination, Case[] cases)  {
 boolean haut_true=false, droite_true=false, bas_true=false, gauche_true=false;
 // Above
 if(this.haut!=null)    {
  if(haut.joueur==this.joueur && this.haut!=case_origine)   {
   if(this.haut==case_destination)  {
    return true;
   }
   haut_true=haut.isContiguJoueur(this,case_destination, cases);
  }
 }
 // ...
 // Same code than Above, only variables names change
 // ...
 return haut_true||droite_true||bas_true||gauche_true;
}
  • The class name for a square : Case
  • The map data : Case[] cases
  • The player id : joueur
  • The case above : haut

That code work very well on little map (~ 50 to 100 squares). But i got this on bigger ones :

08-25 11:26:31.912: E/AndroidRuntime(5497): FATAL EXCEPTION: main
08-25 11:26:31.912: E/AndroidRuntime(5497): java.lang.StackOverflowError
08-25 11:26:31.912: E/AndroidRuntime(5497):     at mypackage.isContiguJoueur(Case.java:xxx)
... x 100

Sorry for my bad english and thanks for future help ! 🙂

Edit : I forgot. To avoid mass useless recursive tests I already did this :

if(this.droite!=null && !haut_true) {
// ...
if(this.bas!=null && !haut_true && !droite_true)    {
// ...
if(this.gauche!=null && !haut_true && !droite_true && !bas_true)    {
// ...
  • 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-10T07:05:24+00:00Added an answer on June 10, 2026 at 7:05 am

    Your problem is that your paths are exponential with the number of squares on the board. The stack overflow error implies you are recursing too many times: each recursion takes up stack space, and you are running out of it (Chaque recursion utilise l’espace sur le pile, et il y’en a trop, alors il n y a plus d’espace – et c’est une dépassement de pile).

    You could do this iteratively, (sans recursion) and not run into this problem. But bear in mind the number of possible paths still remains very large, and this can be CPU consuming.

    Hope This Helps,

    TG

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

Sidebar

Related Questions

I'm creating a little tic tac toe game and I generate the computer's move
I'm creating a map editor for a little game project that I'm doing. Considering
I am creating a little game and looking for a good way to sort
I am creating a little game as a private project. Users can die and
I'm creating this cool HTML Jeopardy game and I need a little coding help.
I need a little help creating a catch-all error handling page in my ICEfaces
I'm creating a little puzzle game just as a hobby project but the project
I am creating a little flash game for the facebook platform, but I am
I'm creating a little game using Three.js and everything is going well apart from
I am creating a little game client that will end up connecting to a

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.