staticint Search(int alpha, int beta, int depth, MOVE * pBestMove){int i, value, havemove, movecnt;
MOVE moveBuf[200], tmpMove;
nodes++;/* visiting a node, count it */
havemove =0;
pBestMove->type = MOVE_TYPE_NONE;
movecnt = Gen(side, moveBuf);/* generate all moves for current position *//* loop through the moves */for(i =0; i < movecnt;++i){
mm2 = moveBuf[i];if(!MakeMove()){
TakeBack();continue;}
havemove =1;if(depth -1>0)/* If depth is still, continue to search deeper */
value =-Search(-beta, -alpha, depth -1, &tmpMove);else/* If no depth left (leaf node), go to evalute that position */
value = Eval();
TakeBack();if(value > alpha){/* This move is so good and caused a cutoff */if(value >= beta)return beta;
alpha = value;*pBestMove = moveBuf[i];/* so far, current move is the best reaction
* for current position */}}if(!havemove){/* If no legal moves, that is checkmate or
* stalemate */if(IsInCheck(side))return-MATE + ply;/* add ply to find the longest path to lose or shortest path to win */elsereturn0;}return alpha;}
a very simple open source chess program with a command line interface written by Pham Hong Nguyen in C for didactic purpose, introduced in 2002 [1]. Since FirstChess lacks en passant and castling, there is implicit invitation to improve it.
Table of Contents
Description
Board
The 8x8 board consists of two arrays for piece type and color.Search
The negamaxed alpha-beta lacks any move ordering techniques:Evaluation
FirstChess' evaluation considers material with following point values:See also
Forum Posts
External Links
References
What links here?
Up one level