// File: 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
subq $0x910, %rsp            # imm = 0x910
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x798(%rbp)
movq %rdi, %rax
movq %rax, -0x7a8(%rbp)
callq 0x58f0
movq -0x798(%rbp), %rdi
addq $0x18, %rdi
movq %rdi, -0x7a0(%rbp)
callq 0x5910
movq -0x798(%rbp), %rdi
addq $0x34, %rdi
callq 0xb130
jmp 0x3e9e
movq -0x7a8(%rbp), %rdi
addq $0x38, %rdi
movq %rdi, -0x7b0(%rbp)
callq 0xab50
jmp 0x3eb7
movq -0x7a8(%rbp), %rdi
addq $0x50, %rdi
movq %rdi, -0x7b8(%rbp)
callq 0xaa30
jmp 0x3ed0
movq -0x7a8(%rbp), %rdi
addq $0x68, %rdi
movq %rdi, -0x7c0(%rbp)
callq 0xaac0
jmp 0x3ee9
movq -0x7a8(%rbp), %rax
addq $0x80, %rax
movq %rax, -0x7d8(%rbp)
movq %rax, %rcx
addq $0xa0, %rcx
movq %rcx, -0x7d0(%rbp)
movq %rax, -0x7c8(%rbp)
movq -0x7c8(%rbp), %rdi
movq %rdi, -0x7e0(%rbp)
callq 0xc390
jmp 0x3f2a
movq -0x7d0(%rbp), %rcx
movq -0x7e0(%rbp), %rax
addq $0x10, %rax
cmpq %rcx, %rax
movq %rax, -0x7c8(%rbp)
jne 0x3f15
movq -0x7a8(%rbp), %rdi
addq $0x120, %rdi            # imm = 0x120
movq %rdi, -0x7e8(%rbp)
callq 0xc390
jmp 0x3f64
movq -0x7a8(%rbp), %rdi
addq $0x130, %rdi            # imm = 0x130
movq %rdi, -0x7f0(%rbp)
callq 0xc5b0
jmp 0x3f80
movq -0x7a8(%rbp), %rax
addq $0x178, %rax            # imm = 0x178
movq %rax, -0x808(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x800(%rbp)
leaq -0x2d(%rbp), %rdi
movq %rdi, -0x7f8(%rbp)
callq 0x3440
movq -0x808(%rbp), %rdi
movq -0x800(%rbp), %rsi
movq -0x7f8(%rbp), %rdx
callq 0x3310
jmp 0x3fcb
leaq -0x2d(%rbp), %rdi
callq 0x3290
xorl %edi, %edi
callq 0x31d0
jmp 0x3fdd
movq 0xffec(%rip), %rax      # 0x13fd0
movq (%rax), %rdi
leaq 0xa041(%rip), %rsi      # 0xe02f
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x30c0
jmp 0x3ffa
callq 0x33f0
jmp 0x4001
movl $0x1, %edi
callq 0x31a0
jmp 0x400d
xorl %eax, %eax
movq 0xffba(%rip), %rcx      # 0x13fd0
cmpq (%rcx), %rax
je 0x4030
movq 0xffae(%rip), %rax      # 0x13fd0
movq (%rax), %rax
movswl (%rax), %eax
movl %eax, -0x80c(%rbp)
jmp 0x403d
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, -0x80c(%rbp)
jmp 0x403d
movl -0x80c(%rbp), %eax
movl %eax, -0x38(%rbp)
xorl %eax, %eax
movq 0xff81(%rip), %rcx      # 0x13fd0
cmpq (%rcx), %rax
je 0x406a
movq 0xff75(%rip), %rax      # 0x13fd0
movq (%rax), %rax
movswl 0x2(%rax), %eax
movl %eax, -0x810(%rbp)
jmp 0x4077
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, -0x810(%rbp)
jmp 0x4077
movl -0x810(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x38(%rbp), %edi
xorl %esi, %esi
callq 0x3190
jmp 0x408c
movq 0xff3d(%rip), %rax      # 0x13fd0
movq (%rax), %rdi
callq 0x3280
jmp 0x409d
callq 0x33f0
jmp 0x40a4
xorl %esi, %esi
movl %esi, %edi
callq 0x3190
jmp 0x40af
movl $0x1, %edi
callq 0x31a0
jmp 0x40bb
movq -0x10(%rbp), %rsi
leaq -0x240(%rbp), %rdi
movl $0x8, %edx
callq 0x33b0
jmp 0x40d2
leaq -0x260(%rbp), %rdi
callq 0x3320
movl $0x0, -0x264(%rbp)
leaq -0x240(%rbp), %rdi
leaq -0x260(%rbp), %rsi
callq 0x3040
movq %rax, -0x818(%rbp)
jmp 0x4104
movq -0x818(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x32e0
movb %al, -0x819(%rbp)
jmp 0x4122
movb -0x819(%rbp), %al
testb $0x1, %al
jne 0x4131
jmp 0x4496
movl $0x0, -0x268(%rbp)
movl $0x18, %edi
callq 0x3240
movq %rax, -0x828(%rbp)
jmp 0x414e
movq -0x828(%rbp), %rdi
callq 0x5950
movq -0x828(%rbp), %rax
movq %rax, -0x270(%rbp)
leaq -0x260(%rbp), %rax
movq %rax, -0x278(%rbp)
movq -0x278(%rbp), %rdi
callq 0x31e0
movq %rax, -0x280(%rbp)
movq -0x278(%rbp), %rdi
callq 0x3140
movq %rax, -0x288(%rbp)
leaq -0x280(%rbp), %rdi
leaq -0x288(%rbp), %rsi
callq 0x5970
testb $0x1, %al
jne 0x41b8
jmp 0x442c
leaq -0x280(%rbp), %rdi
callq 0x59b0
movb (%rax), %al
movb %al, -0x289(%rbp)
movsbl -0x289(%rbp), %eax
cmpl $0x2a, %eax
jne 0x4334
movq -0x270(%rbp), %rdi
movq %rdi, -0x838(%rbp)
callq 0x5a10
movq %rax, -0x2a0(%rbp)
leaq -0x298(%rbp), %rdi
leaq -0x2a0(%rbp), %rsi
callq 0x5a40
movq -0x838(%rbp), %rdi
movl $0x1, -0x2a4(%rbp)
movq -0x298(%rbp), %rsi
leaq -0x2a4(%rbp), %rdx
callq 0x59d0
movq %rax, -0x830(%rbp)
jmp 0x4236
movq -0x830(%rbp), %rax
movq %rax, -0x2b0(%rbp)
jmp 0x440c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x4b0c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x4b00
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x4af4
movq -0x7d8(%rbp), %rcx
movq %rax, %rsi
movq -0x7e0(%rbp), %rax
movq %rsi, -0x28(%rbp)
movl %edx, -0x2c(%rbp)
cmpq %rax, %rcx
movq %rax, -0x840(%rbp)
je 0x42d1
movq -0x840(%rbp), %rdi
addq $-0x10, %rdi
movq %rdi, -0x848(%rbp)
callq 0x5930
movq -0x7d8(%rbp), %rcx
movq -0x848(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x840(%rbp)
jne 0x42a0
jmp 0x4ae8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x4aa1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x4a95
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x2d(%rbp), %rdi
callq 0x3290
jmp 0x4a89
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x4a7d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x4a65
movsbl -0x289(%rbp), %eax
cmpl $0x20, %eax
jne 0x440a
movq -0x270(%rbp), %rdi
movq %rdi, -0x858(%rbp)
callq 0x5a10
movq %rax, -0x2c0(%rbp)
leaq -0x2b8(%rbp), %rdi
leaq -0x2c0(%rbp), %rsi
callq 0x5a40
movq -0x858(%rbp), %rdi
movl $0x2, -0x2c4(%rbp)
movq -0x2b8(%rbp), %rsi
leaq -0x2c4(%rbp), %rdx
callq 0x59d0
movq %rax, -0x850(%rbp)
jmp 0x439e
movq -0x850(%rbp), %rax
movq %rax, -0x2d0(%rbp)
movl -0x268(%rbp), %esi
movl -0x264(%rbp), %edx
leaq -0x2e0(%rbp), %rdi
callq 0xa8d0
jmp 0x43c6
movq -0x7a8(%rbp), %rdi
addq $0x18, %rdi
leaq -0x2e0(%rbp), %rsi
callq 0x5a80
jmp 0x43df
leaq -0x2e0(%rbp), %rdi
callq 0xa900
jmp 0x440a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x2e0(%rbp), %rdi
callq 0xa900
jmp 0x4a65
jmp 0x440c
movl -0x268(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x268(%rbp)
leaq -0x280(%rbp), %rdi
callq 0x5af0
jmp 0x419c
movq -0x7a8(%rbp), %rdi
movl -0x264(%rbp), %eax
incl %eax
movl %eax, -0x264(%rbp)
callq 0x5d10
movq %rax, -0x2f0(%rbp)
leaq -0x2e8(%rbp), %rdi
leaq -0x2f0(%rbp), %rsi
callq 0x5d40
movq -0x7a8(%rbp), %rdi
movq -0x270(%rbp), %rdx
movq -0x2e8(%rbp), %rsi
callq 0x5b10
movq %rax, -0x860(%rbp)
jmp 0x4483
movq -0x860(%rbp), %rax
movq %rax, -0x2f8(%rbp)
jmp 0x40e8
movq -0x7a8(%rbp), %rsi
movl -0x264(%rbp), %eax
movl %eax, 0x30(%rsi)
movq %rsi, %rdi
addq $0x38, %rdi
addq $0x18, %rsi
callq 0xa710
jmp 0x44b8
movq -0x7a8(%rbp), %rsi
movq %rsi, %rax
movq %rax, -0x868(%rbp)
addq $0x38, %rsi
leaq -0x308(%rbp), %rdi
callq 0xa840
jmp 0x44db
leaq -0x308(%rbp), %rdi
callq 0xa5b0
movl %eax, -0x86c(%rbp)
jmp 0x44ef
movq -0x868(%rbp), %rdi
movl -0x86c(%rbp), %eax
movslq %eax, %rsi
callq 0x58b0
movq -0x7a8(%rbp), %rsi
movq %rax, -0x878(%rbp)
addq $0x38, %rsi
leaq -0x318(%rbp), %rdi
callq 0xa840
jmp 0x4524
leaq -0x318(%rbp), %rdi
callq 0xa570
movl %eax, -0x87c(%rbp)
jmp 0x4538
movq -0x878(%rbp), %rdi
movl -0x87c(%rbp), %eax
movslq %eax, %rsi
callq 0x58d0
movl $0x3, (%rax)
leaq -0x318(%rbp), %rdi
callq 0xa900
leaq -0x308(%rbp), %rdi
callq 0xa900
movq -0x7a8(%rbp), %rsi
movq %rsi, %rdi
addq $0x50, %rdi
addq $0x18, %rsi
callq 0xa710
jmp 0x4584
movq -0x7a8(%rbp), %rsi
movq %rsi, %rax
movq %rax, -0x888(%rbp)
addq $0x50, %rsi
leaq -0x328(%rbp), %rdi
callq 0xa840
jmp 0x45a7
leaq -0x328(%rbp), %rdi
callq 0xa5b0
movl %eax, -0x88c(%rbp)
jmp 0x45bb
movq -0x888(%rbp), %rdi
movl -0x88c(%rbp), %eax
movslq %eax, %rsi
callq 0x58b0
movq -0x7a8(%rbp), %rsi
movq %rax, -0x898(%rbp)
addq $0x50, %rsi
leaq -0x338(%rbp), %rdi
callq 0xa840
jmp 0x45f0
leaq -0x338(%rbp), %rdi
callq 0xa570
movl %eax, -0x89c(%rbp)
jmp 0x4604
movq -0x898(%rbp), %rdi
movl -0x89c(%rbp), %eax
movslq %eax, %rsi
callq 0x58d0
movl $0x4, (%rax)
leaq -0x338(%rbp), %rdi
callq 0xa900
leaq -0x328(%rbp), %rdi
callq 0xa900
movq -0x7a8(%rbp), %rsi
movq %rsi, %rdi
addq $0x68, %rdi
addq $0x18, %rsi
callq 0xa710
jmp 0x4650
movq -0x7a8(%rbp), %rsi
movq %rsi, %rax
movq %rax, -0x8a8(%rbp)
addq $0x68, %rsi
leaq -0x348(%rbp), %rdi
callq 0xa840
jmp 0x4673
leaq -0x348(%rbp), %rdi
callq 0xa5b0
movl %eax, -0x8ac(%rbp)
jmp 0x4687
movq -0x8a8(%rbp), %rdi
movl -0x8ac(%rbp), %eax
movslq %eax, %rsi
callq 0x58b0
movq -0x7a8(%rbp), %rsi
movq %rax, -0x8b8(%rbp)
addq $0x68, %rsi
leaq -0x358(%rbp), %rdi
callq 0xa840
jmp 0x46bc
leaq -0x358(%rbp), %rdi
callq 0xa570
movl %eax, -0x8bc(%rbp)
jmp 0x46d0
movq -0x8b8(%rbp), %rdi
movl -0x8bc(%rbp), %eax
movslq %eax, %rsi
callq 0x58d0
movl $0x5, (%rax)
leaq -0x358(%rbp), %rdi
callq 0xa900
leaq -0x348(%rbp), %rdi
callq 0xa900
movq -0x7a8(%rbp), %rax
addq $0x80, %rax
movq %rax, -0x360(%rbp)
movq -0x360(%rbp), %rax
movq %rax, -0x368(%rbp)
movq -0x360(%rbp), %rax
addq $0xa0, %rax
movq %rax, -0x370(%rbp)
movq -0x368(%rbp), %rax
cmpq -0x370(%rbp), %rax
je 0x489d
movq -0x7a8(%rbp), %rsi
movq -0x368(%rbp), %rax
movq %rax, -0x378(%rbp)
movq -0x378(%rbp), %rdi
addq $0x18, %rsi
callq 0xc3b0
jmp 0x4774
movq -0x7a8(%rbp), %rax
movq %rax, -0x8c8(%rbp)
movq -0x378(%rbp), %rdi
callq 0xc480
movl %eax, -0x8c0(%rbp)
jmp 0x4796
movq -0x8c8(%rbp), %rdi
movl -0x8c0(%rbp), %eax
movslq %eax, %rsi
callq 0x58b0
movq %rax, -0x8d8(%rbp)
movq -0x378(%rbp), %rdi
callq 0xc4a0
movl %eax, -0x8cc(%rbp)
jmp 0x47c6
movq -0x8d8(%rbp), %rdi
movl -0x8cc(%rbp), %eax
movslq %eax, %rsi
callq 0x58d0
movl $0x6, (%rax)
movq -0x368(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x368(%rbp)
jmp 0x4739
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x481e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x318(%rbp), %rdi
callq 0xa900
leaq -0x308(%rbp), %rdi
callq 0xa900
jmp 0x4a65
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x4855
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x338(%rbp), %rdi
callq 0xa900
leaq -0x328(%rbp), %rdi
callq 0xa900
jmp 0x4a65
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x488c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x358(%rbp), %rdi
callq 0xa900
leaq -0x348(%rbp), %rdi
callq 0xa900
jmp 0x4a65
movq -0x7a8(%rbp), %rax
movb $0x1, 0x19c(%rax)
movl $0x0, 0x198(%rax)
movb $0x0, 0x19d(%rax)
movb $0x0, 0x19e(%rax)
leaq -0x240(%rbp), %rdi
callq 0x3050
jmp 0x48d1
movq -0x18(%rbp), %rax
movq %rax, -0x8e8(%rbp)
movl $0x4, %edi
movl $0x8, %esi
callq 0x5d80
movl %eax, -0x8dc(%rbp)
jmp 0x48f3
movl -0x8dc(%rbp), %edx
movq -0x8e8(%rbp), %rsi
leaq -0x580(%rbp), %rdi
callq 0x33b0
jmp 0x490e
leaq -0x580(%rbp), %rdi
callq 0x32c0
movl %eax, -0x8ec(%rbp)
jmp 0x4922
movl -0x8ec(%rbp), %eax
movb %al, -0x581(%rbp)
movsbl -0x581(%rbp), %eax
cmpl $-0x1, %eax
jne 0x495e
leaq -0x580(%rbp), %rdi
callq 0x3050
jmp 0x4948
jmp 0x4a2c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x4a59
leaq -0x580(%rbp), %rdi
callq 0x3050
jmp 0x496c
movq -0x18(%rbp), %rax
movq %rax, -0x8f8(%rbp)
movl $0x4, %edi
movl $0x8, %esi
callq 0x5d80
movl %eax, -0x8f0(%rbp)
jmp 0x498e
movl -0x8f0(%rbp), %edx
movq -0x8f8(%rbp), %rsi
leaq -0x790(%rbp), %rdi
callq 0x33b0
jmp 0x49a9
movq -0x7a8(%rbp), %rdi
addq $0x130, %rdi            # imm = 0x130
leaq -0x790(%rbp), %rsi
callq 0xc7c0
jmp 0x49c5
movq -0x7a8(%rbp), %rdi
addq $0x130, %rdi            # imm = 0x130
callq 0xc960
movq %rax, -0x900(%rbp)
jmp 0x49e1
movq -0x900(%rbp), %rsi
movq 0xf5e9(%rip), %rdi      # 0x13fd8
callq 0x3230
jmp 0x49f6
leaq -0x790(%rbp), %rdi
callq 0x3050
jmp 0x4a04
leaq -0x790(%rbp), %rdi
callq 0x3070
jmp 0x4a2c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x790(%rbp), %rdi
callq 0x3070
jmp 0x4a59
leaq -0x580(%rbp), %rdi
callq 0x3070
leaq -0x260(%rbp), %rdi
callq 0x3160
leaq -0x240(%rbp), %rdi
callq 0x3070
addq $0x910, %rsp            # imm = 0x910
popq %rbp
retq
leaq -0x580(%rbp), %rdi
callq 0x3070
leaq -0x260(%rbp), %rdi
callq 0x3160
leaq -0x240(%rbp), %rdi
callq 0x3070
movq -0x808(%rbp), %rdi
callq 0x3160
movq -0x7f0(%rbp), %rdi
callq 0xcd00
movq -0x7e8(%rbp), %rdi
callq 0x5930
movq -0x7d8(%rbp), %rax
addq $0xa0, %rax
movq %rax, -0x908(%rbp)
movq -0x908(%rbp), %rdi
addq $-0x10, %rdi
movq %rdi, -0x910(%rbp)
callq 0x5930
movq -0x7d8(%rbp), %rcx
movq -0x910(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x908(%rbp)
jne 0x4ab5
jmp 0x4ae8
movq -0x7c0(%rbp), %rdi
callq 0xab00
movq -0x7b8(%rbp), %rdi
callq 0xaa70
movq -0x7b0(%rbp), %rdi
callq 0xab90
movq -0x7a0(%rbp), %rdi
callq 0x5da0
movq -0x798(%rbp), %rdi
callq 0x5e00
movq -0x28(%rbp), %rdi
callq 0x3430
nopl (%rax)