Simplifying code

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

Henk
Posts: 7216
Joined: Mon May 27, 2013 10:31 am

Simplifying code

Post by Henk »

Getting tired of detail. So I decided to simplify source code as much as possible.

What to think about this. Only have to make it work.

Code: Select all

var snapShot = position.CreateSnapshot(move);
move.Apply(position);

...
snapShot.Restore();
Of course it is not efficient.
abulmo2
Posts: 433
Joined: Fri Dec 16, 2016 11:04 am
Location: France
Full name: Richard Delorme

Re: Simplifying code

Post by abulmo2 »

Your code is too long.
The too simple ways to do/undo a move on a board during the search are:
copy make

Code: Select all

Position new_position = Position(old_position, move);
...
or make/restore:

Code: Select all

position.update(move);
...
position.restore();
The complexity is, of course, hidden inside the functions.
Richard Delorme
Henk
Posts: 7216
Joined: Mon May 27, 2013 10:31 am

Re: Simplifying code

Post by Henk »

I don't want to create/maintain a stack. So I would choose copy/make
JohnWoe
Posts: 491
Joined: Sat Mar 02, 2013 11:31 pm

Re: Simplifying code

Post by JohnWoe »

That's too much code.
I simply Board = moves + i; And nothing else. There is no simpler way to do it.
copy+make or what's the correct terminology.
Henk
Posts: 7216
Joined: Mon May 27, 2013 10:31 am

Re: Simplifying code

Post by Henk »

JohnWoe wrote: Fri Apr 24, 2020 2:39 pm That's too much code.
I simply Board = moves + i; And nothing else. There is no simpler way to do it.
copy+make or what's the correct terminology.
Don't understand. What is "+ i".
"ï" is next move? Then each time you need the current position you have to reconstruct it from the moves.
Too slow.
Last edited by Henk on Fri Apr 24, 2020 2:57 pm, edited 2 times in total.
Henk
Posts: 7216
Joined: Mon May 27, 2013 10:31 am

Re: Simplifying code

Post by Henk »

Can't copy position efficiently. Too many bytes.
JohnWoe
Posts: 491
Joined: Sat Mar 02, 2013 11:31 pm

Re: Simplifying code

Post by JohnWoe »

Henk wrote: Fri Apr 24, 2020 2:51 pm
JohnWoe wrote: Fri Apr 24, 2020 2:39 pm That's too much code.
I simply Board = moves + i; And nothing else. There is no simpler way to do it.
copy+make or what's the correct terminology.
Don't understand. What is "+ i".
"ï" is next move? Then each time you need the current position you have to reconstruct it from the moves.
Too slow.
It's a pointer to the global board. Board = moves + i
i = index -> in for loops.
Obviously my method only works on single threaded model. Slower method? Yes. But so simple. Bugs slow you down.

The thing is I don't need the current position ever. I just throw it away like trash.
Henk
Posts: 7216
Joined: Mon May 27, 2013 10:31 am

Re: Simplifying code

Post by Henk »

JohnWoe wrote: Fri Apr 24, 2020 3:03 pm
Henk wrote: Fri Apr 24, 2020 2:51 pm
JohnWoe wrote: Fri Apr 24, 2020 2:39 pm That's too much code.
I simply Board = moves + i; And nothing else. There is no simpler way to do it.
copy+make or what's the correct terminology.
Don't understand. What is "+ i".
"ï" is next move? Then each time you need the current position you have to reconstruct it from the moves.
Too slow.
It's a pointer to the global board. Board = moves + i
i = index -> in for loops.
Obviously my method only works on single threaded model. Slower method? Yes. But so simple. Bugs slow you down.

The thing is I don't need the current position ever. I just throw it away like trash.
Still don't understand. "i" is a pointer to the global board? And it iterates over global boards? Or where does it iterate over?
If it is a secret then never mind.

I also don't understand that you don't need the current position ever. O wait you create a new one each time.
JohnWoe
Posts: 491
Joined: Sat Mar 02, 2013 11:31 pm

Re: Simplifying code

Post by JohnWoe »

Henk wrote: Fri Apr 24, 2020 3:10 pm
JohnWoe wrote: Fri Apr 24, 2020 3:03 pm
Henk wrote: Fri Apr 24, 2020 2:51 pm
JohnWoe wrote: Fri Apr 24, 2020 2:39 pm That's too much code.
I simply Board = moves + i; And nothing else. There is no simpler way to do it.
copy+make or what's the correct terminology.
Don't understand. What is "+ i".
"ï" is next move? Then each time you need the current position you have to reconstruct it from the moves.
Too slow.
It's a pointer to the global board. Board = moves + i
i = index -> in for loops.
Obviously my method only works on single threaded model. Slower method? Yes. But so simple. Bugs slow you down.

The thing is I don't need the current position ever. I just throw it away like trash.
Still don't understand. "i" is a pointer to the global board? And it iterates over global boards? Or where does it iterate over?
If it is a secret then never mind.

I also don't understand that you don't need the current position ever. O wait you create a new one each time.
It's not a big secret. I have explained it many times here. It's pretty slow as you said(And single threaded). That of course depends on the point of view. I'm a game programmer not a chess programmer. So I only care about source code.

So I only have 1 global board. And moves are per function. Should probably call them boards. But they also contain move_from, move_to flags. So they are kinda moves and boards hybrids. So (moves + i) points to the board on the list.

I don't generate moves at all. I generate boards. So I don't have make() or unmake() stuff to worry about. The code that doesn't exist. Contains 0 bugs and is really fast.

I don't reuse that current position after done operations. Because in unmake() one needs lots of logic to update all bitboards, hashes and stuff that's really bug prone.
Henk
Posts: 7216
Joined: Mon May 27, 2013 10:31 am

Re: Simplifying code

Post by Henk »

Henk wrote: Fri Apr 24, 2020 2:54 pm Can't copy position efficiently. Too many bytes.
Maybe only 32 bytes needed. So maybe not that inefficient.
But too late I already implemented my snapshot solution.