Skip to content

Instantly share code, notes, and snippets.

@grafi-tt
Last active June 29, 2019 03:58
Show Gist options
  • Save grafi-tt/8640721a6056ec6a54bdba679fd66012 to your computer and use it in GitHub Desktop.
Save grafi-tt/8640721a6056ec6a54bdba679fd66012 to your computer and use it in GitHub Desktop.
import numpy as np
def show_board(black_board, white_board):
black_bytes = black_board.to_bytes(8, byteorder='big')
black_array = np.unpackbits(np.frombuffer(black_bytes, dtype=np.uint8))
white_bytes = white_board.to_bytes(8, byteorder='big')
white_array = np.unpackbits(np.frombuffer(white_bytes, dtype=np.uint8))
chars = (black_array * (ord(b'b') - ord(b'-')) +
white_array * (ord(b'w') - ord(b'-')) +
ord(b'-'))
chars = np.pad(chars.reshape((8, 8)), ((0, 0), (0, 1)), 'constant',
constant_values=ord(b'\n'))
return bytes(chars).decode()
print(show_board(0x0000001008000000, 0x0000000810000000))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment