// File: 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:
subq $0x88, %rsp
movq %rdi, 0x80(%rsp)
movq %rsi, 0x78(%rsp)
movq %rdx, 0x70(%rsp)
movq %rcx, 0x68(%rsp)
movq 0x80(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x40(%rax), %rax
cmpl $0x0, 0xb4(%rax)
je 0x2864b
movq 0x78(%rsp), %rdi
movq 0x70(%rsp), %rsi
addq $0x24, %rsi
movq 0x68(%rsp), %rdx
addq $0x24, %rdx
callq 0x298a0
movl %eax, 0x64(%rsp)
cmpl $0x4, 0x64(%rsp)
jge 0x28649
movq 0x28(%rsp), %rax
movq 0x40(%rax), %rax
movl 0xb4(%rax), %edx
movl $0x4, %eax
subl 0x64(%rsp), %eax
imull %eax, %edx
movq 0x68(%rsp), %rax
movswl 0x20(%rax), %ecx
addl %edx, %ecx
movw %cx, 0x20(%rax)
jmp 0x2864b
movq 0x28(%rsp), %rax
movq 0x40(%rax), %rax
cmpl $0x0, 0xb8(%rax)
je 0x286c0
movq 0x28(%rsp), %rax
movq 0x40(%rax), %rax
movl 0xb8(%rax), %eax
movl %eax, 0x24(%rsp)
movq 0x78(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x68(%rsp), %rax
addq $0x24, %rax
movq %rax, 0x18(%rsp)
movq 0x78(%rsp), %rdi
callq 0x1a8a0
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
movb %al, 0x63(%rsp)
movzbl 0x63(%rsp), %edx
callq 0x29920
movl 0x24(%rsp), %edx
imull %eax, %edx
movq 0x68(%rsp), %rax
movswl 0x20(%rax), %ecx
addl %edx, %ecx
movw %cx, 0x20(%rax)
leaq 0x50(%rsp), %rdi
callq 0x10fb0
movq 0x28(%rsp), %rax
movq 0x40(%rax), %rax
cmpl $0x0, 0xbc(%rax)
jne 0x286ee
movq 0x28(%rsp), %rax
movq 0x40(%rax), %rax
cmpl $0x0, 0xc0(%rax)
je 0x2871f
movq 0x78(%rsp), %rdi
movq 0x68(%rsp), %rsi
addq $0x24, %rsi
callq 0x29970
movq %rax, 0x40(%rsp)
movq %rdx, 0x48(%rsp)
movq 0x40(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0x48(%rsp), %rax
movq %rax, 0x58(%rsp)
movq 0x28(%rsp), %rax
movq 0x40(%rax), %rax
cmpl $0x0, 0xc0(%rax)
je 0x28757
movq 0x28(%rsp), %rax
movq 0x40(%rax), %rax
movl 0xc0(%rax), %edx
movzwl 0x52(%rsp), %eax
imull %eax, %edx
movq 0x68(%rsp), %rax
movswl 0x20(%rax), %ecx
addl %edx, %ecx
movw %cx, 0x20(%rax)
movq 0x28(%rsp), %rax
movq 0x40(%rax), %rax
cmpl $0x0, 0xc4(%rax)
je 0x287ae
movq 0x28(%rsp), %rdi
movq 0x78(%rsp), %rsi
movq 0x70(%rsp), %rdx
addq $0x24, %rdx
movq 0x68(%rsp), %rcx
addq $0x24, %rcx
callq 0x28980
testb $0x1, %al
jne 0x28790
jmp 0x287ae
movq 0x28(%rsp), %rax
movq 0x40(%rax), %rax
movl 0xc4(%rax), %edx
movq 0x68(%rsp), %rax
movswl 0x20(%rax), %ecx
addl %edx, %ecx
movw %cx, 0x20(%rax)
movq 0x28(%rsp), %rax
movq 0x40(%rax), %rax
cmpl $0x0, 0xc8(%rax)
je 0x28868
movq 0x28(%rsp), %rax
movq 0x40(%rax), %rax
movl 0xc8(%rax), %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
movl %eax, 0xc(%rsp)
movl $0x0, 0x3c(%rsp)
movq 0x78(%rsp), %rdi
callq 0x1fe80
movl %eax, %ecx
movq 0x28(%rsp), %rax
movl %ecx, 0x8(%rsp)
addq $0x2f18, %rax           # imm = 0x2F18
movq %rax, (%rsp)
movq 0x68(%rsp), %rax
movw 0x24(%rax), %ax
movw %ax, 0x36(%rsp)
movq 0x78(%rsp), %rdi
callq 0x1a8a0
movq (%rsp), %rdi
movb %al, 0x35(%rsp)
movw 0x36(%rsp), %ax
movzwl %ax, %esi
movzbl 0x35(%rsp), %edx
callq 0x29b40
movl %eax, %ecx
movl 0x8(%rsp), %eax
subl %ecx, %eax
movl %eax, 0x38(%rsp)
leaq 0x3c(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0x29b00
movl 0xc(%rsp), %edx
imull (%rax), %edx
movq 0x68(%rsp), %rax
movswl 0x20(%rax), %ecx
addl %edx, %ecx
movw %cx, 0x20(%rax)
addq $0x88, %rsp
retq