Code: Select all
U64 m = (wpawns & UINT64(0x00000000000000ff));
for(int i = 0;i < 7;i++)
m = (((m << 8) | ((m << 9) & UINT64(0x7f7f7f7f7f7f7f7f))) & wpawns);
if(m) wins++;
Please feel free to ask if anything is unclear.
Moderator: Ras
Code: Select all
U64 m = (wpawns & UINT64(0x00000000000000ff));
for(int i = 0;i < 7;i++)
m = (((m << 8) | ((m << 9) & UINT64(0x7f7f7f7f7f7f7f7f))) & wpawns);
if(m) wins++;
Code: Select all
+8 +9
-1 C +1
-7 -8
Code: Select all
r = m
//left shift
do {
t = (((r<<1) &~FILEA) & wpawns);
r |= t;
} while(t)
//and for the right
do {
t = (((r>>1) & ~FILEH) & wpawns);
r |= t;
} while(t)
Code: Select all
U64 m = (wpawns & UINT64(0x00000000000000ff));
for(;m;) {
m = ((m << 1) | (m >> 1) | (m << 8) | (m << 9)) & wpawns;
if(m & 0xff00000000000000) wins++;
}
I think I will using something like that once I correct the shifts ~FILEA and ~FILEH. I will just do it 7 times anyway since unrolled code is much better for the GPU.Another approach would be something like:
Code:
U64 m = (wpawns & UINT64(0x00000000000000ff));
for(;m;) {
m = ((m << 1) | (m >> 1) | (m << 8) | (m << 9)) & wpawns;
if(m & 0xff00000000000000) wins++;
}
Good point. Yes it can move backwards too so I guess I will have to add -7 and -8 to the mix.Furthermore you can get better parallelization by starting off from row 0 and row 7 simultaneously, because this reduces dependency.
I don't know hex enough, but wouldn't it be possible for a line not only to move sideways but also backwards?
Unrolling this one seems costly. It appears to me, the maximum number of steps is 30.Daniel Shawul wrote:Precomputed is a no no since I am doing it on GPU. Right now I am doing all the calculations on the register. I don't want to even use shared mem. I chose HEX 8x8 to use bitboards. makemove,move generation and everything is very easy and lightweight. It is about 100 lines of code total to do a montecarlo on the root board.
I think I will using something like that once I correct the shifts ~FILEA and ~FILEH. I will just do it 7 times anyway since unrolled code is much better for the GPU.Another approach would be something like:
Code:
U64 m = (wpawns & UINT64(0x00000000000000ff));
for(;m;) {
m = ((m << 1) | (m >> 1) | (m << 8) | (m << 9)) & wpawns;
if(m & 0xff00000000000000) wins++;
}
Good point. Yes it can move backwards too so I guess I will have to add -7 and -8 to the mix.Furthermore you can get better parallelization by starting off from row 0 and row 7 simultaneously, because this reduces dependency.
I don't know hex enough, but wouldn't it be possible for a line not only to move sideways but also backwards?
Yes that maybe the longest but I am not sure since the Hex board is difficult to visualize when deformed.Unrolling this one seems costly. It appears to me, the maximum number of steps is 30.
[d]P7/P2PPPPP/P1P4P/P1PPPP1P/P4P1P/P1PP1P1P/PP1PP2P/7P w - - 0 1
btw there is a mistake in my previous posted code. The way the loop is constructed one has to check for m != old m and not m != 0.
Code: Select all
U64 m = (wpawns & UINT64(0x00000000000000ff)),oldm;
print_bitboard(m);
do {
oldm = m;
m = (((m << 8) |
(((m << 9) | (m << 1)) & UINT64(0x7f7f7f7f7f7f7f7f)) |
((m >> 1) & UINT64(0xfefefefefefefefe)))
& wpawns);
print_bitboard(m);
if(m & UINT64(0xff00000000000000)) {
wins++;
break;
}
} while(m != oldm);
Code: Select all
0 1 1 1 0 0 1 1
0 0 1 1 0 0 1 1
0 0 0 0 0 1 0 1
1 0 0 1 1 0 1 0
1 1 1 1 1 0 0 0
1 1 0 0 0 0 0 1
1 1 0 1 0 0 1 1
1 1 0 0 0 1 0 1
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
1 1 0 0 0 1 0 1
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 1
1 1 0 0 0 0 1 1
0 1 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
1 1 0 0 0 0 0 1
1 1 0 0 0 0 1 0
1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
1 1 0 0 0 0 0 0
1 1 0 0 0 0 0 1
1 1 0 0 0 0 0 1
0 1 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0
1 1 1 0 0 0 0 0
1 1 0 0 0 0 0 1
1 1 0 0 0 0 1 0
1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 1 1
0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0
1 1 1 1 0 0 0 0
1 1 0 0 0 0 0 1
1 1 0 0 0 0 0 1
0 1 0 0 0 0 0 0
0 0 0 0 0 0 1 1
0 0 0 0 0 0 1 1
0 0 0 0 0 0 0 1
1 0 0 1 0 0 0 0
1 1 1 1 1 0 0 0
1 1 0 0 0 0 0 1
1 1 0 0 0 0 1 0
1 0 0 0 0 0 0 0
0 1 1 1 0 0 1 1
0 0 1 1 0 0 1 1
0 0 0 0 0 1 0 1
1 0 0 1 1 0 1 0
1 1 1 1 1 0 0 0
1 1 0 0 0 0 0 1
1 1 0 1 0 0 1 1
1 1 0 0 0 1 0 1
wins : 1
Press any key to continue . . .
Code: Select all
U64 m = (wpawns & UINT64(0x00000000000000ff)),oldm;
do {
oldm = m;
m =((((m << 8) | (m >> 8)) |
(((m << 9) | (m << 1)) & UINT64(0x7f7f7f7f7f7f7f7f)) |
(((m >> 7) | (m >> 1)) & UINT64(0xfefefefefefefefe)))
& wpawns);
if(m & UINT64(0xff00000000000000)) {
wins++;
break;
}
} while(m != oldm);
Code: Select all
1 0 0 0 0 0 0 0
1 0 0 1 1 1 1 1
1 0 1 0 0 0 0 1
1 0 1 1 1 1 0 1
1 0 0 0 0 1 0 1
1 0 1 1 0 1 0 1
1 1 0 0 1 0 0 1
0 0 0 0 0 0 0 1
0 0 0 0 0 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0 0 0
1 0 0 0 1 1 1 1
1 0 0 0 0 0 0 1
1 0 0 0 0 0 0 1
1 0 0 0 0 0 0 1
1 0 0 0 0 0 0 1
1 1 0 0 0 0 0 1
0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0
1 0 0 1 1 1 1 1
1 0 0 0 0 0 0 1
1 0 0 0 0 0 0 1
1 0 0 0 0 0 0 1
1 0 0 0 0 0 0 1
1 1 0 0 0 0 0 1
0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0
1 0 0 1 1 1 1 1
1 0 1 0 0 0 0 1
1 0 1 1 1 1 0 1
1 0 0 0 0 1 0 1
1 0 1 1 0 1 0 1
1 1 0 0 1 0 0 1
0 0 0 0 0 0 0 1
wins : 1
Press any key to continue . . .
Code: Select all
U64 m = (wpawns & UINT64(0x00000000000000ff)),oldm;
print_bitboard(m);
do {
oldm = m;
m = (((m << 8) |
(((m << 7) | (m >> 1)) & UINT64(0x7f7f7f7f7f7f7f7f)) |
((m << 1) & UINT64(0xfefefefefefefefe)))
& wpawns);
print_bitboard(m);
if(m & UINT64(0xff00000000000000)) {
wins++;
break;
}
} while(m != oldm);