// File: 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:
subq $0x98, %rsp
movq %rdi, 0x90(%rsp)
movq %rsi, 0x88(%rsp)
movq %rdx, 0x80(%rsp)
movq %rcx, 0x78(%rsp)
movq 0x90(%rsp), %rax
movq %rax, 0x38(%rsp)
movq 0x40(%rax), %rax
cmpl $0x0, 0x110(%rax)
je 0x28f07
movq 0x88(%rsp), %rdi
movq 0x80(%rsp), %rsi
addq $0x24, %rsi
movq 0x78(%rsp), %rdx
addq $0x24, %rdx
callq 0x2a450
movl %eax, 0x74(%rsp)
cmpl $0x4, 0x74(%rsp)
jge 0x28f05
movq 0x38(%rsp), %rax
movq 0x40(%rax), %rax
movl 0x110(%rax), %edx
movl $0x4, %eax
subl 0x74(%rsp), %eax
imull %eax, %edx
movq 0x78(%rsp), %rax
movswl 0x20(%rax), %ecx
addl %edx, %ecx
movw %cx, 0x20(%rax)
jmp 0x28f07
movq 0x38(%rsp), %rax
movq 0x40(%rax), %rax
cmpl $0x0, 0x114(%rax)
je 0x28f82
movq 0x38(%rsp), %rax
movq 0x40(%rax), %rax
movl 0x114(%rax), %eax
movl %eax, 0x34(%rsp)
movq 0x88(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x78(%rsp), %rax
addq $0x24, %rax
movq %rax, 0x28(%rsp)
movq 0x88(%rsp), %rdi
callq 0x1aa40
movq 0x20(%rsp), %rdi
movq 0x28(%rsp), %rsi
movb %al, 0x73(%rsp)
movzbl 0x73(%rsp), %edx
callq 0x2a4d0
movl 0x34(%rsp), %edx
imull %eax, %edx
movq 0x78(%rsp), %rax
movswl 0x20(%rax), %ecx
addl %edx, %ecx
movw %cx, 0x20(%rax)
leaq 0x60(%rsp), %rdi
callq 0x11030
movq 0x38(%rsp), %rax
movq 0x40(%rax), %rax
cmpl $0x0, 0x118(%rax)
jne 0x28fb0
movq 0x38(%rsp), %rax
movq 0x40(%rax), %rax
cmpl $0x0, 0x11c(%rax)
je 0x28fe4
movq 0x88(%rsp), %rdi
movq 0x78(%rsp), %rsi
addq $0x24, %rsi
callq 0x2a520
movq %rax, 0x50(%rsp)
movq %rdx, 0x58(%rsp)
movq 0x50(%rsp), %rax
movq %rax, 0x60(%rsp)
movq 0x58(%rsp), %rax
movq %rax, 0x68(%rsp)
movq 0x38(%rsp), %rax
movq 0x40(%rax), %rax
cmpl $0x0, 0x118(%rax)
je 0x2903f
movq 0x38(%rsp), %rax
movq 0x40(%rax), %rax
movl 0x118(%rax), %eax
movl %eax, 0x18(%rsp)
leaq 0x60(%rsp), %rdi
callq 0x20180
movl %eax, 0x1c(%rsp)
leaq 0x60(%rsp), %rdi
callq 0x20130
movl 0x18(%rsp), %edx
movl %eax, %ecx
movl 0x1c(%rsp), %eax
addl %ecx, %eax
imull %eax, %edx
movq 0x78(%rsp), %rax
movswl 0x20(%rax), %ecx
addl %edx, %ecx
movw %cx, 0x20(%rax)
movq 0x38(%rsp), %rax
movq 0x40(%rax), %rax
cmpl $0x0, 0x11c(%rax)
je 0x29077
movq 0x38(%rsp), %rax
movq 0x40(%rax), %rax
movl 0x11c(%rax), %edx
movzbl 0x61(%rsp), %eax
imull %eax, %edx
movq 0x78(%rsp), %rax
movswl 0x20(%rax), %ecx
addl %edx, %ecx
movw %cx, 0x20(%rax)
movq 0x38(%rsp), %rax
movq 0x40(%rax), %rax
cmpl $0x0, 0x120(%rax)
je 0x290d4
movq 0x38(%rsp), %rdi
movq 0x88(%rsp), %rsi
movq 0x80(%rsp), %rdx
addq $0x24, %rdx
movq 0x78(%rsp), %rcx
addq $0x24, %rcx
callq 0x292b0
testb $0x1, %al
jne 0x290b6
jmp 0x290d4
movq 0x38(%rsp), %rax
movq 0x40(%rax), %rax
movl 0x120(%rax), %edx
movq 0x78(%rsp), %rax
movswl 0x20(%rax), %ecx
addl %edx, %ecx
movw %cx, 0x20(%rax)
movq 0x38(%rsp), %rax
movq 0x40(%rax), %rax
cmpl $0x0, 0x124(%rax)
je 0x29196
movq 0x38(%rsp), %rax
movq 0x40(%rax), %rax
movl 0x124(%rax), %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
movl %eax, 0x14(%rsp)
movl $0x0, 0x4c(%rsp)
movq 0x88(%rsp), %rdi
callq 0x20490
movl %eax, %ecx
movq 0x38(%rsp), %rax
movl %ecx, 0x10(%rsp)
addq $0x28e8, %rax           # imm = 0x28E8
movq %rax, 0x8(%rsp)
movq 0x78(%rsp), %rax
movw 0x24(%rax), %ax
movw %ax, 0x46(%rsp)
movq 0x88(%rsp), %rdi
callq 0x1aa40
movq 0x8(%rsp), %rdi
movb %al, 0x45(%rsp)
movw 0x46(%rsp), %ax
movzwl %ax, %esi
movzbl 0x45(%rsp), %edx
callq 0x2a700
movl %eax, %ecx
movl 0x10(%rsp), %eax
subl %ecx, %eax
movl %eax, 0x48(%rsp)
leaq 0x4c(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x2a6c0
movl 0x14(%rsp), %edx
imull (%rax), %edx
movq 0x78(%rsp), %rax
movswl 0x20(%rax), %ecx
addl %edx, %ecx
movw %cx, 0x20(%rax)
addq $0x98, %rsp
retq
nop