// File: 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
subq $0xe0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xc0(%rbp)
movl $0x0, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
movb 0x10(%rax), %cl
andb $0x1, %cl
movb %cl, -0x19(%rbp)
testb $0x1, 0x10(%rax)
je 0x81df
movq -0xc0(%rbp), %rax
addq $0x48, %rax
movq %rax, -0xc8(%rbp)
jmp 0x81f1
movq -0xc0(%rbp), %rax
addq $0x18, %rax
movq %rax, -0xc8(%rbp)
movq -0xc8(%rbp), %rax
movq %rax, -0x28(%rbp)
leaq -0x14(%rbp), %rax
movq %rax, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
cmpl $0x2, -0x34(%rbp)
jge 0x8465
movl $0x0, -0x38(%rbp)
cmpl $0x6, -0x38(%rbp)
jge 0x8405
movq -0x10(%rbp), %rdi
movzbl -0x19(%rbp), %esi
andl $0x1, %esi
leaq -0x38(%rbp), %rdx
callq 0xb860
movl %edx, -0x50(%rbp)
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x44(%rbp)
movl -0x50(%rbp), %eax
movl %eax, -0x3c(%rbp)
testb $0x1, -0x43(%rbp)
je 0x8286
leaq -0x60(%rbp), %rdi
callq 0x4c60
movl -0x40(%rbp), %eax
movl %eax, -0x60(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0x5c(%rbp)
movq -0x28(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x8c30
movl (%rax), %ecx
movq -0x30(%rbp), %rax
addl (%rax), %ecx
movl %ecx, (%rax)
jmp 0x83f5
movl $0x0, -0x64(%rbp)
movl $0x0, -0x68(%rbp)
movl -0x38(%rbp), %eax
movl %eax, -0x6c(%rbp)
cmpl $0x0, -0x6c(%rbp)
jle 0x8317
movq -0x10(%rbp), %rdi
movzbl -0x19(%rbp), %esi
andl $0x1, %esi
leaq -0x6c(%rbp), %rdx
callq 0xb860
movl %edx, -0x80(%rbp)
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rax
movq %rax, -0x78(%rbp)
movl -0x80(%rbp), %eax
movl %eax, -0x70(%rbp)
testb $0x1, -0x77(%rbp)
je 0x830a
leaq -0x90(%rbp), %rdi
callq 0x4c60
movl -0x74(%rbp), %eax
movl %eax, -0x90(%rbp)
movl -0x70(%rbp), %eax
movl %eax, -0x8c(%rbp)
movq -0x28(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x8c30
movl (%rax), %eax
movl %eax, -0x64(%rbp)
jmp 0x8317
jmp 0x830c
movl -0x6c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x6c(%rbp)
jmp 0x829a
movl -0x38(%rbp), %eax
movl %eax, -0x94(%rbp)
cmpl $0x6, -0x94(%rbp)
jge 0x83c5
movq -0x10(%rbp), %rdi
movzbl -0x19(%rbp), %esi
andl $0x1, %esi
leaq -0x94(%rbp), %rdx
callq 0xb860
movl %edx, -0xa8(%rbp)
movq %rax, -0xb0(%rbp)
movq -0xb0(%rbp), %rax
movq %rax, -0xa0(%rbp)
movl -0xa8(%rbp), %eax
movl %eax, -0x98(%rbp)
testb $0x1, -0x9f(%rbp)
je 0x83af
leaq -0xb8(%rbp), %rdi
callq 0x4c60
movl -0x9c(%rbp), %eax
movl %eax, -0xb8(%rbp)
movl -0x98(%rbp), %eax
movl %eax, -0xb4(%rbp)
movq -0x28(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x8c30
movl (%rax), %eax
movl %eax, -0x68(%rbp)
jmp 0x83c5
jmp 0x83b1
movl -0x94(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x94(%rbp)
jmp 0x8320
movl -0x64(%rbp), %eax
cmpl -0x68(%rbp), %eax
jle 0x83d8
movl -0x64(%rbp), %eax
movl %eax, -0xcc(%rbp)
jmp 0x83e1
movl -0x68(%rbp), %eax
movl %eax, -0xcc(%rbp)
movl -0xcc(%rbp), %eax
movl %eax, -0x64(%rbp)
movl -0x64(%rbp), %ecx
movq -0x30(%rbp), %rax
addl (%rax), %ecx
movl %ecx, (%rax)
jmp 0x83f7
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x821c
movq -0xc0(%rbp), %rax
movb 0x10(%rax), %cl
xorb $-0x1, %cl
andb $0x1, %cl
movb %cl, -0x19(%rbp)
testb $0x1, 0x10(%rax)
je 0x8432
movq -0xc0(%rbp), %rax
addq $0x18, %rax
movq %rax, -0xd8(%rbp)
jmp 0x8444
movq -0xc0(%rbp), %rax
addq $0x48, %rax
movq %rax, -0xd8(%rbp)
movq -0xd8(%rbp), %rax
movq %rax, -0x28(%rbp)
leaq -0x18(%rbp), %rax
movq %rax, -0x30(%rbp)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x820b
movl -0x14(%rbp), %eax
cvtsi2sdl -0x18(%rbp), %xmm0
movsd 0x5363(%rip), %xmm1     # 0xd7d8
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %ecx
subl %ecx, %eax
addq $0xe0, %rsp
popq %rbp
retq
nopl (%rax,%rax)