Sub PawnMovements
If WhoMoves=1 Then 'Whites moves.
'Ahead 1:
BBTo=(((Pawns And Whites) And (Not Rank7)) Shl 8) And (Not Whites) And (Not Blacks)
If BBTo <>0 Then
Do
To=BSF(BBTo)
From=To-8
MovesList(Deep, Move, 1)=From
MovesList(Deep, Move, 2)=To
'MovesList(Deep, Move, 3)= Used for EnPassant
'MovesList(Deep, Move, 4)= Used for Promotions
'MovesList(Deep, Move, 5)= Used for MoveOrdering value
BBTo=BitReset(BBTo,BSF(BBto))
Move=Move+1
Loop Until BBTo=0
EndIf
....
Sub PawnMovements
If WhoMoves=1 Then 'Whites moves.
'Ahead 1:
BBTo=(((Pawns And Whites) And (Not Rank7)) Shl 8) And (Not Whites) And (Not Blacks)
If BBTo <>0 Then
Do
To=BSF(BBTo)
From=To-8
MovesList(Deep, Move, 1)=From
MovesList(Deep, Move, 2)=To
'MovesList(Deep, Move, 3)= Used for EnPassant
'MovesList(Deep, Move, 4)= Used for Promotions
'MovesList(Deep, Move, 5)= Used for MoveOrdering value
BBTo=BitReset(BBTo,BSF(BBto))
Move=Move+1
Loop Until BBTo=0
EndIf
....
1) I would put the colour as a parameter to the function, change whites to colour(1) and put black as colour(0). In that way you don’t need separate code for black and white.
2) I would replace the “if bbto <> 0” and “loop until bbto = 0” with a “while bbto <> 0”
Pio wrote: ↑Fri Apr 02, 2021 12:33 am
...
1) I would put the colour as a parameter to the function, change whites to colour(1) and put black as colour(0). In that way you don’t need separate code for black and white.
I thought in it.
The point is that I could add many variables to reduce the code lines. But this do not slow down the engine?
Pio wrote: ↑Fri Apr 02, 2021 12:33 am
...
2) I would replace the “if bbto <> 0” and “loop until bbto = 0” with a “while bbto <> 0”
Luis Babboni wrote: ↑Fri Apr 02, 2021 1:10 am
Thanks Pio!
Pio wrote: ↑Fri Apr 02, 2021 12:33 am
...
1) I would put the colour as a parameter to the function, change whites to colour(1) and put black as colour(0). In that way you don’t need separate code for black and white.
I thought in it.
The point is that I could add many variables to reduce the code lines. But this do not slow down the engine?
Pio wrote: ↑Fri Apr 02, 2021 12:33 am
...
2) I would replace the “if bbto <> 0” and “loop until bbto = 0” with a “while bbto <> 0”
I´ll take a look to this!
I do not think that will be the time critical part. If you want it faster you should not put the pawn moves in a separate routine since you could then put the whotomove condition before all the move generation instead of doing it multiple times. I really think you should simplify the code as much as possible and then do performance tuning, not the other way round. I actually think my way with parameter will be faster since it will remove a branch but someone like Gerd or HGM who knows much much more than me can probably answer that. Are you sure that the functions bsf and bitreset have been inlined by the clr if you are so concerned about speed? I could not see that you considered the double pawn push in the code.
Sven wrote: ↑Fri Apr 02, 2021 12:57 pm
I think the pawn move generation code indeed needs to be color-specific due to the shift left vs. shift right operations.
You are right. You would have to put in the operator in an array as well to make it work or do what I do and that is to rotate the entire board.