First move without opening book - search or hardcode?

Discussion of chess software programming and technical issues.

Moderator: Ras

KhepriChess
Posts: 93
Joined: Sun Aug 08, 2021 9:14 pm
Full name: Kurt Peters

First move without opening book - search or hardcode?

Post by KhepriChess »

Currently my engine does not make use of an opening book.

Rather than doing a whole search routine immediately from move 1 (assuming the engine is playing as white), is it frowned upon to just hardcode possible common first moves and then randomly pick one of them (like e4, d4, Nc3, Nf3)? I could do a GetMoves at the start and randomly pick one from there, but I don't really want to be making something like 1. h3.
Puffin: Github
KhepriChess: Github
tcusr
Posts: 325
Joined: Tue Aug 31, 2021 10:32 pm
Full name: tcusr

Re: First move without opening book - search or hardcode?

Post by tcusr »

if the first suggested move is h3 then there's something wrong with evaluation
User avatar
algerbrex
Posts: 608
Joined: Sun May 30, 2021 5:03 am
Location: United States
Full name: Christian Dean

Re: First move without opening book - search or hardcode?

Post by algerbrex »

Don't see why this would be frowned upon. Uncommon maybe, but not frowned upon. I'd just make sure to have a way to disable it and make sure it wouldn't be used if the engine was given a position to start from beside the initial position. Although why not opt for just adding polyglot book support instead? Not to hard to get up and running and it gives you to freedom to not only develop a dedicated opening book for your engine in the future but also decouples the book from the engine making it easier to maintain the two in the long run since nothing is hard-coded.

That's what I've done with Blunder, and although right now I don't have a dedicated opening book for it, if I wanted to in the future, I'd just need to use the polyglot tools to create one and then ship it with the engine. And if the user wants to try a different opening book, no problem, just swap their favorite one in and Blunder will pull moves from there.
JVMerlino
Posts: 1397
Joined: Wed Mar 08, 2006 10:15 pm
Location: San Francisco, California

Re: First move without opening book - search or hardcode?

Post by JVMerlino »

Certainly not frowned upon. What you are essentially doing is making a VERY short custom opening book. :D

Just be sure your engine works properly if a GUI tries to force its own opening book moves on your engine, and you're fine.
User avatar
lithander
Posts: 915
Joined: Sun Dec 27, 2020 2:40 am
Location: Bremen, Germany
Full name: Thomas Jahn

Re: First move without opening book - search or hardcode?

Post by lithander »

I think it shouldn't be needed. The GUI usually takes care of playing the opening and if you play "from scratch" your engine will play what it thinks will lead to a good position. I found that as the engine goes stronger it will automatically start to play lines that can be found in an opening book, just as it learns to convert won endgames without a table-base.
Minimal Chess (simple, open source, C#) - Youtube & Github
Leorik (competitive, in active development, C#) - Github & Lichess
KhepriChess
Posts: 93
Joined: Sun Aug 08, 2021 9:14 pm
Full name: Kurt Peters

Re: First move without opening book - search or hardcode?

Post by KhepriChess »

algerbrex wrote: Sat Aug 06, 2022 11:20 pm Don't see why this would be frowned upon. Uncommon maybe, but not frowned upon. I'd just make sure to have a way to disable it and make sure it wouldn't be used if the engine was given a position to start from beside the initial position. Although why not opt for just adding polyglot book support instead? Not to hard to get up and running and it gives you to freedom to not only develop a dedicated opening book for your engine in the future but also decouples the book from the engine making it easier to maintain the two in the long run since nothing is hard-coded.

That's what I've done with Blunder, and although right now I don't have a dedicated opening book for it, if I wanted to in the future, I'd just need to use the polyglot tools to create one and then ship it with the engine. And if the user wants to try a different opening book, no problem, just swap their favorite one in and Blunder will pull moves from there.
Well, maybe then that's just what I'll look at doing and just do it right rather than trying to come up with some half-baked solution.
Puffin: Github
KhepriChess: Github
op12no2
Posts: 547
Joined: Tue Feb 04, 2014 12:25 pm
Location: Gower, Wales
Full name: Colin Jenkins

Re: First move without opening book - search or hardcode?

Post by op12no2 »

There again, letting it search fills the TT.
jdart
Posts: 4398
Joined: Fri Mar 10, 2006 5:23 am
Location: http://www.arasanchess.org

Re: First move without opening book - search or hardcode?

Post by jdart »

UCI engines generally defer opening book handling to the interface they're connected to (Chessbase, Fritz, cutechess, etc).

Arasan has its own opening book with a custom format, but that's mostly for historical reasons. (This can be disabled in case an external program is handling the book).
pedrojdm2021
Posts: 157
Joined: Fri Apr 30, 2021 7:19 am
Full name: Pedro Duran

Re: First move without opening book - search or hardcode?

Post by pedrojdm2021 »

leave it optional:

From UCI Protocol:
* option
* = OwnBook, type check
this means that the engine has its own book which is accessed by the engine itself.
if this is set, the engine takes care of the opening book and the GUI will never
execute a move out of its book for the engine. If this is set to false by the GUI,
the engine should not access its own book.
clayt
Posts: 29
Joined: Thu Jun 09, 2022 5:09 am
Full name: Clayton Ramsey

Re: First move without opening book - search or hardcode?

Post by clayt »

Regarding your first suggested move being h3: I suspect that your leaf evaluation function isn't fine-grained enough, and so your engine is selecting either the first or last move generated, as the rest of the opening moves have the same leaf evaluation after search. Is your current evaluation function just pure material?

As soon as you add a good PST, this issue should go away.