aspose file tools
The moose likes Game Development and the fly likes Optimizing Code for Chess Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Game Development
Reply Bookmark "Optimizing Code for Chess" Watch "Optimizing Code for Chess" New topic
Author

Optimizing Code for Chess

Ashish Schottky
Ranch Hand

Joined: Dec 29, 2009
Posts: 93
Hi again,
I have coded a chess game and it has the following part:

The dynamic memory allocation of the array, makes the program run slowly.
So I tried

but then it gives me a bug as there are no other moves which are tried. It seems that no other moves are loaded into the array execept for the first one.
Is there some problem due to memory allocation or the way in which I am accessing it?
here is the code from filter moves()


How can I allocate all the required memory statically?(There is tremendous slow-down due to dynamic memory allocation).
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 9955
    
    6

You know that "Move[] total_final_moves=new Move[200]" only allocates space for the pointers to the moves. You don't have the 200 Move objects, just pointers/references to them.

You have effectively created an egg carton that can hold 200 eggs, but it is empty.


Never ascribe to malice that which can be adequately explained by stupidity.
Ashish Schottky
Ranch Hand

Joined: Dec 29, 2009
Posts: 93
@Fred: Thanks for replying:
But doesnt this line fill up the array with objects of type Move.
Here ge.filterMoves() return an array of type Move.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Optimizing Code for Chess
 
Similar Threads
Jumping Problem
Having problems in unMakeMove() for chess
determine least number of keypress
Avoiding dynamic memory allocation in AI board games.
Knight's tour