// File: GAStudyGroup[P]GPX2/src/cross/AntColony/Ant.cpp
// Function: Ant::nextStep()
int Ant::nextStep(){
    vector<Choice> choices;
    double sum{0.0},rng{0.0};

    for(unsigned city : Globals::map.getCityList()){
        if(find(path.begin(),path.end(),city) == path.end()){
            choices.push_back(make_pair(city,calcChance(city)));   
        }
    }

    sort(choices.begin(),choices.end(),[](Choice& a, Choice& b){return a.second<b.second;});
    
    for(Choice c : choices){
        sum+=c.second;
    }
    
    uniform_real_distribution<double> dist(0.0,sum);
    
    rng = dist(Globals::urng);
    for(Choice c : choices){
        rng-=c.second;
        if(rng<=0){
            return c.first;
        }
    }
    return choices.back().first;
}

// Assembly:
subq $0x188, %rsp            # imm = 0x188
movq %rdi, 0x178(%rsp)
movq 0x178(%rsp), %rax
movq %rax, 0x38(%rsp)
leaq 0x160(%rsp), %rdi
callq 0x4e1b0
movq $0x0, 0x158(%rsp)
movq $0x0, 0x150(%rsp)
leaq 0x51288(%rip), %rsi     # 0x9dd90
leaq 0x130(%rsp), %rdi
callq 0x195b0
jmp 0x4cb17
leaq 0x130(%rsp), %rax
movq %rax, 0x148(%rsp)
movq 0x148(%rsp), %rdi
callq 0x10130
movq %rax, 0x118(%rsp)
movq 0x148(%rsp), %rdi
callq 0x10160
movq %rax, 0x110(%rsp)
leaq 0x118(%rsp), %rdi
leaq 0x110(%rsp), %rsi
callq 0x11c60
testb $0x1, %al
jne 0x4cb95
leaq 0x130(%rsp), %rdi
callq 0x9af0
jmp 0x4ccfd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x128(%rsp)
movl %eax, 0x124(%rsp)
jmp 0x4cf05
leaq 0x118(%rsp), %rdi
callq 0x11fc0
movq 0x38(%rsp), %rdi
movl (%rax), %eax
movl %eax, 0x10c(%rsp)
callq 0x10130
movq 0x38(%rsp), %rdi
movq %rax, 0xf8(%rsp)
callq 0x10160
movq %rax, 0xf0(%rsp)
movq 0xf8(%rsp), %rdi
movq 0xf0(%rsp), %rsi
leaq 0x10c(%rsp), %rdx
callq 0x4e150
movq %rax, 0x30(%rsp)
jmp 0x4cbf3
movq 0x38(%rsp), %rdi
movq 0x30(%rsp), %rax
movq %rax, 0x100(%rsp)
callq 0x10160
movq %rax, 0xe8(%rsp)
leaq 0x100(%rsp), %rdi
leaq 0xe8(%rsp), %rsi
callq 0x11aa0
testb $0x1, %al
jne 0x4cc30
jmp 0x4cce9
movq 0x38(%rsp), %rdi
movl 0x10c(%rsp), %esi
callq 0x4c7a0
movsd %xmm0, 0x28(%rsp)
jmp 0x4cc49
movsd 0x28(%rsp), %xmm0
movsd %xmm0, 0xc0(%rsp)
leaq 0x10c(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
callq 0x4e1f0
movsd %xmm0, 0x18(%rsp)
movl %eax, 0x24(%rsp)
jmp 0x4cc79
movsd 0x18(%rsp), %xmm0
movl 0x24(%rsp), %eax
movl %eax, 0xc8(%rsp)
movsd %xmm0, 0xd0(%rsp)
leaq 0xd8(%rsp), %rdi
leaq 0xc8(%rsp), %rsi
callq 0x4e230
jmp 0x4ccaa
leaq 0x160(%rsp), %rdi
leaq 0xd8(%rsp), %rsi
callq 0x4e1c0
jmp 0x4ccc1
jmp 0x4cce9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x128(%rsp)
movl %eax, 0x124(%rsp)
leaq 0x130(%rsp), %rdi
callq 0x9af0
jmp 0x4cf05
jmp 0x4cceb
leaq 0x118(%rsp), %rdi
callq 0x11f60
jmp 0x4cb51
leaq 0x160(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x4e260
movq 0x10(%rsp), %rdi
movq %rax, 0xb8(%rsp)
callq 0x4e290
movq %rax, 0xb0(%rsp)
movq 0xb8(%rsp), %rdi
movq 0xb0(%rsp), %rsi
callq 0x4cf20
jmp 0x4cd40
leaq 0x160(%rsp), %rax
movq %rax, 0xa0(%rsp)
movq 0xa0(%rsp), %rdi
callq 0x4e260
movq %rax, 0x98(%rsp)
movq 0xa0(%rsp), %rdi
callq 0x4e290
movq %rax, 0x90(%rsp)
leaq 0x98(%rsp), %rdi
leaq 0x90(%rsp), %rsi
callq 0x4e2c0
testb $0x1, %al
jne 0x4cd95
jmp 0x4cde3
leaq 0x98(%rsp), %rdi
callq 0x4e300
movq (%rax), %rcx
movq %rcx, 0x80(%rsp)
movq 0x8(%rax), %rax
movq %rax, 0x88(%rsp)
movsd 0x88(%rsp), %xmm0
addsd 0x158(%rsp), %xmm0
movsd %xmm0, 0x158(%rsp)
leaq 0x98(%rsp), %rdi
callq 0x4e310
jmp 0x4cd7a
movsd 0x158(%rsp), %xmm1
leaq 0x70(%rsp), %rdi
xorps %xmm0, %xmm0
callq 0x10740
jmp 0x4cdfb
leaq 0x4fc06(%rip), %rsi     # 0x9ca08
leaq 0x70(%rsp), %rdi
callq 0x10770
movsd %xmm0, 0x8(%rsp)
jmp 0x4ce14
movsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x150(%rsp)
leaq 0x160(%rsp), %rax
movq %rax, 0x68(%rsp)
movq 0x68(%rsp), %rdi
callq 0x4e260
movq %rax, 0x60(%rsp)
movq 0x68(%rsp), %rdi
callq 0x4e290
movq %rax, 0x58(%rsp)
leaq 0x60(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x4e2c0
testb $0x1, %al
jne 0x4ce63
jmp 0x4cecb
leaq 0x60(%rsp), %rdi
callq 0x4e300
movq (%rax), %rcx
movq %rcx, 0x48(%rsp)
movq 0x8(%rax), %rax
movq %rax, 0x50(%rsp)
movsd 0x50(%rsp), %xmm1
movsd 0x150(%rsp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, 0x150(%rsp)
xorps %xmm0, %xmm0
ucomisd 0x150(%rsp), %xmm0
jb 0x4cebd
movl 0x48(%rsp), %eax
movl %eax, 0x184(%rsp)
movl $0x1, 0x44(%rsp)
jmp 0x4cee9
jmp 0x4cebf
leaq 0x60(%rsp), %rdi
callq 0x4e310
jmp 0x4ce4e
leaq 0x160(%rsp), %rdi
callq 0x4e330
movl (%rax), %eax
movl %eax, 0x184(%rsp)
movl $0x1, 0x44(%rsp)
leaq 0x160(%rsp), %rdi
callq 0x4e370
movl 0x184(%rsp), %eax
addq $0x188, %rsp            # imm = 0x188
retq
leaq 0x160(%rsp), %rdi
callq 0x4e370
movq 0x128(%rsp), %rdi
callq 0x6850
nop