iPlayChess - A TalkChess Community Engine

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

Mike Sherwin
Posts: 860
Joined: Fri Aug 21, 2020 1:25 am
Location: Planet Earth, Sol system
Full name: Michael J Sherwin

Re: iPlayChess - A TalkChess Community Engine

Post by Mike Sherwin »

abulmo2 wrote: Thu Mar 25, 2021 12:58 pm
1. C - cpp as a better C
Do you mean you are going to abuse the C preprocessor?
Whatever, there is no betterC for cpp:

Code: Select all

$ cpp -betterC hello.c
$ cpp: error: unrecognized command-line option '-betterC'
Use a D compiler instead:
$ ldc2 -betterC hello.d
$ hello

Code: Select all

Hello betterC
If you want a better C ,use a better language ;-)
As it seems that 90% of authors prefer UCI protocol I guess I'll have to learn UCI, ouch. Maybe someone can contrib some UCI code to Get_Command()?

Code: Select all

s32 main() {
  Move move;

  Initialize();

  while (play) {
    Get_Command();
    if (play == PLAY) move = I_Play_Chess(thread[0]);
    if (play == MOVE) Game(move);
  }

  return 0;
}
This is not UCI compliant. UCI does not send move, but a position (with eventually a serie of moves) before asking to think with the go command.
I prefer int main(void) to s32 main() as a more pedantically conforming definition of main, I also hate global variable like play, thread[0], etc. but I guess it is your style. So a more UCI like loop could be in your style could be:

Code: Select all

s32 main() {
  Move move;

  Initialize();

  while (play) {
    Get_Command();
    if (play == UCI) UCI_Info();
    if (play == GO) I_Play_Chess(thread[0]);
    if (play == POS) Set_Position(thread[0]);
    // etc.
  }
In my style a C UCI loop will looks more like that:

Code: Select all

/* Main loop */
int main(void)
{
	char *line = NULL, *param = NULL;
	Uci uci[1];

	globals_init();

	uci_init(uci);

	// loop forever
	for (;;) {
		line = event_wait(uci->event);

		// skip spaces
		param = parse_next(line);

		// uci
		if (parse_command(&param, "uci")) {
			uci_send(uci, "id name %s %s", NAME, VERSION);
			uci_send(uci, "id author %s", AUTHOR);
			uci_send(uci, "option name Hash type spin min %d default %d max %d", HASHSIZE_MIN, hash_size, HASHSIZE_MAX);
			uci_send(uci, "option name Ponder type check default false");
			uci_send(uci, "uciok");

		// ucinewgame
		if (parse_command(&param, "ucinewgame")) {
			uci_new_game(uci);

		// debug mode
		} else if (parse_command(&param,"debug")) {
			uci_debug(uci);

		// isready
		} else if (parse_command(&param,"isready")) {
			uci_send(uci, "readyok");

		// setoption
		} else if (parse_command(&param,"setoption")) {
			uci_set_option(uci, &param);
									 
		// position
		} else if (parse_command(&param,"position")) {
			uci_set_position(uci, &param);

		// go think!
		} else if (parse_command(&param,"go")) {
			uci_go(uci, &param);

		// stop
		} else if (parse_command(&param,"stop")) {
			uci_stop(uci);

		// ponderhit
		} else if (parse_command(&param,"ponderhit")) {
			uci_ponderhit(uci);

		// quit
		} else if (parse_command(&param,"quit")) {
			break;

		}
			
		free(line);
	}

	uci_free(uci);

	return 0;
}
I will study this. Thanks!
Mike Sherwin
Posts: 860
Joined: Fri Aug 21, 2020 1:25 am
Location: Planet Earth, Sol system
Full name: Michael J Sherwin

Re: iPlayChess - A TalkChess Community Engine

Post by Mike Sherwin »

I hate having to repeat this every so often. I was born with a learning disability. I was also born with a hole in my heart that was unfixable back then. I was also not supposed to live. And then I was not to see my 40th birthday. I was not to play tennis, but I did. I even won a few matches! :D Then at 48 I wrote RomiChess. It was the culmination of a 20 year ordeal to overcome my short term memory deficiency.

The way my learning disability works is that some things that have lots of meaning I can remember quite well. So something like Kenny Rogers song, "you got to know when to hold them, know when to fold them, know when to walk away, know when to run. You never count your money while your setting at the table, there'll be time enough for counting, when the dealin's done" from memory. On the other hand I once tried to learn Dutch. I carried a sentence in Dutch around with me for a month. I read it every chance I got. The meanings of the words were on the back of the paper. But, without reading the paper I never had even the faintest recollection of any of the words or what they meant. Then I lost the paper and that experiment was over. Learning C well enough and being able to keep any of it in memory long enough is part of my ordeal. I still keep a C primer next to me and my notes. Almost everyday I write something like, for (i = 0, i < num, i++) {} and wonder why it does not work.

So,
I can't learn another computer language.
C++ is way to complex.
As simple as UCI might be to everyone else it is a supreme challenge for me.
It took me three days to get minimal xboard working in Bric even though I had done it before and had my source code to study.
When I lose focus I forget what I was doing or why.
When I wake up the next day the day before is mostly gone.

I exist in a very small box that I can't easily or at all go beyond. I do my best with what I have. I can't play in anyone else's sandbox. So I can't learn D or change my style or do anything that others say I should do.

No need to comment on any of this. I'm not looking for sympathy. I just want to write Andromeda in C and hope that some other authors might like to be part of what I am trying to do. 8-)
Mike Sherwin
Posts: 860
Joined: Fri Aug 21, 2020 1:25 am
Location: Planet Earth, Sol system
Full name: Michael J Sherwin

Re: iPlayChess - A TalkChess Community Engine

Post by Mike Sherwin »

I'm a bit upset right now. Maybe I'll program after I go get some happy food. On that note I hit a new low ... in my dieting to lose weight. I am down to 208 lbs today! :D After every 5 lbs I lose I allow myself to order a pizza. :D :D That usually puts 3 lbs back on so losing 5 lbs is more like losing 8 lbs. :( :(

Okay so a little theory on going fast in a chess engine. Somewhere between 80 and 90 percent of all nodes are Q-nodes. In Make_Move() that means that between 80 and 90 percent are capture moves. If plenty of "if" statements are used in Make_Move() then a super fast engine is not going to happen. That is why there is not a single "if" statement in Make_Move() and there is only one switch statement. Consider the white e.p. code in Make_Move.

Code: Select all

case We:
      sq = m->ts - ((epbb[ply] == (one << m->ts)) << 3);
      ctype = board[sq];
      mat[BLACK] -= value[ctype];
      pos[WHITE] += (wpPST[m->ts] - wpPST[m->fs]);
      pos[BLACK] -= pcePST[ctype][m->ts];
      piece[BLACK] ^= (u64)(ctype != OO) << sq;
      board[sq] = OO;
      board[m->ts] = WP;
      break;
It is its own type of magic, especially that first line. At this point we do not know if this is an e.p. capture. All we know is that it is a white pawn on the 5th rank. Even after sq is computed it is still not known if we have an e.p. capture. Either 8 or 0 has been subtracted from the to square but it is not known which. But only the type, piece or empty square, is loaded into ctype but it is not known which. However, if it is a Q-node it is a capture and the value of ctype is subtracted from blacks material without ever knowing it is a capture. And the same with the PST. And the bit for the black piece on the board is xored out even though we still do not know if there was a black piece on the to square.

So all the complexity of the white pawn on the fifth is handled correctly without ever "knowing" anything except that the move was generated. And not knowing anything is fast! :)
Mike Sherwin
Posts: 860
Joined: Fri Aug 21, 2020 1:25 am
Location: Planet Earth, Sol system
Full name: Michael J Sherwin

Re: iPlayChess - A TalkChess Community Engine

Post by Mike Sherwin »

mvanthoor wrote: Thu Mar 25, 2021 5:21 pm
Mike Sherwin wrote: Thu Mar 25, 2021 5:08 pm Bricabrac has a bizarre bug that I have not been able to squish. When a side is losing that side's king heads for a1 and when it gets there it commits suicide by capturing itself.
You could try to debug that by logging each evaluation and king move pair to a file. Then you may be able to see a pattern.

What I could think of is something like an "off by one": if you use a 0-63 array, and you happen to subtract 1 from the square where the king is now, if the evaluation is negative (but not subtract 1 if the square is already 0), then your king would move to the left all the time until it reaches A1, and then the next move would be a1a1.

My best move starts out initialized at 0, so if the iterative deepening thread ends up without a move (which should never happen, because it completes at least one iteration), it would send "000000" to the main thread, which would parse this as a1 to a1 promotion to K (move a1a1k).
I found and killed the Bug! :D :D :D
It was in AtkByWhite() and AtkByBlack() functions. Now I can start making progress again :!:
https://www.youtube.com/watch?v=gqsT4xnKZPg
User avatar
mvanthoor
Posts: 1784
Joined: Wed Jul 03, 2019 4:42 pm
Location: Netherlands
Full name: Marcel Vanthoor

Re: iPlayChess - A TalkChess Community Engine

Post by mvanthoor »

Mike Sherwin wrote: Thu Apr 15, 2021 10:49 pm I found and killed the Bug! :D :D :D
It was in AtkByWhite() and AtkByBlack() functions. Now I can start making progress again :!:
https://www.youtube.com/watch?v=gqsT4xnKZPg
Nice :) What was it doing that it shouldn't be doing?
Author of Rustic, an engine written in Rust.
Releases | Code | Docs | Progress | CCRL
Mike Sherwin
Posts: 860
Joined: Fri Aug 21, 2020 1:25 am
Location: Planet Earth, Sol system
Full name: Michael J Sherwin

Re: iPlayChess - A TalkChess Community Engine

Post by Mike Sherwin »

mvanthoor wrote: Fri Apr 16, 2021 12:09 am
Mike Sherwin wrote: Thu Apr 15, 2021 10:49 pm I found and killed the Bug! :D :D :D
It was in AtkByWhite() and AtkByBlack() functions. Now I can start making progress again :!:
https://www.youtube.com/watch?v=gqsT4xnKZPg
Nice :) What was it doing that it shouldn't be doing?
In the sliders code it had a fs where it should have had a ts.