Programming chess engine

Code, algorithms, languages, construction...
spacerocket
Posts: 18
Joined: Sat Mar 22, 2014 1:15 pm

Re: Programming chess engine

Post by spacerocket » Mon Apr 14, 2014 11:52 am

Yep!

I have experimented little with python http://www.pygame.org/news.html but don`t know xojo.

What comes to Bjarne Stroustrup`s book I downloaded the 3rd edition and huh, this contains over 900 pages! The 3rd edition would be a good choice for a beginner?

I also found this: http://www.cprogramming.com/c++book/?inl=sb How about this seems shorter.

velmarin
Posts: 39
Joined: Thu Mar 17, 2011 11:31 am
Real Name: Jose Mº Velasco

Re: Programming chess engine

Post by velmarin » Mon Apr 14, 2014 12:52 pm

You can follow this course, since installing the IDE to finish the engine.

After experimenting with it, it is a public domain project, very interesting.
https://www.youtube.com/watch?v=DWWQEmy ... bag04AMPJq

Download Vice 1.0
http://www.bluefever.net/Downloads/Vice10.zip

Readme:

Code: Select all

Vice (Video Instructional Chess Engine)

Vice came to be as part of a YouTube video tutorial series showing how to create a simple chess engine in C. Vice isn't meant to be anything other than a resource for people starting out with computer chess, and hopefully provides some help and guidance. I certainly don't claim to anything more than a beginner at this myself. The program is not optimised, is definitely not written to a high standard - it is a hobby programmer's attempt to give something back to a great and vibrant community.

Vice is Winboard, UCI protocol compatable. It also has a console mode, but a GUI is much better. It plays under Shredder, Winboard, Chessbase, Arena without (so far) problems.

You are welcome to use the code as you like to help with your projects!

The YouTube playlist is here, 87 videos in total.


Download Link Vice 1.0


Vice 1.0, 30.07.2013

The First Release of Vice, Vice 1.0 (Download)


Vice has the following features:

120 square array board representation
Bitboards for pawns
Alpha-Beta search, and quiescence search
Basic MVV/LVA Move ordering + Killers + History Table
Hash Table with always replace scheme
Very, and I mean very, basic evaluation

velmarin
Posts: 39
Joined: Thu Mar 17, 2011 11:31 am
Real Name: Jose Mº Velasco

Re: Programming chess engine

Post by velmarin » Mon Apr 14, 2014 3:02 pm

Octopus wrote:There are some thoughts to be said: to start chess engine programming it is first important to understand programming. If you don't have relevant experiences in that, it might be helpful not to start witch language C or C++. So put the idea aside, to write a top performing chess engine at your first approach. You should primarily start gathering experiences in (game) programming using a simpler language. I recommend to try Xojo, which is a nice multi OS BASIC related development environment, which is free as long you use it for yourself, sufficient for learning purposes. Additionally the IDE supports object oriented language extensions, enabling multiple experiences also into that direction.

See at: http://www.xojo.com/index.php where you also could find a lot of free documentation and demos.

xojo, license 250 €s
:oops: :evil: :(

spacerocket
Posts: 18
Joined: Sat Mar 22, 2014 1:15 pm

Re: Programming chess engine

Post by spacerocket » Mon Apr 14, 2014 5:03 pm

Yep,

but my basic goal is now to learn to understand C++ not C.

Thanks anyway for your answer. I want first to write a tic-tac-toe in C++ myself then move to chess engines. I can then move to the engine source code you recommended.

But how about my original question, which of the books would be better? Allains book is about 10 times shorter than Bjarnes does that affect something?

Octopus

Re: Programming chess engine

Post by Octopus » Mon Apr 14, 2014 5:58 pm

velmarin wrote:xojo, license 250 €
During the last days there has been a big bundle of software for $19.99 via MacHeist.com
consisting of: BoinxTV, MacJournal, Toon Boom Studio, AccountEdge Pro, iSale, Picturesque,
Starry Night Pro and Xojo Desktop.

It has been a great deal for me. (And personal use always is completely free.)

lucasart
Posts: 201
Joined: Mon Dec 17, 2012 1:09 pm
Contact:

Re: Programming chess engine

Post by lucasart » Tue Apr 15, 2014 12:31 pm

spacerocket wrote: What comes to Bjarne Stroustrup`s book I downloaded the 3rd edition and huh, this contains over 900 pages! The 3rd edition would be a good choice for a beginner?
C++ is a monstruously big and complicated language. Only a monstruous book can cover it (and never completely). The 4th edition is 1400 pages, and excercices are not included. They are on Bjarns website "to save a few trees" in Bjrarn's own words.

The mistake is to think that a beginner can learn C++. It's like trying to teach general relativity to an 8 year old. That's not how you start. You start with easy and cool stuff like Python.
"Talk is cheap. Show me the code." -- Linus Torvalds.

User923005
Posts: 616
Joined: Thu May 19, 2011 1:35 am

Re: Programming chess engine

Post by User923005 » Wed Apr 16, 2014 9:03 am

C++ can be used incrementally. For instance, you don't have to start with function templates, polymorphism and the like. You can just write C code and gradually toss in a few objects. Eventually, you will get the hang of it. And compared to Java, it is a pipsqueak of a language.

Now, I don't really think that C++ is superior to C for writing a chess engine. And I also think that the language chosen should have some means for getting fairly close to the hardware instructions. I suspect that an expert Fortran programmer could write an engine rivaling the best C and C++ engines.

lucasart
Posts: 201
Joined: Mon Dec 17, 2012 1:09 pm
Contact:

Re: Programming chess engine

Post by lucasart » Wed Apr 16, 2014 11:34 am

User923005 wrote:C++ can be used incrementally. For instance, you don't have to start with function templates, polymorphism and the like. You can just write C code and gradually toss in a few objects. Eventually, you will get the hang of it. And compared to Java, it is a pipsqueak of a language.

Now, I don't really think that C++ is superior to C for writing a chess engine. And I also think that the language chosen should have some means for getting fairly close to the hardware instructions. I suspect that an expert Fortran programmer could write an engine rivaling the best C and C++ engines.
C is terse, but very subtle. I don't think it's easy to learn C as a first programming language. I learnt C after having done some Basic, Assembly and Pascal, as well as some algorithmics in CAML, so it was relatively easy to understand for me, because I had the basics.

But for someone with zero knowledge of programming, who probably does not even understand the most basic algorithmic concepts such as loops, recursion, etc. C would present a rather steep learning curve. That's why I mentionned Python. At this point we're not talking about writing a chess engine, I think he's still at the stage of "hello world" programs now.

I have written chess engines both in C and in C++. For this task C++ is neither necessary nor useful. I think C++ shines in GUI toolkits like Qt for example. Sure the same can be done in C, but it's more laborious. In the end the most important and only useful thing in C++ are constructor/destructor and RAII, as well as templates. All the rest can be done in C. Emulating templates with the C preprocessor is possible, but ugly and not as flexible (though better than nothing). As for ctor/dtor and RAII, it's where C fails and C++ really brings something to the table. That being said, in a well conceived chess engine, this is not really necessary.
"Talk is cheap. Show me the code." -- Linus Torvalds.

rtr
Posts: 8
Joined: Thu Apr 03, 2014 2:39 am

Re: Programming chess engine

Post by rtr » Thu Apr 24, 2014 9:42 pm

lucasart wrote:I have written chess engines both in C and in C++. For this task C++ is neither necessary nor useful. I think C++ shines in GUI toolkits like Qt for example. Sure the same can be done in C, but it's more laborious. In the end the most important and only useful thing in C++ are constructor/destructor and RAII, as well as templates. All the rest can be done in C. Emulating templates with the C preprocessor is possible, but ugly and not as flexible (though better than nothing). As for ctor/dtor and RAII, it's where C fails and C++ really brings something to the table. That being said, in a well conceived chess engine, this is not really necessary.
There is a lot to be said for creating types that protect invariants, and doing so in an automated way. In C you can get close, wrapping all types in functions and adding in appropriate asserts, but you still rely on the programmer not touching the data directly. In C++ the compiler can enforce this. Any time the computer can handle checking something instead of relying on the irrational and often fallible human brain, I'm all for it. The same is true for type checking, const, and so on. When everything is an int, you can silently pass a piece when you wanted a square. When a piece is a different type than a square, you can't. Being const-correct is also great, usually saves a few bugs in any project.

spacerocket
Posts: 18
Joined: Sat Mar 22, 2014 1:15 pm

Re: Programming chess engine

Post by spacerocket » Mon Apr 28, 2014 5:44 pm


Post Reply