// File: uclaopt[P]AsyncQVI/include/oracle.h
// Function: test_sailing(Sailing&, std::vector<int, std::allocator<int>>*, Params*)
void test_sailing(Sailing& s, std::vector<int>* pi, Params* params){
	
	double start_time = get_wall_time();
	s.setValues(params);
	// total discounted reward
	double total_reward = 0.;
	// how many times has the goal state been reached.
	int flag = 0;
	int isflag = 0;
	// run text_max_episode episodes
	for (int episode = 0; episode < params->test_max_episode; episode++){
		// start from an arbitrary state
		int i = uniformInt(0,params->len_state-1);
		int j = 0;
		double r = 0;
		isflag = 0;
		for (int step = 0; step < params->test_max_step; step++){
			s.SO(i,(*pi)[i],j,r);
			total_reward += pow(params->gamma,step)*r;
			if(r == 1 && !isflag){
				flag += 1;
				isflag = 1;
			}
			i = j;
		}
	}
	params->test_time += get_wall_time() - start_time;
	// average total reward
	total_reward /= params->test_max_episode;
	cout<<get_wall_time()-params->test_time-params->time<<' '<<total_reward<<' '<<flag<<endl;
	return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
callq 0x3860
movsd %xmm0, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x4cc0
xorps %xmm0, %xmm0
movsd %xmm0, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x20(%rcx), %eax
jge 0x3a10
movq -0x18(%rbp), %rax
movl (%rax), %esi
subl $0x1, %esi
xorl %edi, %edi
callq 0x37a0
movl %eax, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x48(%rbp)
movl $0x0, -0x30(%rbp)
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x24(%rcx), %eax
jge 0x3a00
movq -0x8(%rbp), %rax
movq %rax, -0x58(%rbp)
movl -0x38(%rbp), %eax
movl %eax, -0x50(%rbp)
movq -0x10(%rbp), %rdi
movslq -0x38(%rbp), %rsi
callq 0x4e40
movq -0x58(%rbp), %rdi
movl -0x50(%rbp), %esi
movl (%rax), %edx
leaq -0x3c(%rbp), %rcx
leaq -0x48(%rbp), %r8
callq 0x4dd0
movq -0x18(%rbp), %rax
movsd 0x18(%rax), %xmm0
movl -0x4c(%rbp), %edi
callq 0x4e60
movsd -0x48(%rbp), %xmm2
movsd -0x28(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x28(%rbp)
movsd -0x48(%rbp), %xmm0
movsd 0x964a(%rip), %xmm1     # 0xd018
ucomisd %xmm1, %xmm0
jne 0x39ec
jp 0x39ec
cmpl $0x0, -0x30(%rbp)
jne 0x39ec
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
movl $0x1, -0x30(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x3958
jmp 0x3a02
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x3918
callq 0x3860
subsd -0x20(%rbp), %xmm0
movq -0x18(%rbp), %rax
addsd 0x80(%rax), %xmm0
movsd %xmm0, 0x80(%rax)
movq -0x18(%rbp), %rax
cvtsi2sdl 0x20(%rax), %xmm1
movsd -0x28(%rbp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, -0x28(%rbp)
callq 0x3860
movq -0x18(%rbp), %rax
subsd 0x80(%rax), %xmm0
movq -0x18(%rbp), %rax
subsd 0x78(%rax), %xmm0
movq 0xf572(%rip), %rdi      # 0x12fd8
callq 0x23d0
movq %rax, %rdi
movl $0x20, %esi
callq 0x2270
movq %rax, %rdi
movsd -0x28(%rbp), %xmm0
callq 0x23d0
movq %rax, %rdi
movl $0x20, %esi
callq 0x2270
movq %rax, %rdi
movl -0x2c(%rbp), %esi
callq 0x2380
movq %rax, %rdi
movq 0xf519(%rip), %rsi      # 0x12fc0
callq 0x2200
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)