Simplifying code

Discussion of chess software programming and technical issues.

Moderators: bob, hgm, Harvey Williamson

Forum rules
This textbox is used to restore diagrams posted with the [d] tag before the upgrade.
Henk
Posts: 6367
Joined: Mon May 27, 2013 8:31 am

Simplifying code

Post by Henk » Fri Apr 24, 2020 11:26 am

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: 254
Joined: Fri Dec 16, 2016 10:04 am
Contact:

Re: Simplifying code

Post by abulmo2 » Fri Apr 24, 2020 11:37 am

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: 6367
Joined: Mon May 27, 2013 8:31 am

Re: Simplifying code

Post by Henk » Fri Apr 24, 2020 11:42 am

I don't want to create/maintain a stack. So I would choose copy/make

JohnWoe
Posts: 183
Joined: Sat Mar 02, 2013 10:31 pm

Re: Simplifying code

Post by JohnWoe » Fri Apr 24, 2020 12: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.

Henk
Posts: 6367
Joined: Mon May 27, 2013 8:31 am

Re: Simplifying code

Post by Henk » Fri Apr 24, 2020 12:51 pm

JohnWoe wrote:
Fri Apr 24, 2020 12: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 12:57 pm, edited 2 times in total.

Henk
Posts: 6367
Joined: Mon May 27, 2013 8:31 am

Re: Simplifying code

Post by Henk » Fri Apr 24, 2020 12:54 pm

Can't copy position efficiently. Too many bytes.

JohnWoe
Posts: 183
Joined: Sat Mar 02, 2013 10:31 pm

Re: Simplifying code

Post by JohnWoe » Fri Apr 24, 2020 1:03 pm

Henk wrote:
Fri Apr 24, 2020 12:51 pm
JohnWoe wrote:
Fri Apr 24, 2020 12: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: 6367
Joined: Mon May 27, 2013 8:31 am

Re: Simplifying code

Post by Henk » Fri Apr 24, 2020 1:10 pm

JohnWoe wrote:
Fri Apr 24, 2020 1:03 pm
Henk wrote:
Fri Apr 24, 2020 12:51 pm
JohnWoe wrote:
Fri Apr 24, 2020 12: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: 183
Joined: Sat Mar 02, 2013 10:31 pm

Re: Simplifying code

Post by JohnWoe » Fri Apr 24, 2020 1:40 pm

Henk wrote:
Fri Apr 24, 2020 1:10 pm
JohnWoe wrote:
Fri Apr 24, 2020 1:03 pm
Henk wrote:
Fri Apr 24, 2020 12:51 pm
JohnWoe wrote:
Fri Apr 24, 2020 12: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: 6367
Joined: Mon May 27, 2013 8:31 am

Re: Simplifying code

Post by Henk » Fri Apr 24, 2020 7:11 pm

Henk wrote:
Fri Apr 24, 2020 12: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.

Post Reply