Advertisement
philRG

Bitboard UTTT - Principle

Apr 26th, 2021
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.60 KB | None | 0 0
  1. import random
  2.  
  3. a = 0b011111000
  4.  
  5. print(f'a : {bin(a)}')
  6.  
  7. a = 0b011111000
  8. t = [i for i in range(9) if a & 2**i]
  9.  
  10. player_pos = [8-i for i in range(9) if a & 2**i][::-1]   # [3, 4, 5, 6, 7, 8]
  11. available_pos = [8-i for i in range(9) if not a & 2**i][::-1]  # [0, 1, 2]
  12.  
  13. print(player_pos)
  14. print(available_pos)
  15.  
  16. move = random.choice(available_pos)
  17. b = a ^ 2**(8-move)
  18. print(f'move: {move} -> {bin(b)}')
  19.  
  20. player_pos = [8-i for i in range(9) if b & 2**i][::-1]   # [3, 4, 5, 6, 7, 8]
  21. available_pos = [8-i for i in range(9) if not b & 2**i][::-1]  # [0, 1, 2]
  22.  
  23. print(player_pos)
  24. print(available_pos)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement