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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:11:14+00:00 2026-06-01T13:11:14+00:00

I am working on a homework project in which we need to generate a

  • 0

I am working on a homework project in which we need to generate a state tree for the game of Golf Solitaire. To do this I decided to create a Move class which represents a move from one stack of cards to another – simply put, it holds a reference to the two stacks involved in a single move. Each node in my tree knows what it’s move is.

The problem I am currently having is that my trees are much too large – like OutOfMemoryError too large. Edit – I should note that when I make a tree for a very small game I do not get an error, but my tree is still much larger than it should be!

For those unfamiliar with the game: Golf Solitaire Rules. Note – We did not need to implement the restriction on playing a Queen after a King.

public void makeTree()
{
  _root = makeNode( null, null, 0 );
}

private Node makeNode( Node parent, Move m, int depth )
{
  Node node = new Node( parent, m, depth );
  ArrayList<Move> moves = findAllMoves();
  if( moves.size() == 0 )
    node.setScore( getScore() );
  else {
    for( Move mv : moves ) {
      mv.makeMove();
      Node child = makeNode( node, mv, depth++ );
      node.addChild( child );
      mv.undoMove();
    }
  }
  return node;
}

private ArrayList<Move> findAllMoves()
{
  ArrayList<Move> moves = new ArrayList<Move>();

  for( int i = 0; i < numPlayPiles; i++ ) {
    if( _play[i].size() != 0 ) {
       if( Math.abs( _play[i].top().getRank().ordinal() - 
          discard.getRank().ordinal() ) == 1 ) {
          moves.add( new Move( _play[i], _discard ) );
       }
    }
  }

  if( _draw.size() != 0 )
    moves.add( new Move( _draw, _discard ) );

  return moves;
}

_play[i] is simply referencing a pile of cards in the game.

I realize this is a bit much of code to be posting in a question, but my question is simply about my logic. I have a suspicion that my error is in how I am returning makeNode yet I am totally stuck here. Could anybody confirm my suspicion and/or possibly give me some guidance?

  • 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-01T13:11:15+00:00Added an answer on June 1, 2026 at 1:11 pm

    For anybody who is curious, my issue was one of not reading the assignment properly. Specifically, my findAllMoves method was the issue. A node should have either a move from the draw pile or all possible moves from play piles, but not both. My code above allows each child, even at the same depth, to each create a Move from the draw pile to discard pile – resulting in a huge amount of duplicate nodes.

    It also never checks the end-game conditions. As a result, each leaf node was either a losing score, or 0 (the method would recurse until the draw pile was empty even if the player already won).

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

Sidebar

Related Questions

I'm working on a homework assignment (a project), for which one criterion is that
I'm working on a homework project that requires me to create an object from
Working on a homework assignment and am stuck with this task: Create a loop
I'm working on my first homework project in a web programming class, which is
I'm working on this homework that's kind of confusing me... I am provided with
I'm working on a homework assignment in which I'm required to use char arrays
I'm working on some homework for an intro to C class, in which we
I am working on this homework assignment and I am stuck on what I
I'm working on some homework for an intro to C class, in which we
I am working on a homework project for a Networking class where we have

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.