// File: /workspace/github_cpp_makefile_star2_O3/tewalds[P]morat/havannah/agentmctsthread.cpp
// Function: Morat::Havannah::AgentMCTS::AgentThread::add_knowledge(Morat::Havannah::Board const&, Morat::Havannah::AgentMCTS::Node*, Morat::Havannah::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/corners
		child->know += agent->connect * (cell.numcorners() + 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 0x110(%r13), %eax
testl %eax, %eax
je 0x17949
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, %edx
subl %r9d, %r8d
andl %esi, %edi
movl %r8d, %r10d
negl %r10d
cmovsl %r8d, %r10d
subl %edx, %ecx
andl %esi, %r10d
addl %r9d, %ecx
addl %edi, %r10d
movl %ecx, %edx
negl %edx
cmovsl %ecx, %edx
addl %r10d, %edx
cmpl $0x7, %edx
ja 0x17949
shrl %edx
movl $0x4, %ecx
subl %edx, %ecx
imull %eax, %ecx
addw %cx, 0x20(%rbx)
movl 0x114(%r13), %ebp
testl %ebp, %ebp
je 0x1797d
movsbl 0x24(%rbx), %eax
movsbl (%r15), %ecx
movsbl 0x25(%rbx), %esi
movzbl 0xa(%r15), %edx
movq %r15, %rdi
imull %eax, %ecx
addl %ecx, %esi
callq 0x18ce8
imull %ebp, %eax
addw %ax, 0x20(%rbx)
movq 0x40(%r14), %r13
cmpl $0x0, 0x118(%r13)
jne 0x17991
cmpl $0x0, 0x11c(%r13)
je 0x179dd
leaq 0x24(%rbx), %rsi
movq %r15, %rdi
callq 0x18384
movq 0x40(%r14), %r13
movzbl %ah, %ecx
movl 0x118(%r13), %edx
testl %edx, %edx
je 0x179df
movl $0x828, %esi            # imm = 0x828
movl $0x820, %edi            # imm = 0x820
bextrq %rsi, %rax, %rsi
bextrq %rdi, %rax, %rax
leaq 0x1e0a6(%rip), %rdi     # 0x35a70
movzbl (%rax,%rdi), %eax
movzbl (%rsi,%rdi), %esi
addl %eax, %esi
imull %edx, %esi
addw %si, 0x20(%rbx)
jmp 0x179df
xorl %ecx, %ecx
movl 0x11c(%r13), %eax
testl %eax, %eax
je 0x179f1
imull %ecx, %eax
addw %ax, 0x20(%rbx)
movl 0x120(%r13), %ebp
testl %ebp, %ebp
je 0x17a17
addq $0x24, %r12
leaq 0x24(%rbx), %rcx
movq %r15, %rsi
movq %r12, %rdx
callq 0x17a82
testb %al, %al
je 0x17a17
addw %bp, 0x20(%rbx)
movl 0x124(%r13), %eax
testl %eax, %eax
je 0x17a72
movq 0xf410(%r14), %rdx
movl %eax, %ebp
negl %ebp
movsbl (%r15), %r12d
cmovsl %eax, %ebp
movzwl 0x24(%rbx), %eax
addq $0x28e8, %r14           # imm = 0x28E8
movq %r14, %rdi
movsbl (%rdx), %edx
movsbl %al, %ecx
shrl $0x8, %eax
movsbl %al, %esi
imull %ecx, %edx
addl %edx, %esi
movzbl 0xa(%r15), %edx
callq 0x18b84
subl %eax, %r12d
movl %r12d, %eax
sarl $0x1f, %eax
andnl %r12d, %eax, %eax
imull %ebp, %eax
addw %ax, 0x20(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop