// File: SYLOH[P]ant-sim/antsim.cpp
// Function: ant::selectNextNode(map, bool*, int)
int ant::selectNextNode(map mMap, bool * visitedNodes, int curNode){
	float total=0;
	float nodeCounter=0;
	float randResult;
	
	//create the random horizon
	for (int i = 0; i < numNodes; i++){
		if(!visitedNodes[i]){
			total += mMap.trailArray[curNode][i]*pow((1/mMap.distArray[curNode][i]),distWeight);
		}
	}
	srand((unsigned)time(0)+id);//reseed the RNG
	randResult = total * ((float)rand()/(float)RAND_MAX);//rolls the dice
	
	for (int i= 0; i < numNodes; i++){
		if(!visitedNodes[i]){
			nodeCounter += mMap.trailArray[curNode][i]*pow((1/mMap.distArray[curNode][i]),distWeight);
			if (nodeCounter >= randResult){
				return i;
			}
		}
	}
	
	return 0;	
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
leaq 0x10(%rbp), %rax
movq %rax, -0x40(%rbp)
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x38(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x20(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x24(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl 0x2bf5(%rip), %eax      # 0x50c8
jge 0x2570
movq -0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
testb $0x1, (%rax,%rcx)
jne 0x2560
movq -0x40(%rbp), %rax
movq %rax, %rcx
addq $0x9c40, %rcx           # imm = 0x9C40
movslq -0x1c(%rbp), %rdx
imulq $0x190, %rdx, %rdx      # imm = 0x190
addq %rdx, %rcx
movslq -0x2c(%rbp), %rdx
movss (%rcx,%rdx,4), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x48(%rbp)
movslq -0x1c(%rbp), %rcx
imulq $0x190, %rcx, %rcx      # imm = 0x190
addq %rcx, %rax
movslq -0x2c(%rbp), %rcx
movss 0xae1(%rip), %xmm0      # 0x3010
divss (%rax,%rcx,4), %xmm0
movl $0x1, %edi
callq 0x2d30
movaps %xmm0, %xmm2
movsd -0x48(%rbp), %xmm0
movss -0x20(%rbp), %xmm1
cvtss2sd %xmm1, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x20(%rbp)
jmp 0x2562
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x24ca
xorl %eax, %eax
movl %eax, %edi
callq 0x10a0
movq %rax, %rcx
movq -0x38(%rbp), %rax
movl %ecx, %edi
addl 0x194(%rax), %edi
callq 0x10b0
movss -0x20(%rbp), %xmm0
movss %xmm0, -0x4c(%rbp)
callq 0x1050
movss -0x4c(%rbp), %xmm0
cvtsi2ss %eax, %xmm1
movss 0xa5f(%rip), %xmm2      # 0x300c
divss %xmm2, %xmm1
mulss %xmm1, %xmm0
movss %xmm0, -0x28(%rbp)
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl 0x2afe(%rip), %eax      # 0x50c8
jge 0x2680
movq -0x18(%rbp), %rax
movslq -0x30(%rbp), %rcx
testb $0x1, (%rax,%rcx)
jne 0x2670
movq -0x40(%rbp), %rax
movq %rax, %rcx
addq $0x9c40, %rcx           # imm = 0x9C40
movslq -0x1c(%rbp), %rdx
imulq $0x190, %rdx, %rdx      # imm = 0x190
addq %rdx, %rcx
movslq -0x30(%rbp), %rdx
movss (%rcx,%rdx,4), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x58(%rbp)
movslq -0x1c(%rbp), %rcx
imulq $0x190, %rcx, %rcx      # imm = 0x190
addq %rcx, %rax
movslq -0x30(%rbp), %rcx
movss 0x9e6(%rip), %xmm0      # 0x3010
divss (%rax,%rcx,4), %xmm0
movl $0x1, %edi
callq 0x2d30
movaps %xmm0, %xmm2
movsd -0x58(%rbp), %xmm0
movss -0x24(%rbp), %xmm1
cvtss2sd %xmm1, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x24(%rbp)
movss -0x24(%rbp), %xmm0
ucomiss -0x28(%rbp), %xmm0
jb 0x266e
movl -0x30(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x2687
jmp 0x2670
jmp 0x2672
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x25c1
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq