Page 1 of 14

Simplifying code

Posted: Fri Apr 24, 2020 1:26 pm
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.

Re: Simplifying code

Posted: Fri Apr 24, 2020 1:37 pm
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.

Re: Simplifying code

Posted: Fri Apr 24, 2020 1:42 pm
by Henk
I don't want to create/maintain a stack. So I would choose copy/make

Re: Simplifying code

Posted: Fri Apr 24, 2020 2:39 pm
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.

Re: Simplifying code

Posted: Fri Apr 24, 2020 2:51 pm
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.

Re: Simplifying code

Posted: Fri Apr 24, 2020 2:54 pm
by Henk
Can't copy position efficiently. Too many bytes.

Re: Simplifying code

Posted: Fri Apr 24, 2020 3:03 pm
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.

Re: Simplifying code

Posted: Fri Apr 24, 2020 3:10 pm
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.

Re: Simplifying code

Posted: Fri Apr 24, 2020 3:40 pm
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.

Re: Simplifying code

Posted: Fri Apr 24, 2020 9:11 pm
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.