// File: NathanWine[P]2048-AI-Solvers/src/Game.cpp
// Function: Game::computePossibilities() const
std::map<int, weightedmoves> Game::computePossibilities() const {
    // Note: Responsibility to check if game can continue is given to other functions
    std::map<int, weightedmoves> possibilities;
    movelist valid_moves;
    generatePossibleMoves(valid_moves);

    for (auto const &move : valid_moves) {
        int dir = move.first;
        for (int i = 0; i < DIM; ++i) {
            for (int j = 0; j < DIM; ++j) {
                if (move.second.state[i][j] == 0) {      // If space is 0, add all outcomes if tile added here
                    Game game_copy = move.second;
                    game_copy.state[i][j] = 2;
                    possibilities[dir].push_back(std::pair<float, Game>(0.9, game_copy));
                    game_copy.state[i][j] = 4;
                    possibilities[dir].push_back(std::pair<float, Game>(0.1, game_copy));
                }
            }
        }
    }

    for (auto &possibility : possibilities) {           // Normalize the probabilities
        int len = (int) possibility.second.size();
        for (int i = 0; i < len; ++i) {
            possibility.second[i].first /= len;
        }
    }

    return possibilities;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x150, %rsp            # imm = 0x150
movq %rdi, -0x138(%rbp)
movq %rdi, %rax
movq %rax, -0x130(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x128(%rbp)
movb $0x0, -0x11(%rbp)
callq 0x114e0
leaq -0x30(%rbp), %rdi
movq %rdi, -0x120(%rbp)
callq 0x7e30
movq -0x128(%rbp), %rdi
movq -0x120(%rbp), %rsi
callq 0xf630
jmp 0xfc0d
leaq -0x30(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rdi
callq 0x7e90
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rdi
callq 0x7ec0
movq %rax, -0x58(%rbp)
leaq -0x50(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x7ef0
testb $0x1, %al
jne 0xfc45
jmp 0xfe6f
leaq -0x50(%rbp), %rdi
callq 0x7f30
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x64(%rbp)
movl $0x0, -0x68(%rbp)
cmpl $0x4, -0x68(%rbp)
jge 0xfe5f
movl $0x0, -0x6c(%rbp)
cmpl $0x4, -0x6c(%rbp)
jge 0xfe4f
movq -0x60(%rbp), %rdi
addq $0x8, %rdi
addq $0x8, %rdi
movslq -0x68(%rbp), %rsi
callq 0x7f70
movq %rax, %rdi
movslq -0x6c(%rbp), %rsi
callq 0x7f90
cmpl $0x0, (%rax)
jne 0xfe3f
movq -0x60(%rbp), %rsi
addq $0x8, %rsi
leaq -0x90(%rbp), %rdi
callq 0x3f70
jmp 0xfcbd
leaq -0x88(%rbp), %rdi
movslq -0x68(%rbp), %rsi
callq 0x7fb0
movq %rax, %rdi
movslq -0x6c(%rbp), %rsi
callq 0x4230
movq -0x138(%rbp), %rdi
movl $0x2, (%rax)
leaq -0x64(%rbp), %rsi
callq 0x11500
movq %rax, -0x140(%rbp)
jmp 0xfcf8
movabsq $0x3feccccccccccccd, %rax # imm = 0x3FECCCCCCCCCCCCD
movq %rax, -0xc0(%rbp)
leaq -0xb8(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
leaq -0x90(%rbp), %rdx
callq 0x11610
jmp 0xfd25
movq -0x140(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x115e0
jmp 0xfd3a
leaq -0xb8(%rbp), %rdi
callq 0x8c80
leaq -0x88(%rbp), %rdi
movslq -0x68(%rbp), %rsi
callq 0x7fb0
movq %rax, %rdi
movslq -0x6c(%rbp), %rsi
callq 0x4230
movq -0x138(%rbp), %rdi
movl $0x4, (%rax)
leaq -0x64(%rbp), %rsi
callq 0x11500
movq %rax, -0x148(%rbp)
jmp 0xfd81
movabsq $0x3fb999999999999a, %rax # imm = 0x3FB999999999999A
movq %rax, -0xf0(%rbp)
leaq -0xe8(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
leaq -0x90(%rbp), %rdx
callq 0x11610
jmp 0xfdae
movq -0x148(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
callq 0x115e0
jmp 0xfdc3
leaq -0xe8(%rbp), %rdi
callq 0x8c80
leaq -0x90(%rbp), %rdi
callq 0x4460
jmp 0xfe3f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0xff74
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0xfe2e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x8c80
jmp 0xfe2e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0xe8(%rbp), %rdi
callq 0x8c80
leaq -0x90(%rbp), %rdi
callq 0x4460
jmp 0xff74
jmp 0xfe41
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
jmp 0xfc73
jmp 0xfe51
movl -0x68(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x68(%rbp)
jmp 0xfc62
jmp 0xfe61
leaq -0x50(%rbp), %rdi
callq 0x7f50
jmp 0xfc2f
movq -0x138(%rbp), %rax
movq %rax, -0xf8(%rbp)
movq -0xf8(%rbp), %rdi
callq 0x8050
movq %rax, -0x100(%rbp)
movq -0xf8(%rbp), %rdi
callq 0x8080
movq %rax, -0x108(%rbp)
leaq -0x100(%rbp), %rdi
leaq -0x108(%rbp), %rsi
callq 0x80b0
testb $0x1, %al
jne 0xfebf
jmp 0xff5f
leaq -0x100(%rbp), %rdi
callq 0x80e0
movq %rax, -0x110(%rbp)
movq -0x110(%rbp), %rdi
addq $0x8, %rdi
callq 0x8100
movl %eax, -0x114(%rbp)
movl $0x0, -0x118(%rbp)
movl -0x118(%rbp), %eax
cmpl -0x114(%rbp), %eax
jge 0xff4c
cvtsi2ssl -0x114(%rbp), %xmm0
movss %xmm0, -0x14c(%rbp)
movq -0x110(%rbp), %rdi
addq $0x8, %rdi
movslq -0x118(%rbp), %rsi
callq 0x11650
movss -0x14c(%rbp), %xmm1
movss (%rax), %xmm0
divss %xmm1, %xmm0
movss %xmm0, (%rax)
movl -0x118(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x118(%rbp)
jmp 0xfef2
jmp 0xff4e
leaq -0x100(%rbp), %rdi
callq 0x8230
jmp 0xfea3
movb $0x1, -0x11(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x7fd0
testb $0x1, -0x11(%rbp)
jne 0xff97
jmp 0xff8b
leaq -0x30(%rbp), %rdi
callq 0x7fd0
movq -0x138(%rbp), %rdi
callq 0x8360
jmp 0xffa7
movq -0x138(%rbp), %rdi
callq 0x8360
movq -0x130(%rbp), %rax
addq $0x150, %rsp            # imm = 0x150
popq %rbp
retq
movq -0x38(%rbp), %rdi
callq 0x33d0