UCI implementation

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

Moderator: Ras

playjunior
Posts: 338
Joined: Fri Jun 22, 2007 12:53 am

UCI implementation

Post by playjunior »

Can anyone tell me where to find the simplest engine with UCI/Winboard? I have downloaded FirstChess and want to make it stronger than my newbie friend, but over the weekend. I have never written a chess engine before, and my "C" skills are, so to say, rather mediocre. However, the task is not impossible :).
So, my problem is: I want UCI, but I don't want to write it, I want to copy-paste :)
Thanks!
User avatar
pedrox
Posts: 1056
Joined: Fri Mar 10, 2006 6:07 am
Location: Basque Country (Spain)

Re: UCI implementation

Post by pedrox »

Good luck,

Firtschess is not a complete program, as you say he has no a protocol xboard or UCI to be able to play in a graphic interface.

The generator of moves lacks the castling and enpassant, nor does not have a generator of captures and not using quiesce. The search is simple and does not recognize the rule of the 50 moves or repeat 3 times a position, the program is not ready to play for time, only in a certain level of depth. The evaluation is only material without pieces squares position. And I believe that the program presents some bug (passed pawn?).

A game de firtschess:

Humano - Firstchess

1.e4 Na6

2.d4 Rb8

3.Nf3 Ra8

4.Bxa6 Rb8 ??

There must be some mistake in the program because it no captures the bishop.

You can not copy and paste to make a protocol UCI or Xboard, it is more complicated. I would advise you study TSCP and as makes his xboard management, I think it is as simple but you must understand a little TSCP.

DanaSah is a program that uses the generator moves of FirstChess, at least a good part of it and also its function to see if a king is in check, although danasah is written with variable names and comments in Spanish.

Pedro
playjunior
Posts: 338
Joined: Fri Jun 22, 2007 12:53 am

Re: UCI implementation

Post by playjunior »

Thanks a lot!!!
The bug in search you mentioned is becuase it returns wrong scores in eval()
It is:
if (side == WHITE)
return score;
return -score;
while it should be:
if (side == WHITE)
return -score;
return score;

I am now adding some "knowledge" to it, like I want it to understand that it should develop pieces :) :)
To tell the truth I don't want a big and complicated program to modify. I always wanted to have something of my own but always got lazy when thought about move generator :). IHMO its fun to read about all the search stuff and implement it myself, so it's an advantage of FirstChess that it has only basic Alpha-Beta.
Now I would like to add some UCI stuff and add some stuff into it until it is enough to beat a 1300-1400 player who does not know how to play against computers ;)
Once again, thank you very much for the hints.
User avatar
Jim Ablett
Posts: 2394
Joined: Fri Jul 14, 2006 7:56 am
Location: London, England
Full name: Jim Ablett

Re: UCI implementation

Post by Jim Ablett »

playjunior wrote:Can anyone tell me where to find the simplest engine with UCI/Winboard? I have downloaded FirstChess and want to make it stronger than my newbie friend, but over the weekend. I have never written a chess engine before, and my "C" skills are, so to say, rather mediocre. However, the task is not impossible :).
So, my problem is: I want UCI, but I don't want to write it, I want to copy-paste :)
Thanks!
Hi Andranik

Take a look at Glaurung's src for uci implementation.

http://www.glaurungchess.com/

regards,
Jim.
PK
Posts: 913
Joined: Mon Jan 15, 2007 11:23 am
Location: Warsza

Re: UCI implementation

Post by PK »

Some time ago I tried to improve FirstChess as my first try to write something in C (I've already got a program in Delphi). After adding some pcsq values and making sure eval is returned with a correct sign (which it was not originally.) I played a couple of moves . Program crashed as soon as there was a promotion within the horizon.
playjunior
Posts: 338
Joined: Fri Jun 22, 2007 12:53 am

Re: UCI implementation

Post by playjunior »

Thanks a lot to everyone.
Glaurungs code is awesome. Tidy, well organized, seems like a normal OO program (well, at least the classes regarding the UCI).
I will try to have a look at the promotion bug.
Btw, one more question: FirstChess has a really low node count while I have added almost no knowledge, just a couple of piece mobility tables. Is it because of the board representation and, as a result, a very slow move generator?
User avatar
pedrox
Posts: 1056
Joined: Fri Mar 10, 2006 6:07 am
Location: Basque Country (Spain)

Re: UCI implementation

Post by pedrox »

playjunior wrote:Btw, one more question: FirstChess has a really low node count while I have added almost no knowledge, just a couple of piece mobility tables. Is it because of the board representation and, as a result, a very slow move generator?
How it compares the number of nodes?

TSCP uses board 12x10 = 120 and also used mailbox. If you change the generator of moves and the generator of captures of DanaSah (based in FirstChess) by the TSCP to will have the same speed. Even the function Incheck of FirstChess is twice fast that it of TSCP.

So I think that the number of nodes is not only low by the generator, but also may not use other tricks, and things in the search, as hash tables, futility prunning, LMR, null move, etc.

If you want a generator fast of moves then perhaps you should think about bitboards, possibly as fast or more than any other system, to gain speed on 64 bits. The bitboards are not only used in the generator, also help in the evaluation.
playjunior
Posts: 338
Joined: Fri Jun 22, 2007 12:53 am

Re: UCI implementation

Post by playjunior »

pedrox wrote:
playjunior wrote:Btw, one more question: FirstChess has a really low node count while I have added almost no knowledge, just a couple of piece mobility tables. Is it because of the board representation and, as a result, a very slow move generator?
How it compares the number of nodes?

TSCP uses board 12x10 = 120 and also used mailbox. If you change the generator of moves and the generator of captures of DanaSah (based in FirstChess) by the TSCP to will have the same speed. Even the function Incheck of FirstChess is twice fast that it of TSCP.

So I think that the number of nodes is not only low by the generator, but also may not use other tricks, and things in the search, as hash tables, futility prunning, LMR, null move, etc.

If you want a generator fast of moves then perhaps you should think about bitboards, possibly as fast or more than any other system, to gain speed on 64 bits. The bitboards are not only used in the generator, also help in the evaluation.
Thank you once again for your help!
I am confused a bit now: how is the node count affected by pruning? Node count is about the nodes that are ACTUALLY visited, and whatever you prune does not count right? That was why I was surprised by FirstChess node count.
I have set depth = 5, so it makes a move after like around 1-2 second(s). I played e2-e4, it answered Ng1-f3, with a Node Count = 15000 (approximately). So 15000 nodes in 2 seconds means 7500 nodes/sec. This is horribly low number if I understand correctly.
I am using a Core2Duo 2.13 Ghz laptop and Visual Studio 2005.
PK
Posts: 913
Joined: Mon Jan 15, 2007 11:23 am
Location: Warsza

Re: UCI implementation

Post by PK »

Actually using just about any pruning technique, You reduce search speed of Your program. Hash tables require that Zorbrist keys are calculated in one way or the other, null move requires checking board material and so on.

And have You checked NPS *without* Your improvements? There is a good piece of advice, that reads: "The first thing You ought to write are the test procedures".

regards,

Pawel Koziol
playjunior
Posts: 338
Joined: Fri Jun 22, 2007 12:53 am

Re: UCI implementation

Post by playjunior »

Thank you!
Without just material evals ( the original eval function) it averages 100-150 kn/s.
With a couple of mobility tables it became 65-75 kn/s
I am using the "Release" configuration in VS 2005.
Initially I posted different numbers in this thread because that was a Debug config. However, as far as I understand- 150 kn/s means something is really slow there.