// File: /workspace/github_cpp_makefile_star2_O3/Teris45[P]Maze-Game/Engine.cpp
// Function: Engine::Engine(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, char*)
Engine::Engine(const string& filename,const string& mybin, char *playersname) :moving(), poterakos(), goblinakos(), traalinakos(),hg(),username(playersname){

    curs_set(0);
    addstr("Welcome to the game young Mpampis\n\n");
    refresh();
    sleep(1);

    int xr,yr;
    getyx(stdscr,yr,xr);
    move(yr,0);
    clrtoeol();
    refresh();

    move(0,0);

    sleep(1);
    ifstream file(filename);
    string str;


    //Iterating through maze, and building it
    int y = 0;
    while (getline(file, str)){
        int x = 0;
        auto *line = new vector<int>;
        for(char i : str) {
            if (i == '*')
                line->insert(line->end(), WALL);
            else if (i == ' ') {
                line->insert(line->end(), DIADROMOS);
                Point p(x,y);
                this->available_points.push_back(p);
            }
            x++;
        }
        y++;
        this->maze.insert(this->maze.end(),*line);
    }
    this->last_row = y;
    this->poterakos.setPoint(available_points);
    this->maze[poterakos.getPoint().getY()][poterakos.getPoint().getX()] = POTERAKOS;


    this->goblinakos.setPoint(available_points);
    this->maze[goblinakos.getPoint().getY()][goblinakos.getPoint().getX()] = GOBLINAKOS;


    this->traalinakos.setPoint(available_points);
    this->maze[traalinakos.getPoint().getY()][traalinakos.getPoint().getX()] = TRAALINAKOS;

    for(auto & gem : this->gems) {
        gem.setPoint(available_points);
        this->maze[gem.getY()][gem.getX()] = GEM;
    }

    this->poterAlive = true;
    this->cntEatenGems = 0;
    this->winner = false;
    this->gameEnded = false;

//    mapUpdate();

    file.close();

    ifstream file2(mybin,ios::binary | ios::in);

    char c = file2.get();
    if(c==EOF){
        file2.close();
    }
    else{
        file2.close();
        ifstream  file3(mybin,ios::binary | ios::in);
        hg.load(file3);
        cout<<hg.toStr();
        file3.close();
    }


}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x688, %rsp            # imm = 0x688
movq %rcx, %r12
movq %rdx, -0x68(%rbp)
movq %rsi, %r15
movq %rdi, %rbx
leaq 0x18(%rdi), %rax
movq %rax, -0x38(%rbp)
addq $0x34, %rdi
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rbx)
movups %xmm0, 0x10(%rbx)
movups %xmm0, (%rbx)
movq %rbx, -0x30(%rbp)
callq 0x5a2c
leaq 0x38(%rbx), %rdi
movq %rdi, -0x50(%rbp)
callq 0x5998
leaq 0x50(%rbx), %rdi
movq %rdi, -0x48(%rbp)
callq 0x5930
leaq 0x68(%rbx), %rdi
movq %rdi, -0x40(%rbp)
callq 0x5964
leaq 0x80(%rbx), %r14
xorl %ebx, %ebx
movq %r14, %rdi
callq 0x61f4
addq $-0x10, %rbx
addq $0x10, %r14
cmpq $-0xa0, %rbx
jne 0x3b60
movq -0x30(%rbp), %rbx
leaq 0x120(%rbx), %rdi
movq %rdi, -0x90(%rbp)
callq 0x61f4
leaq 0x130(%rbx), %rdi
movq %rdi, -0x60(%rbp)
callq 0x62e4
leaq 0x178(%rbx), %rdi
leaq -0x6a8(%rbp), %rdx
movq %r12, %rsi
callq 0x3110
xorl %edi, %edi
callq 0x31b0
movq 0x640c(%rip), %rbx      # 0x9fd0
movq (%rbx), %rdi
leaq 0x34b2(%rip), %rsi      # 0x7080
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x30d0
callq 0x33a0
movl $0x1, %edi
callq 0x3190
movq (%rbx), %rax
testq %rax, %rax
je 0x3bf4
movswl (%rax), %edi
jmp 0x3bf9
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
xorl %esi, %esi
callq 0x3170
movq (%rbx), %rdi
callq 0x3250
callq 0x33a0
xorl %edi, %edi
xorl %esi, %esi
callq 0x3170
movl $0x1, %edi
callq 0x3190
leaq -0x6a8(%rbp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
movl $0x8, %edx
callq 0x3360
leaq -0x78(%rbp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq $0x0, -0x58(%rbp)
leaq -0x298(%rbp), %r13
movq -0x6a8(%rbp), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3210
movsbl %al, %edx
movq %rbx, %rdi
leaq -0x88(%rbp), %rsi
callq 0x3400
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x3d59
movl $0x18, %edi
callq 0x3220
movq %rax, %r12
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq $0x0, 0x10(%rax)
movq -0x80(%rbp), %rbx
testq %rbx, %rbx
je 0x3d33
movq -0x88(%rbp), %r15
xorl %r14d, %r14d
movzbl (%r15,%r14), %eax
cmpl $0x20, %eax
je 0x3cee
cmpl $0x2a, %eax
jne 0x3d2b
movq 0x8(%r12), %rsi
movl $0x1, -0x298(%rbp)
movq %r12, %rdi
movq %r13, %rdx
callq 0x4e0a
jmp 0x3d2b
movq 0x8(%r12), %rsi
movl $0x2, -0x298(%rbp)
movq %r12, %rdi
movq %r13, %rdx
callq 0x4e0a
movq %r13, %rdi
movl %r14d, %esi
movq -0x58(%rbp), %rdx
callq 0x5866
movq -0x38(%rbp), %rdi
movq %r13, %rsi
callq 0x49c6
movq %r13, %rdi
callq 0x587c
incq %r14
cmpq %r14, %rbx
jne 0x3cc3
movq -0x30(%rbp), %rdi
movq 0x8(%rdi), %rsi
movq %r12, %rdx
callq 0x49fa
movq -0x58(%rbp), %rax
incl %eax
movq %rax, -0x58(%rbp)
leaq -0x6a8(%rbp), %rbx
jmp 0x3c59
movq -0x30(%rbp), %rax
movq -0x58(%rbp), %rcx
movl %ecx, 0x30(%rax)
movq -0x50(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x57a4
leaq -0x298(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x582a
leaq -0x298(%rbp), %rdi
callq 0x5766
cltq
leaq (%rax,%rax,2), %rbx
shlq $0x3, %rbx
movq -0x30(%rbp), %rax
addq (%rax), %rbx
leaq -0x4a0(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x582a
leaq -0x4a0(%rbp), %rdi
callq 0x5752
cltq
movq (%rbx), %rcx
movl $0x3, (%rcx,%rax,4)
leaq -0x4a0(%rbp), %rdi
callq 0x587c
leaq -0x298(%rbp), %rdi
callq 0x587c
movq -0x48(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x57a4
leaq -0x298(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x582a
leaq -0x298(%rbp), %rdi
callq 0x5766
cltq
leaq (%rax,%rax,2), %rbx
shlq $0x3, %rbx
movq -0x30(%rbp), %rax
addq (%rax), %rbx
leaq -0x4a0(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x582a
leaq -0x4a0(%rbp), %rdi
callq 0x5752
cltq
movq (%rbx), %rcx
movl $0x4, (%rcx,%rax,4)
leaq -0x4a0(%rbp), %rdi
callq 0x587c
leaq -0x298(%rbp), %rdi
callq 0x587c
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x57a4
leaq -0x298(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x582a
leaq -0x298(%rbp), %rdi
callq 0x5766
cltq
leaq (%rax,%rax,2), %rbx
shlq $0x3, %rbx
movq -0x30(%rbp), %rax
addq (%rax), %rbx
leaq -0x4a0(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x582a
leaq -0x4a0(%rbp), %rdi
callq 0x5752
cltq
movq (%rbx), %rcx
movl $0x5, (%rcx,%rax,4)
leaq -0x4a0(%rbp), %rdi
callq 0x587c
leaq -0x298(%rbp), %rdi
callq 0x587c
movl $0x80, %ebx
movq -0x30(%rbp), %rax
leaq (%rax,%rbx), %r14
movq %r14, %rdi
movq -0x38(%rbp), %rsi
callq 0x6202
movq %r14, %rdi
callq 0x627a
movl %eax, %r15d
movq -0x30(%rbp), %rax
movq (%rax), %r12
movq %r14, %rdi
callq 0x6284
movslq %r15d, %rcx
leaq (%rcx,%rcx,2), %rcx
cltq
movq (%r12,%rcx,8), %rcx
movl $0x6, (%rcx,%rax,4)
addq $0x10, %rbx
cmpq $0x120, %rbx            # imm = 0x120
jne 0x3ed7
movq -0x30(%rbp), %rax
movw $0x1, 0x19c(%rax)
movl $0x0, 0x198(%rax)
movb $0x0, 0x19e(%rax)
leaq -0x6a8(%rbp), %rdi
callq 0x3050
leaq -0x298(%rbp), %rdi
movq -0x68(%rbp), %rsi
movl $0xc, %edx
callq 0x3360
leaq -0x298(%rbp), %rdi
callq 0x32b0
cmpb $-0x1, %al
jne 0x3f86
leaq -0x298(%rbp), %rdi
callq 0x3050
jmp 0x401a
leaq -0x298(%rbp), %rdi
callq 0x3050
leaq -0x4a0(%rbp), %rdi
movq -0x68(%rbp), %rsi
movl $0xc, %edx
callq 0x3360
leaq -0x4a0(%rbp), %rsi
movq -0x60(%rbp), %rdi
callq 0x647c
movq -0x60(%rbp), %rdi
callq 0x65ae
movq %rax, %r14
testq %rax, %rax
je 0x3fe4
movq %r14, %rdi
callq 0x3130
movq 0x6001(%rip), %rdi      # 0x9fd8
movq %r14, %rsi
movq %rax, %rdx
callq 0x3270
jmp 0x4002
movq 0x5fed(%rip), %rax      # 0x9fd8
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
leaq (%rax,%rcx), %rdi
movl 0x20(%rax,%rcx), %esi
orl $0x1, %esi
callq 0x3390
leaq -0x4a0(%rbp), %rdi
callq 0x3050
leaq -0x4a0(%rbp), %rdi
callq 0x3060
leaq -0x298(%rbp), %rdi
callq 0x3060
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0x4042
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x3230
leaq -0x6a8(%rbp), %rdi
callq 0x3060
addq $0x688, %rsp            # imm = 0x688
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x40ea
jmp 0x4154
jmp 0x408c
jmp 0x4143
jmp 0x4143
jmp 0x4154
jmp 0x408c
jmp 0x4143
jmp 0x4143
jmp 0x4154
movq %rax, %r15
leaq -0x4a0(%rbp), %rdi
callq 0x587c
jmp 0x4146
jmp 0x4143
jmp 0x4143
jmp 0x4154
jmp 0x4107
movq %rax, %r15
jmp 0x41a0
movq %rax, %r15
jmp 0x41a9
movq %rax, %r15
jmp 0x41b5
movq %rax, %r15
jmp 0x41da
movq %rax, %r15
jmp 0x41e3
movq %rax, %r15
leaq -0x4a0(%rbp), %rdi
callq 0x3060
jmp 0x40ed
movq %rax, %r15
leaq -0x298(%rbp), %rdi
callq 0x3060
jmp 0x4157
movq %rax, %r15
jmp 0x41ec
jmp 0x4154
jmp 0x4107
movq %rax, %r15
jmp 0x417f
jmp 0x4154
jmp 0x4154
movq %rax, %r15
testq %rbx, %rbx
je 0x41d1
negq %rbx
movq -0x30(%rbp), %rax
leaq 0x70(%rax), %r14
leaq (%r14,%rbx), %rdi
callq 0x587c
addq $-0x10, %rbx
jne 0x4127
jmp 0x41d1
jmp 0x4154
jmp 0x4154
jmp 0x4154
jmp 0x4154
movq %rax, %r15
leaq -0x298(%rbp), %rdi
callq 0x587c
jmp 0x4157
movq %rax, %r15
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0x4173
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x3230
leaq -0x6a8(%rbp), %rdi
callq 0x3060
movq -0x30(%rbp), %rax
movq 0x178(%rax), %rdi
addq $0x188, %rax            # imm = 0x188
cmpq %rax, %rdi
je 0x41a0
movq (%rax), %rsi
incq %rsi
callq 0x3230
movq -0x60(%rbp), %rdi
callq 0x6b50
movq -0x90(%rbp), %rdi
callq 0x587c
movl $0x110, %ebx            # imm = 0x110
movq -0x30(%rbp), %r14
leaq (%r14,%rbx), %rdi
callq 0x587c
addq $-0x10, %rbx
cmpq $0x70, %rbx
jne 0x41be
movq -0x40(%rbp), %rdi
callq 0x5846
movq -0x48(%rbp), %rdi
callq 0x5846
movq -0x50(%rbp), %rdi
callq 0x5846
movq -0x38(%rbp), %rdi
callq 0x4ab0
movq -0x30(%rbp), %rdi
callq 0x4b06
movq %r15, %rdi
callq 0x33e0