// File: /workspace/github_cpp_makefile_star2_O1/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 %rcx, %rbx
movq %rdx, %r12
movq %rsi, %r15
movq %rdi, %r14
movq 0x40(%rdi), %rax
movl 0xb4(%rax), %ecx
testl %ecx, %ecx
je 0x173de
movsbl 0x25(%r12), %edx
movsbl 0x25(%rbx), %esi
movl %edx, %edi
subl %esi, %edi
movl %edi, %r8d
negl %r8d
cmovsl %edi, %r8d
movl $0xff, %edi
andl %edi, %r8d
movsbl 0x24(%r12), %r9d
movsbl 0x24(%rbx), %r10d
addl %r9d, %edx
subl %r10d, %r9d
movl %r9d, %r11d
negl %r11d
cmovsl %r9d, %r11d
andl %edi, %r11d
addl %r8d, %r11d
addl %r10d, %esi
subl %esi, %edx
movl %edx, %esi
negl %esi
cmovsl %edx, %esi
addl %r11d, %esi
cmpl $0x7, %esi
ja 0x173de
shrl %esi
movl $0x4, %edx
subl %esi, %edx
imull %ecx, %edx
addw %dx, 0x20(%rbx)
movl 0xb8(%rax), %ebp
testl %ebp, %ebp
je 0x1740c
movsbl 0x24(%rbx), %eax
movsbl (%r15), %ecx
imull %eax, %ecx
movsbl 0x25(%rbx), %esi
addl %ecx, %esi
movl 0x8(%r15), %edx
movq %r15, %rdi
callq 0x1830e
imull %ebp, %eax
addw %ax, 0x20(%rbx)
movq 0x40(%r14), %rax
cmpl $0x0, 0xbc(%rax)
jne 0x17426
cmpl $0x0, 0xc0(%rax)
je 0x174e8
leaq 0x24(%rbx), %rsi
movq %r15, %rdi
callq 0x17c54
shrl $0x10, %eax
movq 0x40(%r14), %r13
movl 0xc0(%r13), %ecx
testl %ecx, %ecx
je 0x1744b
imull %ecx, %eax
addw %ax, 0x20(%rbx)
movl 0xc4(%r13), %ebp
testl %ebp, %ebp
je 0x17471
addq $0x24, %r12
leaq 0x24(%rbx), %rcx
movq %r15, %rsi
movq %r12, %rdx
callq 0x174f0
testb %al, %al
je 0x17471
addw %bp, 0x20(%rbx)
movl 0xc8(%r13), %ecx
testl %ecx, %ecx
je 0x174d9
movl %ecx, %eax
negl %eax
cmovsl %ecx, %eax
movsbl (%r15), %ecx
movzwl 0x24(%rbx), %edx
movsbq 0x8(%r15), %rsi
movsbl %dl, %edi
shrl $0x8, %edx
movq 0xcb70(%r14), %r8
movsbl (%r8), %r8d
imull %edi, %r8d
movsbl %dl, %edx
addl %r8d, %edx
movslq %edx, %rdx
imulq $0x9c4, %rsi, %rsi      # imm = 0x9C4
addq %r14, %rsi
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
xorl %eax, %eax
jmp 0x17435
nop