Programming language features for computer chess

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

Xann
Posts: 127
Joined: Sat Jan 22, 2011 7:14 pm
Location: Lille, France

Programming language features for computer chess

Post by Xann »

One of the reasons I stopped CC is that I was unhappy with the existing languages.

What I want is so precise that it simply does not exist, though Modula 3 comes extremely close.
Yes I tried Ada but it's way too rigid and I disagree with some design choices.

I gave some thought about what features would be useful for computer chess.

Two things for me.

1) iterators (with "yield" statement)

Extremely useful for both mailbox (maybe outdated now) and bitboard.
Incremental move gen etc ...

Sure, we can do it with classes, but classes are verbose.
Also when I tried with GCC Linux, it became slower and slower.
Classes with a single field were not optimised properly.
Since then, I was told classes were fine.
Maybe I tried in a wrong way, or it didn't work with GCC then (2003 version I think).

I think if I had iterators in 2005, Fruit would be 4x smaller, and maybe more.

2) fixed-point arithmetic

I could live without that one.
But think about it: eval score, fractional plies, probabilities?
You can change the granularity with a single line of code (type declaration).

What do you think of this?
Any more ideas?

Fabien.
User avatar
smrf
Posts: 484
Joined: Mon Mar 13, 2006 11:08 am
Location: Klein-Gerau, Germany

Re: Programming language features for computer chess

Post by smrf »

For chess programming I have switched back from C++ to C. And still I base my data structures partially on two post boxes - not at all using bit boards, now having a pure monochrome approach, thus simplifying testing and maintaining of chess routines.
Gerd Isenberg
Posts: 2250
Joined: Wed Mar 08, 2006 8:47 pm
Location: Hattingen, Germany

Re: Programming language features for computer chess

Post by Gerd Isenberg »

Hello Fabien,

Welcome back to computer chess!

I am not a language expert, but I found C++ template classes quite efficient (I wrap all the SSE2 intrinsic functions and datatypes I use with quad-bitboards). Instead of fixed point why not floating point for that stuff, has become quite efficient with all those SSEx extensions on x86 or x86-64 and other architectures?

Cheers,
Gerd
Xann
Posts: 127
Joined: Sat Jan 22, 2011 7:14 pm
Location: Lille, France

Re: Programming language features for computer chess

Post by Xann »

Gerd Isenberg wrote:I am not a language expert, but I found C++ template classes quite efficient (I wrap all the SSE2 intrinsic functions and datatypes I use with quad-bitboards). Instead of fixed point why not floating point for that stuff, has become quite efficient with all those SSEx extensions on x86 or x86-64 and other architectures?
Hi Gerd!

Point taken.

You haven't given up on low-level stuff, have you :)
I don't see why you should !

Fabien.
Gerd Isenberg
Posts: 2250
Joined: Wed Mar 08, 2006 8:47 pm
Location: Hattingen, Germany

Re: Programming language features for computer chess

Post by Gerd Isenberg »

Xann wrote: You haven't given up on low-level stuff, have you :)
At least I use C++ classes with wrapped intrinsics now, and no longer (inline) Assembly with mnemonics like punpckhqdq ;-)
Ron Murawski
Posts: 397
Joined: Sun Oct 29, 2006 4:38 am
Location: Schenectady, NY

Re: Programming language features for computer chess

Post by Ron Murawski »

Xann wrote:One of the reasons I stopped CC is that I was unhappy with the existing languages.

What I want is so precise that it simply does not exist, though Modula 3 comes extremely close.
Yes I tried Ada but it's way too rigid and I disagree with some design choices.

I gave some thought about what features would be useful for computer chess.

Two things for me.

1) iterators (with "yield" statement)

Extremely useful for both mailbox (maybe outdated now) and bitboard.
Incremental move gen etc ...

Sure, we can do it with classes, but classes are verbose.
Also when I tried with GCC Linux, it became slower and slower.
Classes with a single field were not optimised properly.
Since then, I was told classes were fine.
Maybe I tried in a wrong way, or it didn't work with GCC then (2003 version I think).

I think if I had iterators in 2005, Fruit would be 4x smaller, and maybe more.

2) fixed-point arithmetic

I could live without that one.
But think about it: eval score, fractional plies, probabilities?
You can change the granularity with a single line of code (type declaration).

What do you think of this?
Any more ideas?

Fabien.
Hi Fabien (and welcome back!),

I have researched a number of languages for the purpose of chess programming.
I tried to keep an eye on what can be expected in the future. It seems obvious
that as time passes cpus will contain more and more cores inside. Today we
have 4 to 16 cores: in the future it will become thousands.

What we need are languages that automatically scale their performance as the
number of cores increases. These scalable languages have a name. They are
called functional languages. But "pure" functional languages are a pain to
work in (for me, anyway). There are many new hybrid languages that support a
procedural/imperative approach as well as a functional one.

One of these hybrid languages is called Scala, which runs on the JVM. Scala
supports "iterators with 'yield' statement" (also known as comprehensions or
generators) as well as much more.

Scala is a compiled, statically typed language, so its execution speed is
sufficient. The compiler is very good at optimizing integer operations and
routimely out-performs equivalent Java code. Scala has something called type
inference: "Scala is able to infer types by usage. This makes most static type
declarations optional. Static types need not be explicitly declared unless a
compiler error indicates the need. In practice, some static type declarations
are included for the sake of code clarity. Lack of explicit type declarations
give Scala the appearance of a dynamically typed language."

Scala is quite powerful and, if used correctly (using Actors), will
automatically scale its performance along with cpu core increases. A Scala
program running on a single core cpu will run at about 50% to 70% the speed of
an equivalent C/C++ program (which is a reflection of the Java virtual machine
speed), but on a dual-core, the same Scala program runs about twice as fast.

I was not impressed with the Scala development tools. The language tools still
need a couple more years to mature.

http://en.wikipedia.org/wiki/Scala_%28p ... anguage%29

I too would be interested in any other rich language that chess programmers
have found.

Ron
User avatar
JuLieN
Posts: 2949
Joined: Mon May 05, 2008 12:16 pm
Location: Bordeaux (France)
Full name: Julien Marcel

Re: Programming language features for computer chess

Post by JuLieN »

@Ron

Ron, there's something else : Apple designed a new extension to the c/c++ and objective-C language called OpenCL and released it to the public domain. There is now a public consortium (like the one for OpenGL or the one for JPEG) that will continue its development.

Its purpose is to automatize the use of multicores (both in CPUs and GPUs) by just including the headers in your code (I've never tried it, so maybe it would need a better explanation).

For the moment, and as far as I know, it's only included in Mac OS X Snow Leopard but Intel, NVidia and AMD jumped into the project and will support it under Windows as well.

It could be interesting to have a look at it too. On Macs, testers got blazing fast results by toy-testings things like pi-decimals generation and so on. Maybe we'll soon have CPU+GPU couples that will allow each of us to run private DeepBlue at home (just much stronger because of smarter software).

More details : http://en.wikipedia.org/wiki/OpenCL
(take a look : that's the future, just like OpenGL was in 1988 :) ).
"The only good bug is a dead bug." (Don Dailey)
[Blog: http://tinyurl.com/predateur ] [Facebook: http://tinyurl.com/fbpredateur ] [MacEngines: http://tinyurl.com/macengines ]
User avatar
phhnguyen
Posts: 1434
Joined: Wed Apr 21, 2010 4:58 am
Location: Australia
Full name: Nguyen Hong Pham

Re: Programming language features for computer chess

Post by phhnguyen »

smrf wrote:For chess programming I have switched back from C++ to C. And still I base my data structures partially on two post boxes - not at all using bit boards, now having a pure monochrome approach, thus simplifying testing and maintaining of chess routines.
Very interesting, I usually check reasons why I should use C++ but not C for my program.

I knew the long time myth about C++ object pointers may make programs 10% slower than similar C ones in general. But if that is all price I have been still ready to pay for all advantages of C++ over C. I hope with recent C++ compilers (such as Visual Studio 20xx) the speed gap now becomes much smaller.

Any reason and update for the "battle" between C and C++? Thanks.
vladan.vuckovic

Re: Programming language features for computer chess

Post by vladan.vuckovic »

Dear Fabien,

I used Pascal (Delphi 7) for recursive null-move Alpha-Beta searcher and x86 assembly for quiescence/evaluator in my Axon/Achilles chess engines.

This hybrid architecture was very useful due to fact that most of the search intelligence could easily be controlled in higher programming languages (Pascal) and that 50-80% search time is consumed in quiescence/evaluator (written in assembly, manually coded).

Also, I have invented the special data structure named CCR....it is published in ICGA Journal paper. It is very efficient and perfectly suitable both for 32-bit or 64-bit machines with much easier handling in pure machine code programming compared to bitboards.


(Vladan Vučković (2008). The Compact Chessboard Representation. ICGA Journal Vol. 31 No. 3, pp. 157-164)


Best regards,

dr Vladan Vuckovic
Ron Murawski
Posts: 397
Joined: Sun Oct 29, 2006 4:38 am
Location: Schenectady, NY

Re: Programming language features for computer chess

Post by Ron Murawski »

JuLieN wrote:@Ron

Ron, there's something else : Apple designed a new extension to the c/c++ and objective-C language called OpenCL and released it to the public domain. There is now a public consortium (like the one for OpenGL or the one for JPEG) that will continue its development.

Its purpose is to automatize the use of multicores (both in CPUs and GPUs) by just including the headers in your code (I've never tried it, so maybe it would need a better explanation).

For the moment, and as far as I know, it's only included in Mac OS X Snow Leopard but Intel, NVidia and AMD jumped into the project and will support it under Windows as well.

It could be interesting to have a look at it too. On Macs, testers got blazing fast results by toy-testings things like pi-decimals generation and so on. Maybe we'll soon have CPU+GPU couples that will allow each of us to run private DeepBlue at home (just much stronger because of smarter software).

More details : http://en.wikipedia.org/wiki/OpenCL
(take a look : that's the future, just like OpenGL was in 1988 :) ).
Hi Marcel,

I looked through some of the OpenCL download packages and I find this
definition:
"a set of advanced hardware and software technologies that enable graphics
processing cores (GPU), working in concert with the system’s x86 cores (CPU),
to accelerate many applications beyond just graphics."

So I think OpenCL is trying to leverage available GPU power, which is not quite
the same as scaling program performance according to cpu cores available.

Nevertheless this is interesting technology! Thanks!

Ron