// File: /workspace/github_cpp_makefile_star2_O2/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 $0x48, %rsp
movq %rsi, %rbx
leaq -0x44(%rbp), %r13
andl $0x0, (%r13)
leaq -0x3c(%rbp), %rax
andl $0x0, (%rax)
movb 0x10(%rdi), %al
leaq 0x48(%rdi), %rcx
movq %rdi, -0x60(%rbp)
leaq 0x18(%rdi), %r14
testb %al, %al
movq %r14, -0x50(%rbp)
movq %rcx, -0x58(%rbp)
cmovneq %rcx, %r14
xorl %edx, %edx
leaq -0x2c(%rbp), %r12
cmpl $0x2, %edx
je 0x58c4
movl %edx, -0x40(%rbp)
xorl %ecx, %ecx
movzbl %al, %r15d
andl $0x1, %r15d
movq %r13, -0x68(%rbp)
movl %ecx, -0x30(%rbp)
cmpl $0x6, %ecx
jge 0x58a0
movq %rbx, %rdi
movl %r15d, %esi
leaq -0x30(%rbp), %rdx
callq 0x6d40
btl $0x8, %eax
jb 0x580d
movl -0x30(%rbp), %eax
movl %eax, -0x2c(%rbp)
testl %eax, %eax
jle 0x5827
movq %rbx, %rdi
movl %r15d, %esi
movq %r12, %rdx
callq 0x6d40
btl $0x8, %eax
jb 0x582c
movl -0x2c(%rbp), %eax
decl %eax
jmp 0x57eb
shrq $0x20, %rax
movl %eax, -0x38(%rbp)
movl %edx, -0x34(%rbp)
movq %r14, %rdi
leaq -0x38(%rbp), %rsi
callq 0x5cb0
movl (%rax), %eax
jmp 0x5892
xorl %r13d, %r13d
jmp 0x5845
shrq $0x20, %rax
movl %eax, -0x38(%rbp)
movl %edx, -0x34(%rbp)
movq %r14, %rdi
leaq -0x38(%rbp), %rsi
callq 0x5cb0
movl (%rax), %r13d
movl -0x30(%rbp), %eax
movl %eax, -0x2c(%rbp)
cmpl $0x5, %eax
jg 0x586b
movq %rbx, %rdi
movl %r15d, %esi
movq %r12, %rdx
callq 0x6d40
btl $0x8, %eax
jb 0x586f
movl -0x2c(%rbp), %eax
incl %eax
jmp 0x5848
xorl %eax, %eax
jmp 0x5887
shrq $0x20, %rax
movl %eax, -0x38(%rbp)
movl %edx, -0x34(%rbp)
movq %r14, %rdi
leaq -0x38(%rbp), %rsi
callq 0x5cb0
movl (%rax), %eax
cmpl %eax, %r13d
cmovgl %r13d, %eax
movq -0x68(%rbp), %r13
addl %eax, (%r13)
movl -0x30(%rbp), %ecx
incl %ecx
jmp 0x57c7
movq -0x60(%rbp), %rax
movb 0x10(%rax), %cl
movl %ecx, %eax
xorb $0x1, %al
testb %cl, %cl
movq -0x58(%rbp), %r14
cmovneq -0x50(%rbp), %r14
movl -0x40(%rbp), %edx
incl %edx
leaq -0x3c(%rbp), %r13
jmp 0x57ad
movl -0x44(%rbp), %eax
cvtsi2sdl -0x3c(%rbp), %xmm0
mulsd 0x2f14(%rip), %xmm0     # 0x87e8
cvttsd2si %xmm0, %ecx
subl %ecx, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop