JanEric1
JanEric1
MModular
Created by JanEric1 on 11/10/2024 in #questions
Compile time facilities
Ok, so there are no other compile time facilities that would allow me to do even more here?
10 replies
MModular
Created by JanEric1 on 11/10/2024 in #questions
Compile time facilities
(and here is the full current code):
fn _is_winner_param[size: Int, //, player: UInt8](board: BOARD[size*size]) -> Bool:

var reference: SIMD[DType.uint8, board.size]
@parameter
for row in range(size):
reference = SIMD[DType.uint8, board.size](0)
@parameter
for col in range(size):
reference[row * size + col] = player
if (board & reference).reduce_bit_count() == size:
return True

# Check columns
@parameter
for col in range(size):
reference = SIMD[DType.uint8, board.size](0)
@parameter
for row in range(size):
reference[row * size + col] = player
if (board & reference).reduce_bit_count() == size:
return True

# Check main diagonal
reference = SIMD[DType.uint8, board.size](0)
@parameter
for i in range(size):
reference[i * size + i] = player
if (board & reference).reduce_bit_count() == size:
return True

# Check anti-diagonal
reference = SIMD[DType.uint8, board.size](0)
@parameter
for i in range(size):
reference[i * size + (size - 1 - i)] = player
if (board & reference).reduce_bit_count() == size:
return True
return False
fn _is_winner_param[size: Int, //, player: UInt8](board: BOARD[size*size]) -> Bool:

var reference: SIMD[DType.uint8, board.size]
@parameter
for row in range(size):
reference = SIMD[DType.uint8, board.size](0)
@parameter
for col in range(size):
reference[row * size + col] = player
if (board & reference).reduce_bit_count() == size:
return True

# Check columns
@parameter
for col in range(size):
reference = SIMD[DType.uint8, board.size](0)
@parameter
for row in range(size):
reference[row * size + col] = player
if (board & reference).reduce_bit_count() == size:
return True

# Check main diagonal
reference = SIMD[DType.uint8, board.size](0)
@parameter
for i in range(size):
reference[i * size + i] = player
if (board & reference).reduce_bit_count() == size:
return True

# Check anti-diagonal
reference = SIMD[DType.uint8, board.size](0)
@parameter
for i in range(size):
reference[i * size + (size - 1 - i)] = player
if (board & reference).reduce_bit_count() == size:
return True
return False
10 replies
MModular
Created by JanEric1 on 11/10/2024 in #questions
Compile time facilities
So what i have above should be functionally equivalent to the start of this for size = 3: and player=1
# Columns
if (board & (1, 0, 0, 1, 0, 0, 1, 0, 0)).reduce_bit_count() == 3:
return True
if (board & (0, 1, 0, 0, 1, 0, 0, 1, 0)).reduce_bit_count() == 3:
return True
if (board & (0, 0, 1, 0, 0, 1, 0, 0, 1)).reduce_bit_count() == 3:
return True
if (board & (1, 1, 1, 0, 0, 0, 0, 0, 0)).reduce_bit_count() == 3:
return True
if (board & (0, 0, 0, 1, 1, 1, 0, 0, 0)).reduce_bit_count() == 3:
return True
if (board & (0, 0, 0, 0, 0, 0, 1, 1, 1)).reduce_bit_count() == 3:
return True
if (board & (1, 0, 0, 0, 1, 0, 0, 0, 1)).reduce_bit_count() == 3:
return True
if (board & (0, 0, 1, 0, 1, 0, 1, 0, 0)).reduce_bit_count() == 3:
return True
return False
# Columns
if (board & (1, 0, 0, 1, 0, 0, 1, 0, 0)).reduce_bit_count() == 3:
return True
if (board & (0, 1, 0, 0, 1, 0, 0, 1, 0)).reduce_bit_count() == 3:
return True
if (board & (0, 0, 1, 0, 0, 1, 0, 0, 1)).reduce_bit_count() == 3:
return True
if (board & (1, 1, 1, 0, 0, 0, 0, 0, 0)).reduce_bit_count() == 3:
return True
if (board & (0, 0, 0, 1, 1, 1, 0, 0, 0)).reduce_bit_count() == 3:
return True
if (board & (0, 0, 0, 0, 0, 0, 1, 1, 1)).reduce_bit_count() == 3:
return True
if (board & (1, 0, 0, 0, 1, 0, 0, 0, 1)).reduce_bit_count() == 3:
return True
if (board & (0, 0, 1, 0, 1, 0, 1, 0, 0)).reduce_bit_count() == 3:
return True
return False
I just dont know how to best generate these at compile time.
10 replies
MModular
Created by JanEric1 on 11/7/2024 in #questions
Most efficient way to check for tictactoe board win
Does anyone have ideas how I can improve this and ensure as much as possible happens at compile time?
7 replies
MModular
Created by JanEric1 on 11/7/2024 in #questions
Most efficient way to check for tictactoe board win
Thinking something like this:
var reference: SIMD[DType.uint8, board.size]
@parameter
for row in range(size):
reference = SIMD[DType.uint8, board.size](0)
@parameter
for col in range(size):
reference[row * size + col] = player
if (board & reference).reduce_bit_count() == size:
return True
var reference: SIMD[DType.uint8, board.size]
@parameter
for row in range(size):
reference = SIMD[DType.uint8, board.size](0)
@parameter
for col in range(size):
reference[row * size + col] = player
if (board & reference).reduce_bit_count() == size:
return True
But i dont know if that actually does everything i want at compile time or if i need other facilities
7 replies
MModular
Created by JanEric1 on 11/7/2024 in #questions
Most efficient way to check for tictactoe board win
This is the signature i am thinking of:
fn _is_winner[size: Int, //, player: UInt8](board: BOARD[size*size]) -> Bool:
fn _is_winner[size: Int, //, player: UInt8](board: BOARD[size*size]) -> Bool:
So it should be doable at compile time, but i am just not sure how to go about it exactly.
7 replies