// File: tewalds[P]morat/pentago/board.h
// Function: Morat::Pentago::Board::move_rand(Morat::XORShift_uint64&)
bool move_rand(XORShift_uint64 & rand){
		//find an empty space, this should take log2(bits set) to converge, assuming a good and fast RNG
		uint64_t move = (~sides[0]) & 0xFFFFFFFFFULL; // bits set for all empty positions
		uint64_t mask;
		do {
			mask = rand();
			if((move & mask) > 0) // don't let it drop to no bits set
				move &= mask;
		} while(move & (move-1));
//		} while(bitcount(move) > 1); // if there's only one bit left, that's our move

		sides[to_play_.to_i()] |= move;

		uint64_t rotation = (mask >> 36); //mask is already a random number, so just re-use the unused high bits
		uint64_t direction = rotation & 0x4;
		uint64_t quadrant = rotation & 0x3;

		if (direction) {
			sides[1] = rotate_quad_ccw(sides[1], quadrant);
			sides[2] = rotate_quad_ccw(sides[2], quadrant);
		} else {
			sides[1] = rotate_quad_cw(sides[1], quadrant);
			sides[2] = rotate_quad_cw(sides[2], quadrant);
		}
		sides[0] = sides[1] | sides[2];

		num_moves_++;
		to_play_ = ~to_play_;
		outcome_ = Outcome::UNDEF;
		cached_score = default_score;
		cached_hash = 0;

		return true;
	}

// Assembly:
subq $0x58, %rsp
movq %rdi, 0x50(%rsp)
movq %rsi, 0x48(%rsp)
movq 0x50(%rsp), %rax
movq %rax, 0x10(%rsp)
movq (%rax), %rax
xorq $-0x1, %rax
movabsq $0xfffffffff, %rcx      # imm = 0xFFFFFFFFF
andq %rcx, %rax
movq %rax, 0x40(%rsp)
movq 0x48(%rsp), %rdi
callq 0x26a40
movq %rax, 0x38(%rsp)
movq 0x40(%rsp), %rax
andq 0x38(%rsp), %rax
cmpq $0x0, %rax
jbe 0x2675f
movq 0x38(%rsp), %rax
andq 0x40(%rsp), %rax
movq %rax, 0x40(%rsp)
jmp 0x26761
movq 0x40(%rsp), %rax
movq 0x40(%rsp), %rcx
subq $0x1, %rcx
andq %rcx, %rax
cmpq $0x0, %rax
jne 0x26731
movq 0x10(%rsp), %rdi
movq 0x40(%rsp), %rax
movq %rax, 0x8(%rsp)
addq $0x19, %rdi
callq 0x16220
movq 0x8(%rsp), %rdx
movb %al, %cl
movq 0x10(%rsp), %rax
movsbq %cl, %rcx
orq (%rax,%rcx,8), %rdx
movq %rdx, (%rax,%rcx,8)
movq 0x38(%rsp), %rax
shrq $0x24, %rax
movq %rax, 0x30(%rsp)
movq 0x30(%rsp), %rax
andq $0x4, %rax
movq %rax, 0x28(%rsp)
movq 0x30(%rsp), %rax
andq $0x3, %rax
movq %rax, 0x20(%rsp)
cmpq $0x0, 0x28(%rsp)
je 0x26819
movq 0x10(%rsp), %rax
movq 0x8(%rax), %rdi
movq 0x20(%rsp), %rax
movl %eax, %esi
callq 0x164f0
movq %rax, %rcx
movq 0x10(%rsp), %rax
movq %rcx, 0x8(%rax)
movq 0x10(%rax), %rdi
movq 0x20(%rsp), %rax
movl %eax, %esi
callq 0x164f0
movq %rax, %rcx
movq 0x10(%rsp), %rax
movq %rcx, 0x10(%rax)
jmp 0x26856
movq 0x10(%rsp), %rax
movq 0x8(%rax), %rdi
movq 0x20(%rsp), %rax
movl %eax, %esi
callq 0x16570
movq %rax, %rcx
movq 0x10(%rsp), %rax
movq %rcx, 0x8(%rax)
movq 0x10(%rax), %rdi
movq 0x20(%rsp), %rax
movl %eax, %esi
callq 0x16570
movq %rax, %rcx
movq 0x10(%rsp), %rax
movq %rcx, 0x10(%rax)
movq 0x10(%rsp), %rax
movq 0x8(%rax), %rcx
orq 0x10(%rax), %rcx
movq %rcx, (%rax)
movb 0x18(%rax), %cl
addb $0x1, %cl
movb %cl, 0x18(%rax)
movb 0x19(%rax), %al
movb %al, 0x1e(%rsp)
movzbl 0x1e(%rsp), %edi
callq 0x165d0
movb %al, %cl
movq 0x10(%rsp), %rax
movb %cl, 0x1f(%rsp)
movb 0x1f(%rsp), %cl
movb %cl, 0x19(%rax)
leaq 0x34f7e(%rip), %rcx     # 0x5b817
movb (%rcx), %cl
movb %cl, 0x1a(%rax)
movw $0xdead, 0x1c(%rax)     # imm = 0xDEAD
movq $0x0, 0x20(%rax)
movb $0x1, %al
andb $0x1, %al
addq $0x58, %rsp
retq
nopw %cs:(%rax,%rax)
nop