Open source engine random moves

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

Isaac
Posts: 265
Joined: Sat Feb 22, 2014 8:37 pm

Open source engine random moves

Post by Isaac »

I wonder whether there's an open source chess engine that plays totally random moves. If not, how hard would it be to transform Stockfish into such an engine?

I ask this because I have something in mind to do with such an engine, of course.


I'd prefer open source because I could know which pseudo random number generator the engine uses and I'd prefer one that's "good".
Thanks!
User avatar
MikeB
Posts: 4889
Joined: Thu Mar 09, 2006 6:34 am
Location: Pen Argyl, Pennsylvania

Re: Open source engine random moves

Post by MikeB »

Search Brutus random or BrustusRND. Plays random moves and CCRL tested it and its rating was about 210. Not sure if it's open source.
Isaac
Posts: 265
Joined: Sat Feb 22, 2014 8:37 pm

Re: Open source engine random moves

Post by Isaac »

MikeB wrote:Search Brutus random or BrustusRND. Plays random moves and CCRL tested it and its rating was about 210. Not sure if it's open source.
Thanks, I just downloaded it. Apparently only works under windows (ouch), and yes it seems to be closed source so I don't know how good or bad the prng is.

Regarding Stockfish option, should I modify search.cpp, abort the search early and return any legal move randomly? Or do I need to tweak several files?
xmas79
Posts: 286
Joined: Mon Jun 03, 2013 7:05 pm
Location: Italy

Re: Open source engine random moves

Post by xmas79 »

RandomFish sounds good :)

Simply generate all moves at the root, generate one random number between 0 and N-1 (where N is the number of moves the movegen generates) and play it, totally skipping search.

Is that enough?
Isaac
Posts: 265
Joined: Sat Feb 22, 2014 8:37 pm

Re: Open source engine random moves

Post by Isaac »

xmas79 wrote:RandomFish sounds good :)

Simply generate all moves at the root, generate one random number between 0 and N-1 (where N is the number of moves the movegen generates) and play it, totally skipping search.

Is that enough?
Is this code in movegen.cpp? I'm not sure where exactly.

Do I need to modify search.cpp and write somewhere "return Rootmoves" where i is a random number between 0 and N-1 where N is the number of legal moves for a given position?

Edit: I need it to be aware of the 50 moves draw rule.

Edit2: Nevermind about that last sentence, I suppose cutechess will adjudicate games with that rule.
Isaac
Posts: 265
Joined: Sat Feb 22, 2014 8:37 pm

Re: Open source engine random moves

Post by Isaac »

I don't see where in the code SF returns its move.
Isaac
Posts: 265
Joined: Sat Feb 22, 2014 8:37 pm

Re: Open source engine random moves

Post by Isaac »

I think I made it. I'll make my test.
Isaac
Posts: 265
Joined: Sat Feb 22, 2014 8:37 pm

Re: Open source engine random moves

Post by Isaac »

Unfortunately my SF version doesn't play entirely randomly. I've made a few changes in search.cpp, like best = rootMoves[j].pv[0]; where j is a random int between 0 and the number of legal moves for the root position.
Here's the code of the file I modified: http://pastebin.com/zENrhpgM, with my changes. I'd appreciate if someone could fix it and make SF play randomly and then post the code either in github or pastebin.

I've ran a match of about 60 games between 2 such modified SF and got around 10 wins which is way too many. That's why I believe it doesn't play entirely randomly.
User avatar
Laskos
Posts: 10948
Joined: Wed Jul 26, 2006 10:21 pm
Full name: Kai Laskos

Re: Open source engine random moves

Post by Laskos »

Isaac wrote: I've ran a match of about 60 games between 2 such modified SF and got around 10 wins which is way too many. That's why I believe it doesn't play entirely randomly.
Why? Have a look at:
http://www.talkchess.com/forum/viewtopic.php?t=40193

"One billion random games generated with a single thread on a 3.2 GHz Intel Core i3:

Code: Select all

[] rgstat 1000000000 
Summary: 
  Checkmate 153,023,351 (0.153023) 
  FiftyMoves 199,868,185 (0.199868) 
  Insufficient 560,510,846 (0.560511) 
  Repetition 25,427,172 (0.0254272) 
  Stalemate 61,170,446 (0.0611704) 
Count: 1,000,000,000   Elapsed: 159960  (6251.57 Hz / 0.00015996 s)
".

Could you share a Windows binary?
AlvaroBegue
Posts: 931
Joined: Tue Mar 09, 2010 3:46 pm
Location: New York
Full name: Álvaro Begué (RuyDos)

Re: Open source engine random moves

Post by AlvaroBegue »

I made a random-moving version of my engine and I removed most of the needless parts. What's a good place for me to post it?

EDIT: Let's try DropBox. https://www.dropbox.com/sh/1o3ymy403yy8 ... 0-MUa?dl=0