// File: /workspace/github_cpp_makefile_star2_O1/tyhsu[P]Ewn/minimax.cpp
// Function: Minimax::evaluate_feature(Game&)
int Minimax::evaluate_feature(Game& cur_game)
{
	int ai_val = 0, opp_val = 0;
	bool cur_side = this->ai_side;
	Heuristic_map *feature_map = this->ai_side? &this->feature_map_B: &this->feature_map_A;
	int *val_ptr = &ai_val;

	for (int side=0; side<2; side++) {
		for (int chs_index = 0; chs_index < 6; chs_index++) {
			// calculate the score of the side
			Chess chs = cur_game.get_chs_list(cur_side, chs_index);
			if (chs.exist) {
				// [exist] chess calculating function.
				Pos temp;
				temp.first = chs.x;
				temp.second = chs.y;
				*val_ptr += (*feature_map)[temp];
			}
			else {
				// [non-exist] chess calculating function.
				// prev_chs_val: find closest, previous chess num's value.
				// next_chs_val: find closest, following chess num's value.
				int prev_chs_val = 0, next_chs_val = 0;
				// get small part of chess list.
				for (int prev_chs_index = chs_index; prev_chs_index > 0; prev_chs_index--) {
					Chess ctmp = cur_game.get_chs_list(cur_side, prev_chs_index);
					if (ctmp.exist) {
						Pos temp;
						temp.first = ctmp.x;
						temp.second = ctmp.y;
						prev_chs_val = (*feature_map)[temp];
						break;
					}
				}

				// get big part of chess list.
				for (int next_chs_index = chs_index; next_chs_index < 6; next_chs_index++) {
					Chess ctmp = cur_game.get_chs_list(cur_side, next_chs_index);
					if (ctmp.exist) {
						Pos temp;
						temp.first = ctmp.x;
						temp.second = ctmp.y;
						next_chs_val = (*feature_map)[temp];
						break;
					}
				}

				// select one.
				prev_chs_val = (prev_chs_val > next_chs_val ? prev_chs_val : next_chs_val);
				*val_ptr += prev_chs_val;
			}
		}

		// calculate the score of opponent's side
		cur_side = !this->ai_side;
		feature_map = this->ai_side? &this->feature_map_A: &this->feature_map_B;
		val_ptr = &opp_val;
	}

	return ai_val - (int)(opp_val*1.2);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
xorl %ecx, %ecx
leaq -0x4c(%rbp), %r12
movl %ecx, (%r12)
leaq -0x3c(%rbp), %rax
movl %ecx, (%rax)
movb 0x10(%rdi), %al
leaq 0x48(%rdi), %rdx
movq %rdi, -0x68(%rbp)
addq $0x18, %rdi
testb %al, %al
movq %rdi, -0x58(%rbp)
movq %rdx, -0x60(%rbp)
cmovneq %rdx, %rdi
movq %rdi, -0x48(%rbp)
movq %rsi, %r14
leaq -0x30(%rbp), %rbx
movq %rcx, -0x70(%rbp)
movl $0x0, -0x30(%rbp)
movzbl %al, %r15d
andl $0x1, %r15d
movq %r12, -0x78(%rbp)
movq %r14, %rdi
movl %r15d, %esi
movq %rbx, %rdx
callq 0x86fc
btl $0x8, %eax
jb 0x6fd2
movl -0x30(%rbp), %eax
movl %eax, -0x2c(%rbp)
xorl %r12d, %r12d
movl $0x0, %ebx
testl %eax, %eax
jle 0x6f62
xorl %ebx, %ebx
movq %r14, %rdi
movl %r15d, %esi
leaq -0x2c(%rbp), %rdx
callq 0x86fc
movq %rax, %r13
btl $0x8, %r13d
jae 0x6f4d
movq %r13, %rax
shrq $0x20, %rax
movl %eax, -0x38(%rbp)
movl %edx, -0x34(%rbp)
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x747a
movl (%rax), %ebx
btl $0x8, %r13d
jb 0x6f62
movl -0x2c(%rbp), %eax
leal -0x1(%rax), %ecx
movl %ecx, -0x2c(%rbp)
cmpl $0x1, %eax
jg 0x6f18
movl -0x30(%rbp), %eax
movl %eax, -0x2c(%rbp)
cmpl $0x5, %eax
jg 0x6fbb
xorl %r12d, %r12d
movq %r14, %rdi
movl %r15d, %esi
leaq -0x2c(%rbp), %rdx
callq 0x86fc
movq %rax, %r13
btl $0x8, %r13d
jae 0x6fa6
movq %r13, %rax
shrq $0x20, %rax
movl %eax, -0x38(%rbp)
movl %edx, -0x34(%rbp)
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x747a
movl (%rax), %r12d
btl $0x8, %r13d
jb 0x6fbb
movl -0x2c(%rbp), %eax
leal 0x1(%rax), %ecx
movl %ecx, -0x2c(%rbp)
cmpl $0x5, %eax
jl 0x6f70
cmpl %r12d, %ebx
cmovgl %ebx, %r12d
movq -0x78(%rbp), %rax
addl %r12d, (%rax)
movq %rax, %r12
leaq -0x30(%rbp), %rbx
jmp 0x6fef
shrq $0x20, %rax
movl %eax, -0x38(%rbp)
movl %edx, -0x34(%rbp)
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x747a
movl (%rax), %eax
addl %eax, (%r12)
movl -0x30(%rbp), %eax
leal 0x1(%rax), %ecx
movl %ecx, -0x30(%rbp)
cmpl $0x5, %eax
jl 0x6eec
movq -0x68(%rbp), %rax
movb 0x10(%rax), %cl
movl %ecx, %eax
xorb $0x1, %al
testb %cl, %cl
movq -0x60(%rbp), %rcx
cmovneq -0x58(%rbp), %rcx
movq %rcx, -0x48(%rbp)
movq -0x70(%rbp), %rdx
leal 0x1(%rdx), %ecx
leaq -0x3c(%rbp), %r12
testl %edx, %edx
je 0x6ed5
movl -0x4c(%rbp), %eax
cvtsi2sdl -0x3c(%rbp), %xmm0
mulsd 0x27aa(%rip), %xmm0     # 0x97e8
cvttsd2si %xmm0, %ecx
subl %ecx, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop