Sep 14, 2007

[Other] C and Sagan

I have never thought too high about programming in C, however I often find myself blaming Mediocre for being slow due to being programmed in Java.

Anyone programming in C will tell you that it is lightyears faster than Java. And anyone programming in Java will tell you that the difference is negligible.

I tend to end up somewhere in the middle. Not being a superstar programmer I think that whatever speed advantage I might potentially get with C will be lost in sloppy coding.

However, just to see if there really is a difference I have started sketching on a C chess engine I call Sagan.

I am mainly doing this to not have any excuses for the engine playing badly. :) I hate the "well it's not strong, but you can only expect that from Java".

This is just in the planning stages for now. Studying at 150% speed does not give much room for anything but planning. :)


Sparky said...

Ironic... you're contemplating writing a C engine and I'm contemplating writing a Java engine. Why Java - because its a more readable language... go figure :-)

Good luck - would be interesting to see how this turns out. Keep it up

Jonatan Pettersson said...

Yeah, Java is much easier to keep understandable, and still I manage to make a mess out of it.

I wonder what I'll make with C. :)

Looking forward to seeing you Java engine.

Yves said...

for me it is strange this comparaison.
I think it is more link with some algorithm and development issue or solution found.
Look at Kingsout chess engine in java. It has a speed near or equal to shredder.

Jonatan Pettersson said...

Well it depends what you mean with speed. A high nps is one way to look at it but that is not the whole truth.

If I removed the evaluation in Mediocre it would probably almost tenfold the nodes searched per second. However that wouldn't mean Mediocre got faster, and it would play a lot worse obviously.

King's Out has a high nps but a near non-existant evaluation and as I understand it that was the intention of Berndt, "fast but dumb".

Java is largely made for reliability, sometimes at the cost of alternative faster implementations that you could do in C.

Yves said...

yes you are right, i was talekd about the kn/s than is very near shredder.
but i think if he add more evaluation function and some tips, he will have a very strong engine.

Rajiv Bakulesh Shah said...

If I recall correctly, your engine doesn't use BitBoards, so it doesn't depend on low-level bit-twiddling hacks. Write it in whatever language you enjoy the most!

On the other hand, my engine uses BitBoards, so it depends on low-level bit-twiddling hacks, so it must be fairly close to the bare-metal.

It's interesting that we both considered changing languages around the same time. Read more about my thought process here:

Fritz said...

When I once wrote a Reversi engine to learn Java (all methods declared static), porting it to Pascal (around 30 lines of code, so nearly "verbal" translation was possible) increased the engine speed by a factor of 5; this might also apply to a chess engine that is carefully designed for speed. In my engine, however, a lot of time is spent on hash table lookups for move orderings, so the speed of that engine is tightly linked to the speed of memory access. Have you profiled Mediocre to see where it spends its time?

Jonatan Pettersson said...

I have done some profiling but I should probably do a thorough profile soon again. Last time I got the impression the tiny methods took a lot of time (like checking for ability to reach a square which is just one line of code but still in a method).

I tried to manually inline these methods just to find out that it didn't help speed at all. That was a bunch of hours wasted. :)

But as I said I should probably try thorough profiling again.

Generic Viagra Online said...

I don’t know If I said it already but …I’m so glad I found this site…Keep up the good work I read a lot of blogs on a daily basis and for the most part, people lack substance but, I just wanted to make a quick comment to say great blog. Thanks!