Changes

Jump to: navigation, search

FirstChess

4,783 bytes added, 13:05, 4 January 2019
Created page with "'''Home * Engines * FirstChess''' FILE:firstchess.png|border|right|thumb|link=http://devwebcl.atarionline.pl/cc65/firstchess.png| FirstChess screen <ref>..."
'''[[Main Page|Home]] * [[Engines]] * FirstChess'''

[[FILE:firstchess.png|border|right|thumb|link=http://devwebcl.atarionline.pl/cc65/firstchess.png| FirstChess screen <ref>firstchess.png from [http://devwebcl.atarionline.pl/cc65/ Index of /cc65]</ref> ]]

'''FirstChess''',<br/>
a very simple [[:Category:Open Source|open source chess program]] with a [[CLI|command line interface]] by [[Pham Hong Nguyen]], written in [[C]] for didactic purpose, introduced in 2002 <ref>[https://www.stmintz.com/ccc/index.php?id=242289 FirstChess - a crazy project!] by [[Pham Hong Nguyen]], [[CCC]], July 24, 2002</ref>. Since FirstChess lacks [[En passant|en passant]] and [[Castling|castling]], there is implicit invitation to improve it.

=Description=
==Board==
The [[8x8 Board|8x8 board]] consists of two [[Array|arrays]] for [[Pieces#PieceTypeCoding|piece type]] and color.
<pre>
#define PAWN 0x0
#define KNIGHT 0x1
#define BISHOP 0x2
#define ROOK 0x3
#define QUEEN 0x4
#define KING 0x5
#define EMPTY 0x6
#define WHITE 0x0
#define BLACK 0x1

int piece[64] = {
ROOK, KNIGHT,BISHOP,QUEEN, KING, BISHOP,KNIGHT,ROOK,
PAWN, PAWN, PAWN, PAWN, PAWN, PAWN, PAWN, PAWN,
EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY,
EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY,
EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY,
EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY,
PAWN, PAWN, PAWN, PAWN, PAWN, PAWN, PAWN, PAWN,
ROOK, KNIGHT,BISHOP,QUEEN, KING, BISHOP,KNIGHT,ROOK
};

int color[64] = {
BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK,
BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK,
EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY,
EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY,
EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY,
EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY,
WHITE, WHITE, WHITE, WHITE, WHITE, WHITE, WHITE, WHITE,
WHITE, WHITE, WHITE, WHITE, WHITE, WHITE, WHITE, WHITE
};
</pre>

==Search==
The [[Negamax|negamaxed]] [[Alpha-Beta|alpha-beta]] lacks any [[Move Ordering|move ordering]] techniques:
<pre>
static int 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 */
else
return 0;
}
return alpha;
}
</pre>

==Evaluation==
FirstChess' [[Evaluation|evaluation]] considers [[Material|material]] with following [[Point Value|point values]]:
<pre>
#define VALUE_PAWN 100
#define VALUE_KNIGHT 300
#define VALUE_BISHOP 300
#define VALUE_ROOK 500
#define VALUE_QUEEN 900
#define VALUE_KING 10000

int Eval()
{
int value_piece[6] = {VALUE_PAWN, VALUE_KNIGHT, VALUE_BISHOP, VALUE_ROOK, VALUE_QUEEN, VALUE_KING};
int i, score = 0;
for (i = 0; i < 64; i++) {
if (color[i] == WHITE)
score += value_piece[piece[i]];
else if (color[i] == BLACK)
score -= value_piece[piece[i]];
}
if (side == WHITE)
return score;
return -score;
}
</pre>

=See also=
* [[Ax]]

=Forum Posts=
* [https://www.stmintz.com/ccc/index.php?id=242289 FirstChess - a crazy project!] by [[Pham Hong Nguyen]], [[CCC]], July 24, 2002
* [http://www.open-aurec.com/wbforum/viewtopic.php?f=2&t=50206 Beginner programmer Winboard and chess computing advice] by tr2, [[Computer Chess Forums|Winboard Forum]], June 09, 2009

=External Links=
* [http://devwebcl.atarionline.pl/cc65/ Index of /cc65] from [http://devwebcl.atarionline.pl/ atarionline.pl] <ref>oups, better replace "unsigned char" by "int"</ref>

=References=
<references />
'''[[Engines|Up one level]]'''
[[Category:Open Source]]

Navigation menu