Mini Rodent asks for code review

Discussion of anything and everything relating to chess playing software and machines.

Moderators: hgm, Harvey Williamson, bob

Forum rules
This textbox is used to restore diagrams posted with the [d] tag before the upgrade.
Post Reply
PK
Posts: 755
Joined: Mon Jan 15, 2007 10:23 am
Location: Warsza
Contact:

Mini Rodent asks for code review

Post by PK » Thu Oct 01, 2015 3:11 pm

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.

jdart
Posts: 3503
Joined: Fri Mar 10, 2006 4:23 am
Location: http://www.arasanchess.org

Re: Mini Rodent asks for code review

Post by jdart » Thu Oct 01, 2015 8:27 pm

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

PK
Posts: 755
Joined: Mon Jan 15, 2007 10:23 am
Location: Warsza
Contact:

Re: Mini Rodent asks for code review

Post by PK » Thu Oct 01, 2015 9:23 pm

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.

jdart
Posts: 3503
Joined: Fri Mar 10, 2006 4:23 am
Location: http://www.arasanchess.org

Re: Mini Rodent asks for code review

Post by jdart » Thu Oct 01, 2015 9:57 pm

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

Dann Corbit
Posts: 8662
Joined: Wed Mar 08, 2006 7:57 pm
Location: Redmond, WA USA
Contact:

Re: Mini Rodent asks for code review

Post by Dann Corbit » Fri Oct 02, 2015 4:28 am

That code is C++ and not C.
I would rename the code to have an extension of:
.cpp
OR
.cc
OR
.C {note capitalized}

User avatar
velmarin
Posts: 1579
Joined: Mon Feb 21, 2011 8:48 am

Re: Mini Rodent asks for code review

Post by velmarin » Fri Oct 02, 2015 7:37 pm

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 !!. :) :)

Ferdy
Posts: 3607
Joined: Sun Aug 10, 2008 1:15 pm
Location: Philippines

Re: Mini Rodent asks for code review

Post by Ferdy » Sat Oct 03, 2015 10:20 am

(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.

Code: Select all

assert(p->pc[Fsq(move)] != NO_PC);  // To detect no_pc
assert&#40;p->pc&#91;Fsq&#40;move&#41;&#93; <= NO_PC&#41;;  // To detect beyond no_pc for deeper examination
history&#91;p->pc&#91;Fsq&#40;move&#41;&#93;&#93;&#91;Tsq&#40;move&#41;&#93; += depth * depth;
Considering history is,
int history[12][64];
and NO_PC is 12.

(3) From eval too.

Code: Select all

if &#40;sd == WC&#41; bbZone |= ShiftSouth&#40;bbZone&#41;;
if &#40;sd == BC&#41; bbZone |= ShiftNorth&#40;bbZone&#41;;
Suggestion.

Code: Select all

assert&#40;sd == WC || sd == BC&#41;;
if &#40;sd == WC&#41; bbZone |= ShiftSouth&#40;bbZone&#41;;
else bbZone |= ShiftNorth&#40;bbZone&#41;;
(4)

Code: Select all

printf&#40;"info depth %d time %d nodes %d nps %d\n", root_depth, elapsed, nodes, nps&#41;;
For U64 nodes and nps, you might use %I64d.

(5) Perhaps in the eval create multiple pair of score.
From,

Code: Select all

int mg&#91;2&#93;;
int eg&#91;2&#93;;
To something like.

Code: Select all

mg_pst&#91;2&#93;;
eg_pst&#91;2&#93;;

mg_pvalue&#91;2&#93;;
eg_pvalue&#91;2&#93;;

mg_pos&#91;2&#93;;
eg_pos&#91;2&#93;;

mg_mobility&#91;2&#93;;
eg_mobility&#91;2&#93;;
and others
So that later eval can be easily isolated for debugging perhaps.

PK
Posts: 755
Joined: Mon Jan 15, 2007 10:23 am
Location: Warsza
Contact:

Re: Mini Rodent asks for code review

Post by PK » Sat Oct 03, 2015 10:55 am

Thank You for all Your suggestions!

Within evaluation function I will probably prefer using a table like

Code: Select all

eval_factors&#91;side&#93;&#91;phase&#93;&#91;factor&#93;
and extending Add() function to

Code: Select all

void Add&#40;int sd, int factor, int mg, int eg&#41;
Asserts will be added ant checked after the completion of today's testing run.

Ferdy
Posts: 3607
Joined: Sun Aug 10, 2008 1:15 pm
Location: Philippines

Re: Mini Rodent asks for code review

Post by Ferdy » Sat Oct 03, 2015 11:49 am

PK wrote:Thank You for all Your suggestions!

Within evaluation function I will probably prefer using a table like

Code: Select all

eval_factors&#91;side&#93;&#91;phase&#93;&#91;factor&#93;
and extending Add() function to

Code: Select all

void Add&#40;int sd, int factor, int mg, int eg&#41;
Asserts will be added ant checked after the completion of today's testing run.
Regarding tables, I limit it to 2d, I try to avoid tables beyond that size.

PK
Posts: 755
Joined: Mon Jan 15, 2007 10:23 am
Location: Warsza
Contact:

Re: Mini Rodent asks for code review

Post by PK » Thu Oct 15, 2015 3:46 pm

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.

Post Reply