Mini Rodent asks for code review
Moderators: hgm, Harvey Williamson, bob
Forum rules
This textbox is used to restore diagrams posted with the [d] tag before the upgrade.
This textbox is used to restore diagrams posted with the [d] tag before the upgrade.
Mini Rodent asks for code review
https://github.com/nescitus/Rodent_II
I decided to share a developement snapshot of something that will eventually become Rodent 2.0. The code I am linking to is pretty basic, and intentionally so. First of all, it may serve as a starting point of somebody else's work, just as Sungorus 1.4 by Pablo Vazquez has been my starting point. Secondly, I have already discarded two attempts at adding new features too fast, and that convinced me about the merits of establishing a solid base.
- strength is likely to exceed 2500 CCRL
- known bugs of Sungorus 1.4 are dealt with (problem with time losses, lack of a draw by 50 moves rule, castling code causing spurious MSVC range warning)
- in the process, Timer class has been created
- functions for making and unmaking moves are now part of POS (board) class
- late move reductions and late move pruning are added. the former can be easily improved, but I decided leave it for the later version.
- hashing algorithm differentiates between pv and non-pv nodes
- history table is incremented by depth * depth and there is a piece of code keeping the score within reasonable limits
- two null moves in a row are now explicitly forbidden
- there is a basic eval featuring midgame/endgame scaling, piece/square tables (basically form Toga Log User Manual), mobility, king safety, passed, backward and isolated pawns, king's pawn shield and pawn storms.
I don't want this mini engine to enter the rating lists. however, I would be very grateful for code reviews and suggestions of changes, especially those improving readability.
I decided to share a developement snapshot of something that will eventually become Rodent 2.0. The code I am linking to is pretty basic, and intentionally so. First of all, it may serve as a starting point of somebody else's work, just as Sungorus 1.4 by Pablo Vazquez has been my starting point. Secondly, I have already discarded two attempts at adding new features too fast, and that convinced me about the merits of establishing a solid base.
- strength is likely to exceed 2500 CCRL
- known bugs of Sungorus 1.4 are dealt with (problem with time losses, lack of a draw by 50 moves rule, castling code causing spurious MSVC range warning)
- in the process, Timer class has been created
- functions for making and unmaking moves are now part of POS (board) class
- late move reductions and late move pruning are added. the former can be easily improved, but I decided leave it for the later version.
- hashing algorithm differentiates between pv and non-pv nodes
- history table is incremented by depth * depth and there is a piece of code keeping the score within reasonable limits
- two null moves in a row are now explicitly forbidden
- there is a basic eval featuring midgame/endgame scaling, piece/square tables (basically form Toga Log User Manual), mobility, king safety, passed, backward and isolated pawns, king's pawn shield and pawn storms.
I don't want this mini engine to enter the rating lists. however, I would be very grateful for code reviews and suggestions of changes, especially those improving readability.
Pawel Koziol
http://www.pkoziol.cal24.pl/rodent/rodent.htm
http://www.pkoziol.cal24.pl/rodent/rodent.htm
-
jdart
- Posts: 3503
- Joined: Fri Mar 10, 2006 4:23 am
- Location: http://www.arasanchess.org
Re: Mini Rodent asks for code review
Couple of comments:
1. Try to avoid goto in the search module.
2. Unless I missed something it does not seem you have implemented futility pruning in the quiescence search (i.e. pruning moves that cannot generate a score > alpha).
--Jon
1. Try to avoid goto in the search module.
2. Unless I missed something it does not seem you have implemented futility pruning in the quiescence search (i.e. pruning moves that cannot generate a score > alpha).
--Jon
Re: Mini Rodent asks for code review
ad 1: OK, this will be done
ad 2: Mini Rodent inherits some things from Sungorus. One of them is slightly bizzare implementation of delta/futility pruning in quiescence search: it is done on the move generator level via BadCapture() function, which is a wrapper for SEE (not called on low x high). It is a bit confusing, so I'll change that.
ad 2: Mini Rodent inherits some things from Sungorus. One of them is slightly bizzare implementation of delta/futility pruning in quiescence search: it is done on the move generator level via BadCapture() function, which is a wrapper for SEE (not called on low x high). It is a bit confusing, so I'll change that.
Pawel Koziol
http://www.pkoziol.cal24.pl/rodent/rodent.htm
http://www.pkoziol.cal24.pl/rodent/rodent.htm
-
jdart
- Posts: 3503
- Joined: Fri Mar 10, 2006 4:23 am
- Location: http://www.arasanchess.org
Re: Mini Rodent asks for code review
As far as I can tell, BadCapture does not compare against alpha. It only tests for non-gaining captures. You can have a capture that gains a pawn, but if you are 3 pawns below alpha that will not help.
--Jon
--Jon
-
Dann Corbit
- Posts: 8662
- Joined: Wed Mar 08, 2006 7:57 pm
- Location: Redmond, WA USA
- Contact:
Re: Mini Rodent asks for code review
That code is C++ and not C.
I would rename the code to have an extension of:
.cpp
OR
.cc
OR
.C {note capitalized}
I would rename the code to have an extension of:
.cpp
OR
.cc
OR
.C {note capitalized}
Re: Mini Rodent asks for code review
Thanks, all these initiatives seem to magnificent. ´
How amateur and apprentice find it lacking in "comments or learning", too many formulas that do not help the learning "without more explanation".
How a new writing of code (little innovative) that does not start with magic bitboards, not seems difficult to do so. Rodent could be "much Rodent".Very thanks !!.

How amateur and apprentice find it lacking in "comments or learning", too many formulas that do not help the learning "without more explanation".
How a new writing of code (little innovative) that does not start with magic bitboards, not seems difficult to do so. Rodent could be "much Rodent".Very thanks !!.
Re: Mini Rodent asks for code review
(1) Perhaps it is better to separate piece_values from pst's, in the spirit of readability and future eval parameter value auto-tuning.
(2) Might add an assert as well, to make sure history has good data.
Considering history is,
int history[12][64];
and NO_PC is 12.
(3) From eval too.
Suggestion.
(4)
For U64 nodes and nps, you might use %I64d.
(5) Perhaps in the eval create multiple pair of score.
From,
To something like.
So that later eval can be easily isolated for debugging perhaps.
(2) Might add an assert as well, to make sure history has good data.
Code: Select all
assert(p->pc[Fsq(move)] != NO_PC); // To detect no_pc
assert(p->pc[Fsq(move)] <= NO_PC); // To detect beyond no_pc for deeper examination
history[p->pc[Fsq(move)]][Tsq(move)] += depth * depth;int history[12][64];
and NO_PC is 12.
(3) From eval too.
Code: Select all
if (sd == WC) bbZone |= ShiftSouth(bbZone);
if (sd == BC) bbZone |= ShiftNorth(bbZone);Code: Select all
assert(sd == WC || sd == BC);
if (sd == WC) bbZone |= ShiftSouth(bbZone);
else bbZone |= ShiftNorth(bbZone);Code: Select all
printf("info depth %d time %d nodes %d nps %d\n", root_depth, elapsed, nodes, nps);(5) Perhaps in the eval create multiple pair of score.
From,
Code: Select all
int mg[2];
int eg[2];Code: Select all
mg_pst[2];
eg_pst[2];
mg_pvalue[2];
eg_pvalue[2];
mg_pos[2];
eg_pos[2];
mg_mobility[2];
eg_mobility[2];
and othersRe: Mini Rodent asks for code review
Thank You for all Your suggestions!
Within evaluation function I will probably prefer using a table like
and extending Add() function to
Asserts will be added ant checked after the completion of today's testing run.
Within evaluation function I will probably prefer using a table like
Code: Select all
eval_factors[side][phase][factor]Code: Select all
void Add(int sd, int factor, int mg, int eg)Pawel Koziol
http://www.pkoziol.cal24.pl/rodent/rodent.htm
http://www.pkoziol.cal24.pl/rodent/rodent.htm
Re: Mini Rodent asks for code review
Regarding tables, I limit it to 2d, I try to avoid tables beyond that size.PK wrote:Thank You for all Your suggestions!
Within evaluation function I will probably prefer using a table like
and extending Add() function toCode: Select all
eval_factors[side][phase][factor]
Asserts will be added ant checked after the completion of today's testing run.Code: Select all
void Add(int sd, int factor, int mg, int eg)
Re: Mini Rodent asks for code review
it seems that I reached my goal a bit earlier than expected and this 2400 lines of code can already hold its own against good old Fruit 2.1. so here comes Mini Rodent 0.2, still not ready for the rating lists, but probably 2650+ Elo on CCRL scale:
https://github.com/nescitus/Rodent_II
the code might have been even shorter, were it not for debugging infrastructure. however, in the next 100 lines You will see more of it - perft, detailed evaluation output and some console mode enhancements are missing.
https://github.com/nescitus/Rodent_II
the code might have been even shorter, were it not for debugging infrastructure. however, in the next 100 lines You will see more of it - perft, detailed evaluation output and some console mode enhancements are missing.
Pawel Koziol
http://www.pkoziol.cal24.pl/rodent/rodent.htm
http://www.pkoziol.cal24.pl/rodent/rodent.htm
