Mar 26, 2007

[Programming] Faster SEE

For some reason I had the following lines inside the see() method. Meaning they were initialized every time the SEE was called:
int[] piece_values = {0,1,3,3,5,9,99,0,99,9,5,3,3,1};
int[] w_attackers = new int[16];
int[] b_attackers = new int[16];
int[] scores = new int[32];
Since we actually do not have to clear any of these at the start of every SEE-check (we keep track of the index and never use what existed there before) I simply moved them out of the method, making them static variables that are not cleared at each call.

This speeded up the SEE-check with about 30-40%. Imagine that. :)

Now SEE is not called that insanely often so in total this small change probably only accounts for a 5-10% speedup overall. But it is a reminder that you have to be careful with your initializations in Java. :)


Jaco van Niekerk said...

The LMR and SEE additions to your program should give the program a great boost. I think your program is the strongest Java engine out there? Have you looked?

Anonymous said...

I admire your productivity!! Do you have a day job??

Jonatan Pettersson said...

Hmm, I know of 5-6 other Java engines and among those King's Out is probably the best. Mediocre is currently quite equal to King's out.

I should take the time to gather all the engines and get a little Java tournament going, might be interesting.

Thanks for the idea. :)

I am a computer science student so there is plenty of spare time to use up. :)

Jaco van Niekerk said...

Well, enjoy it while you can. Once you code for a living, this will change, I can promise you. I get up at 5am to work on Vicki, and I have a bit of time in the evenings...(but then you're so tired that you can not be really very productive) Damn, I envy you! :-)

Anonymous said...


Thank's for writing this very interessting blog! It's a joy to follow!

Your latest version is playing really solid chess!

One thing I have noticed is that Mediocre manages its time poorly when playing "x moves in y minutes" games. It usually reaches the time control with 30-40 % of the time remaining.
This behaviour probably costs a few ELO-points in tournaments wich use this format.

Jonatan Pettersson said...

Thanks for the kind words. :)

While writing version 0.3 I made an attempt at a new time management algorithm and failed miserably, not sure what happened. I have been planning to make a new attempt now that version 0.3 is out.

But what you mention is very true. Mediocre only calculates the given time after each move and uses a certain percent of it. However, it would be very easy to adjust it so "x moves in y minutes"-controls would be handled more effectively.

Anonymous said...


first of all > great stuff !!
Really helpful for starting in chess programming.
Would be nice for late joiners
to have all the archived articles
in a more downloadable format, i.e. as one bundle with all *.html or in pdf format

Keep the fire burning :-)

bye4now, gilbert

Jonatan Pettersson said...

Yes I know, as the blog has grown it has become hard even for me to find some of the older stuff.

I'm planning to put together a website with a collection of the guides and some sort of better overview.

Hopefully I'll get around to do it quite soon.