Advertisement

Chess programming

Started by October 13, 2003 11:12 AM
30 comments, last by Druzzer007 21 years, 4 months ago
quote:

Just out of curiosity (I'm not that experienced with the details of templates), how fast would your ColorTraits approach perform compared to other approaches? And what does it convert to? Does it do an if statement under the hood or a table lookup or a function pointer, or what? Like I said, I'm not all that familiar with how the compiler translates these kind of templated things.



Templates are evaluated in compile time, which means that there is no overhead whatsoever. The effect is that now I can call the functions passed_pawns<White>() and passed_pawns<Black>(), they would do the right thing, they are as efficient as if they had been coded separately, but I only had to write one function.

[edited by - Alvaro on October 14, 2003 9:02:01 PM]
I know that if you do passed_pawns(), that will be the same as if you did WhitePassedPawns(), but what if you did:


Color c = GetColorToMove();
Bitboard passedPawns = passed_pawns;


I don''t see how that could be a compile time decision. If you do passed_pawns(), you still need an if statement or something to determine whether to call passed_pawns() or passed_pawns(), right?
Advertisement
quote:
Original post by Russell
I know that if you do passed_pawns<White>(), that will be the same as if you did WhitePassedPawns(), but what if you did:

Color c = GetColorToMove();Bitboard passedPawns = passed_pawns; 


I don''t see how that could be a compile time decision. If you do passed_pawns<White>(), you still need an if statement or something to determine whether to call passed_pawns<White>() or passed_pawns<Black>(), right?


You can''t compile that code, as c''s value cannot be decided in compile time. But that is an unlikely use of those functions. Typically, you would need to detect all passed pawns at the evaluation function, regardless of whose turn it is.

At least in the checkers and chess programs that I have written in the past, I end up having tons of duplicated code that could have been avoided with this method.

hey Guys i really love this and i have been looking for something like this for a week, i want you guys to help me get started on a very simple chess game using C could you please paste the code here so that we can discuss it, thanks!
quote:
Original post by Russell
Two things.

1. There is zero reason to use OpenGL to write graphics for a chess program
In response to Russell


1. There is zero reason to use OpenGL to write graphics for a chess program,

Could you please clarify your point further, i see no reason at this time for Druzzer007 to use OpenGL since it is less rigourous than C also at the moment he does not intend to make it a network game so i think OpenGL is the best way to start or he can use DirectX which is used by many commercial companies.
Advertisement
quote:
Original post by Anonymous Poster
In response to Russell


1. There is zero reason to use OpenGL to write graphics for a chess program,

Could you please clarify your point further, i see no reason at this time for Druzzer007 to use OpenGL since it is less rigourous than C also at the moment he does not intend to make it a network game so i think OpenGL is the best way to start or he can use DirectX which is used by many commercial companies.

My point was that he doesn''t have any need to do any kind of graphics programming period. You can download free GUIs that will work with a text based program. The text based program accepts certain commands, and it outputs certain commands to the GUI, such as "e2e4" means "I make the move e2e4". These GUIs also handle things like playing on the internet and saving the game in a standard format, and so on. This takes a lot of the work off the shoulders of the chess programmer. The chess programm now only has to worry about writing the chess playing part, and doesn''t have to worry about graphics, networking, supporting standards, and other things, which would take a lot of work just by themselves. A chess program is a big undertaking, and there is almost no reason to write all of that stuff in addition to a chess program.
quote:
Original post by Anonymous Poster
hey Guys i really love this and i have been looking for something like this for a week, i want you guys to help me get started on a very simple chess game using C could you please paste the code here so that we can discuss it, thanks!


Go here: clicky

Any of those engines with an "S" by their name come with source code. Try reading some of the easier ones, like TSCP, MSCP, and some of the other weaker ones. You can find out which ones are weak at this site.
If you''d like to use it on net you should use Java. Java has also easier possibility to add something to your code. (you liked to be independent on Windoze don''t forget it. ^-^)

It''s not about microbenchmarks it''s about easiest and bugless programming. It''s about your programming style not about OO or not OO.
So... best thing how can you learn something is by trying it. So in Java you''d like to use Graphics2D for GUI, for start. And you would like to test your idea about polymorphism on simple framework. You could have that test done by two weeks so go for IT.
I think it''s not too much about choice of language, it''s more about brain you''d use for it. You might look even at this article it''s about GO, but it could be helpfull too. CG-AISurvey.pdf google for it. ~-^
And yes for chess you''d like some standard library of starting moves. Would you risk Neural Network? ~-^
Raghar,

The computer chess community is a very strong one. We have people who have gone to great lengths to make it simple for us to write a chess program. This is how it works. You can write your chess program as a text based program. All it has to do is read commands from standard input, and write its output to standard output. The GUI takes care of setting everything up so that it can read what your program outputs and so that it can write to your program''s standard input. Your text based program only has to worry about playing chess and outputing moves (basically). The GUI takes care of displaying the board, all of the graphics and animation, and most GUIs will let your program play on several of the Internet Chess Servers such as chessclub.com or freechess.org. My point is, there is no need at all for the chess programmer to write a single line of code for graphics or networking. It may be easier to do graphics or networking in Java, but there is no need.

You can read about these communication protocols at the links below. I believe I gave them in another post in this thread also. Read about them and understand how they work before you assume Java is the best choice for a chess program. The speed penalty that you take on by using Java is unecessary, and you don''t gain anything over C/C++ in exchange for the slowdown.

Winboard
UCI

This topic is closed to new replies.

Advertisement