Advertisement

How to program a chess: a forum based tutorial

Started by December 23, 2004 11:09 PM
276 comments, last by da_grat1 19 years, 8 months ago
Quote: To be honest, I think the Beowulf code needs to be rewritten because I'm finding it almost illegible.


yeah.. very true.. the code is illegible... No matter how I read it.. still can't understand it.. T_T ... but when I see you modify the main.c .. my brain suddenly open.. b'coz it is more readable... :)

By the way... about the latest source code that you uploaded here.. when I try run it, the only thing I can see is the loading bar.. Is it like that? or something wrong with my pc..

It cannot load the chess board or pieces like in your previous source code before you add the loading bar..

Do I need to add something in order to see the board...?
Quote:
By the way... about the latest source code that you uploaded here.. when I try run it, the only thing I can see is the loading bar.. Is it like that? or something wrong with my pc..

It cannot load the chess board or pieces like in your previous source code before you add the loading bar..

Do I need to add something in order to see the board...?


Right now as a test it basically loads all of the subsystems and then unloads them. Nothing graphical. After we finish the Beowulf dll, we are going to start working on the graphical stuff.

I also spent a good portion of my time yesterday researching chess engines. Unfortunately the way they typically link to the driver app is very nasty (IMO). However, as interfaces go, we have one of the coolest around :).

Will post later,
- llvllatrix
Advertisement
Quote: However, as interfaces go, we have one of the coolest around :).

Very true.. lol..
That means.. to load the graphics and move the pieces might take a long time to be done..
Hey guys,

Here's a quick update on my progress. After a few hours of coding I'm finially finished with the first cut of the INTERFACE to the chess engine. Here it is:

#ifndef __BW_H__#define __BW_H__//----------------------------------------------------------------------------////bw.h////Copyright © Rishi Ramraj, 2005// Beowulf DLL Header//----------------------------------------------------------------------------#ifdef __cplusplusextern "C" {#endif//··········································································////    header :: Inclusions//··········································································////··········································································////    header :: Definitions//··········································································//#define DLL_ENTRY __declspec(dllexport)// Beowulf standard typestypedef void					bw_void;typedef int						bw_bool;typedef unsigned int			bw_enum;typedef char					bw_char;typedef bw_char					bw_string [256]	;typedef int						bw_int;typedef float					bw_float;typedef double					bw_double;// Boolean #define BW_TRUE								1#define BW_FALSE							0// Beowulf chess typestypedef bw_char					bw_move[10];typedef signed char				bw_piece;typedef bw_piece				bw_board[64];// Piece Identifiers#define BW_PAWN								1#define BW_ROOK								2#define BW_KNIGHT  							3#define BW_BISHOP  							4#define BW_QUEEN   							5#define BW_KING    							6#define BW_EMPTY   							0#define BW_WHITE_PAWN   					(BW_PAWN)#define BW_WHITE_ROOK   					(BW_ROOK)#define BW_WHITE_KNIGHT 					(BW_KNIGHT)#define BW_WHITE_BISHOP 					(BW_BISHOP)#define BW_WHITE_QUEEN  					(BW_QUEEN)#define BW_WHITE_KING   					(BW_KING)#define BW_BLACK_PAWN   					(-BW_PAWN)#define BW_BLACK_ROOK   					(-BW_ROOK)#define BW_BLACK_KNIGHT 					(-BW_KNIGHT)#define BW_BLACK_BISHOP 					(-BW_BISHOP)#define BW_BLACK_QUEEN  					(-BW_QUEEN)#define BW_BLACK_KING   					(-BW_KING)// Colors#define BW_WHITE						0x0000#define BW_BLACK						0x0001// Enable Modes#define BW_OPEN_BOOK						0x0010#define BW_RESIGN						0x0011// Game States#define BW_GAME_UNSTARTED					0x0020#define BW_GAME_IN_PROGRESS					0x0021#define BW_CHECK						0x0022#define BW_CHECKMATE						0x0023#define BW_STALEMATE						0x0024#define BW_DRAW_REPETITION					0x0025#define BW_DRAW_FIFTY_MOVE_RULE					0x0026#define BW_DRAW_LACK_OF_FORCE					0x0027//··········································································////    header :: Structures//··········································································////··········································································////    header :: Class Defs//··········································································////··········································································////    header :: Function Defs//··········································································////// System Management//// bw_init_beowulf// Initialize the Beowulf system. This must be called before any calls to the// system can take effect. This function should only be called once. Returns true // on success, false otherwise. Behaviour is undefined if initialization is // called more than once.DLL_ENTRY bw_bool bw_init_beowulf(void);// bw_deinit_beowulf// Deinitialize the Beowulf system. This function must be called after all// calls to the image system. This function should only be called once.DLL_ENTRY bw_void bw_deinit_beowulf(void);// bw_enable// Enables subsystems defined under Enable Modes above.DLL_ENTRY bw_void bw_enable(bw_enum ena_mode);// bw_disable// disables subsystems defined under Enable Modes above.DLL_ENTRY bw_void bw_disable(bw_enum ena_mode);//// Opening Book//// bw_load_opening_book// Loads the opening book for the Beowulf system. This file contains strategy// for the beginning of the chess game. The system can function without the// file.DLL_ENTRY bw_bool bw_load_opening_book(bw_string path);// bw_reset_opening_book// Unloads the opening book. This is also called by bw_deinit_beowulf().DLL_ENTRY bw_void bw_reset_opening_book(bw_void);//// System Personality//// bw_load_personality// Loads the personality file for the Beowulf system. The system can function // without the file.DLL_ENTRY bw_bool bw_load_personality(bw_string path);// bw_reset_personality// Unloads the personality. This is also called by bw_deinit_beowulf().DLL_ENTRY bw_void bw_reset_personality(bw_void);//// Attribute Manager//// bw_reset_attrs// Resets the system to it's default state (note that this is independent from// the Opening Book and Personality).DLL_ENTRY bw_void bw_reset_attrs(bw_void);// bw_set_white_chess_clock_attr// Sets the total length of white's game in minutes; the length of the// game is the time a player has to achieve a check mate.DLL_ENTRY bw_void bw_set_white_chess_clock_attr(bw_float minutes);// bw_set_black_chess_clock_attr// Sets the total length of black's game in minutes; the length of the// game is the time a player has to achieve a check mate.DLL_ENTRY bw_void bw_set_black_chess_clock_attr(bw_float minutes);// bw_set_max_move_duration_attr// The maximum time a computer player has to make it's move. This// time is overrided by the minimum depth attribute.DLL_ENTRY bw_void bw_set_max_move_duration_attr(bw_float minutes);// bw_set_min_search_depth_attr// Sets the minimum search depth. When the computer is computing a// move it builds a tree of possible moves and expands that tree to// produce better results. The minimum search depth reprents how many// moves ahead the computer should search at a minimum.DLL_ENTRY bw_void bw_set_min_search_depth_attr(bw_int depth);// bw_set_white_skill_attr// Skill level of the white computer opponent. This is an integer // between 1 and 10, 10 being the strongest.DLL_ENTRY bw_void bw_set_white_skill_attr(bw_int skill);// bw_set_black_skill_attr// Skill level of the black computer opponent. This is an integer // between 1 and 10, 10 being the strongest.DLL_ENTRY bw_void bw_set_black_skill_attr(bw_int skill);// bw_set_hash_size_attr// Size of the hash table used by the AI. Larger sizes produce// faster computations. Hash Table Size is 2^size kb.DLL_ENTRY bw_void bw_set_hash_size_attr(bw_int size);//// Game manager//// bw_begin_game// Resets the current state of the game to a new one. This must be followed// by an accompanying bw_end_game() call.DLL_ENTRY bw_void bw_begin_game(bw_void);// bw_end_game// Resets the current state of the game to a new one. This must be follow// an accompanying bw_begin_game() call.DLL_ENTRY bw_void bw_end_game(bw_void);// The following game functions should be called in the main game loop:// bw_ai_ponder_game// An optional call which lets the computer think about its next move while// it's opponent makes their move. This should be called before a call to // bw_move_game or bw_ai_move_game.DLL_ENTRY bw_void bw_ai_ponder_game(bw_void);// bw_move_game// Posts a move to the current side. Returns false if the move is illegal.// This function also returns false if the current game state is not playable.DLL_ENTRY bw_bool bw_move_game(bw_move move);// bw_ai_move_game// Makes the AI preform a move for the current side.DLL_ENTRY bw_void bw_ai_move_game(bw_void);// bw_update_game// Updates the board.DLL_ENTRY bw_void bw_update_game(bw_void);//// Game state information//// bw_get_game_state_info// Retrieves the current game state. Refer to game state definitions above.DLL_ENTRY bw_enum bw_get_game_state_info(bw_void);// bw_get_board_info// Retrieves an image of the current board.DLL_ENTRY bw_board bw_get_board_info(bw_void);//----------------------------------------------------------------------------//bw.h//Copyright © Rishi Ramraj, 2005//----------------------------------------------------------------------------#ifdef __cplusplus}#endif#endif //__BW_H__


All I have left to do is the implementation of the game manager and info functions (unfortunately, the hardest implementations to write). After that I'll write a quick test app and post the results.

Will post later,
- llvllatrix
Hey guys,

Here's a quick update on my progress. After a few hours of coding I'm finially finished with the first cut of the INTERFACE to the chess engine. Here it is:

#ifndef __BW_H__#define __BW_H__//----------------------------------------------------------------------------////bw.h////Copyright © Rishi Ramraj, 2005// Beowulf DLL Header//----------------------------------------------------------------------------#ifdef __cplusplusextern "C" {#endif//··········································································////    header :: Inclusions//··········································································////··········································································////    header :: Definitions//··········································································//#define DLL_ENTRY __declspec(dllexport)// Beowulf standard typestypedef void					bw_void;typedef int						bw_bool;typedef unsigned int			bw_enum;typedef char					bw_char;typedef bw_char					bw_string [256]	;typedef int						bw_int;typedef float					bw_float;typedef double					bw_double;// Boolean #define BW_TRUE								1#define BW_FALSE							0// Beowulf chess typestypedef bw_char					bw_move[10];typedef signed char				bw_piece;typedef bw_piece				bw_board[64];// Piece Identifiers#define BW_PAWN								1#define BW_ROOK								2#define BW_KNIGHT  							3#define BW_BISHOP  							4#define BW_QUEEN   							5#define BW_KING    							6#define BW_EMPTY   							0#define BW_WHITE_PAWN   					(BW_PAWN)#define BW_WHITE_ROOK   					(BW_ROOK)#define BW_WHITE_KNIGHT 					(BW_KNIGHT)#define BW_WHITE_BISHOP 					(BW_BISHOP)#define BW_WHITE_QUEEN  					(BW_QUEEN)#define BW_WHITE_KING   					(BW_KING)#define BW_BLACK_PAWN   					(-BW_PAWN)#define BW_BLACK_ROOK   					(-BW_ROOK)#define BW_BLACK_KNIGHT 					(-BW_KNIGHT)#define BW_BLACK_BISHOP 					(-BW_BISHOP)#define BW_BLACK_QUEEN  					(-BW_QUEEN)#define BW_BLACK_KING   					(-BW_KING)// Colors#define BW_WHITE						0x0000#define BW_BLACK						0x0001// Enable Modes#define BW_OPEN_BOOK						0x0010#define BW_RESIGN						0x0011// Game States#define BW_GAME_UNSTARTED					0x0020#define BW_GAME_IN_PROGRESS					0x0021#define BW_CHECK						0x0022#define BW_CHECKMATE						0x0023#define BW_STALEMATE						0x0024#define BW_DRAW_REPETITION					0x0025#define BW_DRAW_FIFTY_MOVE_RULE					0x0026#define BW_DRAW_LACK_OF_FORCE					0x0027//··········································································////    header :: Structures//··········································································////··········································································////    header :: Class Defs//··········································································////··········································································////    header :: Function Defs//··········································································////// System Management//// bw_init_beowulf// Initialize the Beowulf system. This must be called before any calls to the// system can take effect. This function should only be called once. Returns true // on success, false otherwise. Behaviour is undefined if initialization is // called more than once.DLL_ENTRY bw_bool bw_init_beowulf(void);// bw_deinit_beowulf// Deinitialize the Beowulf system. This function must be called after all// calls to the image system. This function should only be called once.DLL_ENTRY bw_void bw_deinit_beowulf(void);// bw_enable// Enables subsystems defined under Enable Modes above.DLL_ENTRY bw_void bw_enable(bw_enum ena_mode);// bw_disable// disables subsystems defined under Enable Modes above.DLL_ENTRY bw_void bw_disable(bw_enum ena_mode);//// Opening Book//// bw_load_opening_book// Loads the opening book for the Beowulf system. This file contains strategy// for the beginning of the chess game. The system can function without the// file.DLL_ENTRY bw_bool bw_load_opening_book(bw_string path);// bw_reset_opening_book// Unloads the opening book. This is also called by bw_deinit_beowulf().DLL_ENTRY bw_void bw_reset_opening_book(bw_void);//// System Personality//// bw_load_personality// Loads the personality file for the Beowulf system. The system can function // without the file.DLL_ENTRY bw_bool bw_load_personality(bw_string path);// bw_reset_personality// Unloads the personality. This is also called by bw_deinit_beowulf().DLL_ENTRY bw_void bw_reset_personality(bw_void);//// Attribute Manager//// bw_reset_attrs// Resets the system to it's default state (note that this is independent from// the Opening Book and Personality).DLL_ENTRY bw_void bw_reset_attrs(bw_void);// bw_set_white_chess_clock_attr// Sets the total length of white's game in minutes; the length of the// game is the time a player has to achieve a check mate.DLL_ENTRY bw_void bw_set_white_chess_clock_attr(bw_float minutes);// bw_set_black_chess_clock_attr// Sets the total length of black's game in minutes; the length of the// game is the time a player has to achieve a check mate.DLL_ENTRY bw_void bw_set_black_chess_clock_attr(bw_float minutes);// bw_set_max_move_duration_attr// The maximum time a computer player has to make it's move. This// time is overrided by the minimum depth attribute.DLL_ENTRY bw_void bw_set_max_move_duration_attr(bw_float minutes);// bw_set_min_search_depth_attr// Sets the minimum search depth. When the computer is computing a// move it builds a tree of possible moves and expands that tree to// produce better results. The minimum search depth reprents how many// moves ahead the computer should search at a minimum.DLL_ENTRY bw_void bw_set_min_search_depth_attr(bw_int depth);// bw_set_white_skill_attr// Skill level of the white computer opponent. This is an integer // between 1 and 10, 10 being the strongest.DLL_ENTRY bw_void bw_set_white_skill_attr(bw_int skill);// bw_set_black_skill_attr// Skill level of the black computer opponent. This is an integer // between 1 and 10, 10 being the strongest.DLL_ENTRY bw_void bw_set_black_skill_attr(bw_int skill);// bw_set_hash_size_attr// Size of the hash table used by the AI. Larger sizes produce// faster computations. Hash Table Size is 2^size kb.DLL_ENTRY bw_void bw_set_hash_size_attr(bw_int size);//// Game manager//// bw_begin_game// Resets the current state of the game to a new one. This must be followed// by an accompanying bw_end_game() call.DLL_ENTRY bw_void bw_begin_game(bw_void);// bw_end_game// Resets the current state of the game to a new one. This must be follow// an accompanying bw_begin_game() call.DLL_ENTRY bw_void bw_end_game(bw_void);// The following game functions should be called in the main game loop:// bw_ai_ponder_game// An optional call which lets the computer think about its next move while// it's opponent makes their move. This should be called before a call to // bw_move_game or bw_ai_move_game.DLL_ENTRY bw_void bw_ai_ponder_game(bw_void);// bw_move_game// Posts a move to the current side. Returns false if the move is illegal.// This function also returns false if the current game state is not playable.DLL_ENTRY bw_bool bw_move_game(bw_move move);// bw_ai_move_game// Makes the AI preform a move for the current side.DLL_ENTRY bw_void bw_ai_move_game(bw_void);// bw_update_game// Updates the board.DLL_ENTRY bw_void bw_update_game(bw_void);//// Game state information//// bw_get_game_state_info// Retrieves the current game state. Refer to game state definitions above.DLL_ENTRY bw_enum bw_get_game_state_info(bw_void);// bw_get_board_info// Retrieves an image of the current board.DLL_ENTRY bw_board bw_get_board_info(bw_void);//----------------------------------------------------------------------------//bw.h//Copyright © Rishi Ramraj, 2005//----------------------------------------------------------------------------#ifdef __cplusplus}#endif#endif //__BW_H__


All I have left to do is the implementation of the game manager and info functions (unfortunately, the hardest implementations to write). After that I'll write a quick test app and post the results.

Will post later,
- llvllatrix
Wow Really great.. llvllatrix... you manage to modify that troublesome code, from unreadable to readable..
Is the game really going to work soon...
Advertisement
Hey guys,

Anyone up for a game of chess?
http://www.eng.uwaterloo.ca/~rramraj/Gamedev/chess_tutorial/src_tree/chess_src.zip

I've basically wrapped the chess engine and used it in a console interface. You should be able to play the computer if you run the beowulf test binaries. Type quit to exit.

In order to convey your moves to the engine you have to use standard chess notation:
http://www.logicalchess.com/info/reference/notation/

Next I'll be using SDL for our window and UI. Have fun with the code :)

Will post later,
- llvllatrix


[Edited by - llvllatrix on March 13, 2005 8:51:32 AM]
Hey there everyone, Just thought I'd let you know, I ported the beowulf engine to linux, my code SHOULD compile on Linux AND Windows, (I'm waiting for llvllatrix to get back to me about the Windows part)

Please note that for now, all I did was use #ifdef's to make the code compile on linux and probably windows, as well as create a few fairly basic makefiles. and so far, only for the Beowulf specific stuff, I'm working on the rest of it right now, so the rest of the code will still not compile on Linux.


But you can fire up the test file and have a blast :)


find it:  http://www.grevian.org/~grey/files/chess_src.tar.gz
MD5 Sum: d23c55479c10b045460cf8fdc7540800


There.

And stay tuned as I poke 11v11atrix repeatedly for not being cross platform friendly... and for having a hard to type nick :P



edit: Ack! only 4 edit's later, I think this post looks OK, gotta get used to this forum, long time reader, first time poster ;)

[Edited by - Grevian on March 12, 2005 9:40:06 PM]
Hahaha.. Great llvllatrix.. this is the first time I play it in dos.. :) and first of all, it is very hard to figure out the move.. but after I learn from the website... I am able to play the game... but however, still take time to move the alphabets.. lol...

The next one is you are going to implement the SDL and UI right...that means we should be able to load the graphics aswell right..?
ick, the basecode for this is a pain, I dunno what state 11v11atrix is at, but I'm gonna start busting out wxWindows on this thing, and see where I get to, his basecode is all totally windows centric :(

This topic is closed to new replies.

Advertisement