// File: /workspace/github_cpp_makefile_star2_O3/tewalds[P]morat/hex/agentmctsthread.cpp
// Function: Morat::Hex::AgentMCTS::AgentThread::add_knowledge(Morat::Hex::Board const&, Morat::Hex::AgentMCTS::Node*, Morat::Hex::AgentMCTS::Node*)
void AgentMCTS::AgentThread::add_knowledge(const Board & board, Node * node, Node * child){
	if(agent->localreply){ //boost for moves near the previous move
		int dist = board.dist(node->move, child->move);
		if(dist < 4)
			child->know += agent->localreply * (4 - dist);
	}

	if(agent->locality) //boost for moves near previous stones
		child->know += agent->locality * board.local(child->move, board.to_play());

	Board::Cell cell;
	if(agent->connect || agent->size)
		cell = board.test_cell(child->move);

//	if(agent->connect) //boost for moves that connect to edges
//		child->know += agent->connect * cell.numedges();

	if(agent->size) //boost for size of the group
		child->know += agent->size * cell.size;

	if(agent->bridge && test_bridge_probe(board, node->move, child->move)) //boost for maintaining a virtual connection
		child->know += agent->bridge;

	if(agent->dists)
		child->know += abs(agent->dists) * std::max(0, board.lines() - dists.get(child->move, board.to_play()));
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq 0x40(%rdi), %r13
movq %rcx, %rbx
movq %rdx, %r12
movq %rsi, %r15
movq %rdi, %r14
movl 0xb4(%r13), %eax
testl %eax, %eax
je 0x17477
movsbl 0x25(%r12), %ecx
movsbl 0x25(%rbx), %edx
movsbl 0x24(%r12), %r8d
movsbl 0x24(%rbx), %r9d
movl %ecx, %esi
subl %edx, %esi
movl %esi, %edi
negl %edi
cmovsl %esi, %edi
movl $0xff, %esi
addl %r8d, %ecx
subl %r9d, %r8d
andl %esi, %edi
movl %r8d, %r10d
negl %r10d
cmovsl %r8d, %r10d
addl %r9d, %edx
andl %esi, %r10d
subl %edx, %ecx
addl %edi, %r10d
movl %ecx, %edx
negl %edx
cmovsl %ecx, %edx
addl %r10d, %edx
cmpl $0x7, %edx
ja 0x17477
shrl %edx
movl $0x4, %ecx
subl %edx, %ecx
imull %eax, %ecx
addw %cx, 0x20(%rbx)
movl 0xb8(%r13), %ebp
testl %ebp, %ebp
je 0x174aa
movsbl 0x24(%rbx), %eax
movsbl (%r15), %ecx
movsbl 0x25(%rbx), %esi
movl 0x8(%r15), %edx
movq %r15, %rdi
imull %eax, %ecx
addl %ecx, %esi
callq 0x18390
imull %ebp, %eax
addw %ax, 0x20(%rbx)
movq 0x40(%r14), %r13
cmpl $0x0, 0xbc(%r13)
jne 0x174be
cmpl $0x0, 0xc0(%r13)
je 0x174e3
leaq 0x24(%rbx), %rsi
movq %r15, %rdi
callq 0x17cde
movq 0x40(%r14), %r13
movl 0xc0(%r13), %ecx
testl %ecx, %ecx
je 0x174e3
shrl $0x10, %eax
imull %ecx, %eax
addw %ax, 0x20(%rbx)
movl 0xc4(%r13), %ebp
testl %ebp, %ebp
je 0x17509
addq $0x24, %r12
leaq 0x24(%rbx), %rcx
movq %r15, %rsi
movq %r12, %rdx
callq 0x17580
testb %al, %al
je 0x17509
addw %bp, 0x20(%rbx)
movl 0xc8(%r13), %ecx
testl %ecx, %ecx
je 0x17571
movq 0xcb70(%r14), %r8
movzwl 0x24(%rbx), %edx
movsbq 0x8(%r15), %rsi
movl %ecx, %eax
negl %eax
cmovsl %ecx, %eax
movsbl (%r15), %ecx
movsbl (%r8), %r8d
movsbl %dl, %edi
shrl $0x8, %edx
imulq $0x9c4, %rsi, %rsi      # imm = 0x9C4
movsbl %dl, %edx
addq %r14, %rsi
imull %edi, %r8d
addl %r8d, %edx
movslq %edx, %rdx
movl 0x2554(%rsi,%rdx,4), %edi
addl 0x38dc(%rsi,%rdx,4), %edi
subl %edi, %ecx
movl %ecx, %edx
sarl $0x1f, %edx
andnl %ecx, %edx, %ecx
imull %eax, %ecx
addw %cx, 0x20(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq