// File: boczeratul[P]StarCraftGA/ga.cpp
// Function: mutateChromosome(int*, int)
void mutateChromosome(int* chromosome, int r ) {

    double roll = uniform();
    double swapP = 0.33;
    double deleteP = 0.66;
    //double addP = 1;
    
    if ( roll < swapP && r != chromosome[0] && r != 0 )
    {
        // swap
        int temp = chromosome[r+1];
        chromosome[r+1] = chromosome[r];
        chromosome[r] = temp;
    }
    else if (roll < deleteP)
    {
        // delete dont mind
        int action = chromosome[r];
        for ( int i = 1; i < dontMindAction[0]+1; ++i )
        {
            if ( dontMindAction[i] == action )
            {
                // copy 
                for ( int w = r; w < chromosome[0]; ++w )
                {
                    chromosome[w] = chromosome[w+1];
                }
                --chromosome[0];
                break;
            }
        }
    }
    else
    {
        // insert dont mind
        if ( chromosome[0] < MAX_LENGTH-2)
        {


            int pivot =  uniformInt (0, dontMindTotalProb-1); //[0, dontMindTotalProb-1]
            int index = 1;
            while ( pivot > 0 )
            {
                pivot = pivot - actionProb[dontMindAction[index]];
                ++index;
            }
            int action = dontMindAction[index];

            // copy 
            for ( int i = chromosome[0]; i > r-1; --i )
            {
                chromosome[i+1] = chromosome[i];
            }
            chromosome[r] = action;

            ++chromosome[0];

        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
callq 0x2e30
movsd %xmm0, -0x18(%rbp)
movsd 0x8e8f(%rip), %xmm0     # 0xb020
movsd %xmm0, -0x20(%rbp)
movsd 0x8e7a(%rip), %xmm0     # 0xb018
movsd %xmm0, -0x28(%rbp)
movsd -0x18(%rbp), %xmm1
movsd -0x20(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x2205
movl -0xc(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl (%rcx), %eax
je 0x2205
cmpl $0x0, -0xc(%rbp)
je 0x2205
movq -0x8(%rbp), %rax
movl -0xc(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x2c(%rbp)
movq -0x8(%rbp), %rax
movslq -0xc(%rbp), %rcx
movl (%rax,%rcx,4), %edx
movq -0x8(%rbp), %rax
movl -0xc(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl -0x2c(%rbp), %edx
movq -0x8(%rbp), %rax
movslq -0xc(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x236b
movsd -0x18(%rbp), %xmm1
movsd -0x28(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x22a7
movq -0x8(%rbp), %rax
movslq -0xc(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x30(%rbp)
movl $0x1, -0x34(%rbp)
movl -0x34(%rbp), %eax
movl 0xbf19(%rip), %ecx      # 0xe150
addl $0x1, %ecx
cmpl %ecx, %eax
jge 0x22a2
movslq -0x34(%rbp), %rcx
leaq 0xbf07(%rip), %rax      # 0xe150
movl (%rax,%rcx,4), %eax
cmpl -0x30(%rbp), %eax
jne 0x2295
movl -0xc(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x2288
movq -0x8(%rbp), %rax
movl -0x38(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %edx
movq -0x8(%rbp), %rax
movslq -0x38(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x2257
movq -0x8(%rbp), %rax
movl (%rax), %ecx
addl $-0x1, %ecx
movl %ecx, (%rax)
jmp 0x22a2
jmp 0x2297
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x222e
jmp 0x2369
movq -0x8(%rbp), %rax
cmpl $0xf7, (%rax)
jge 0x2367
movl 0xc183(%rip), %esi      # 0xe440
subl $0x1, %esi
xorl %edi, %edi
callq 0x2e80
movl %eax, -0x3c(%rbp)
movl $0x1, -0x40(%rbp)
cmpl $0x0, -0x3c(%rbp)
jle 0x2301
movl -0x3c(%rbp), %eax
movslq -0x40(%rbp), %rdx
leaq 0xbe6b(%rip), %rcx      # 0xe150
movslq (%rcx,%rdx,4), %rdx
leaq 0x110c0(%rip), %rcx     # 0x133b0
subl (%rcx,%rdx,4), %eax
movl %eax, -0x3c(%rbp)
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x22d1
movslq -0x40(%rbp), %rcx
leaq 0xbe44(%rip), %rax      # 0xe150
movl (%rax,%rcx,4), %eax
movl %eax, -0x44(%rbp)
movq -0x8(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x48(%rbp)
movl -0x48(%rbp), %eax
movl -0xc(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jle 0x234e
movq -0x8(%rbp), %rax
movslq -0x48(%rbp), %rcx
movl (%rax,%rcx,4), %edx
movq -0x8(%rbp), %rax
movl -0x48(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl -0x48(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x231b
movl -0x44(%rbp), %edx
movq -0x8(%rbp), %rax
movslq -0xc(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x8(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x2369
jmp 0x236b
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)