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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:11:28+00:00 2026-06-11T03:11:28+00:00

For a C# AI program I use a recursive call to find the best

  • 0

For a C# AI program I use a recursive call to find the best next move (using a 30×30 Array to store the current board state). For each move I make, I want to see which of the possible moves I can make from the new board state will be best… and so on until I either reach an “end of game” position (no further moves possible in that state) or a timer stops the process and no further recursive calls are made (and the “best” known position is returned). This just to explain why I must use recursion (it is not tail recursion) and I cannot use a single (global) board state, but must search all board states possible from the current state.

(Sometimes) I get a System.StackOverflowException. Is there a way to check the available stack space before the next recursive call? Then I could just return the current state as a “best position found so far” and not make the next recursive call. I.e. when the available stack becomes too small it should also count as a base case.

The other option of course, may be to just put each recursive call in a try..catch block and handle the System.StackOverflowException by using it as a base case?

  • 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-11T03:11:29+00:00Added an answer on June 11, 2026 at 3:11 am

    If you really want to go down that path you can use EnsureSufficientExecutionstack method.

    As others pointed out, starting with .NET 2.0 you cannot catch a StackOverflowException, however, from the MSDN documentation you know the previous method has the following behavior:

    Ensures that the remaining stack space is large enough to execute the
    average .NET Framework function.

    When the stack is not large enough according to this method then it will throw an InsufficientExecutionStackException exception that you can catch.

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

Sidebar

Related Questions

I'm making a program use JNI to call some native directives. My code is:
I use a program call php easy calendar. Into that, there is a lot
I'm using Delphi 2009. My program has been compiling and running fine. I use
I often use the excellent find program in Bash to list files with certain
I want to find every application listed in the user program menu. I use
My program use UdpClient to try to receive 27 responses from 27 hosts. The
I have a flight reservation program use mssql ,For reserving flights i want to
This program I use has it's own variables to set when you run it,
I wrote a little program that use activemq embedded broker. Program run on one
I wirte a simple program that use unix sockets to download a html file

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.