// File: nachogoro[P]wordcrack-herminia/src/Board.cpp
// Function: Board::Board(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
Board::Board(const std::string& fileName)
{
    std::ifstream inputfile(fileName);

    std::string line;
    int y = 0;

    while (std::getline(inputfile, line))
    {
        if (y >= VERTICAL_SIZE) {
            throw std::runtime_error("Input file is too long");
        }

        std::vector<std::string> tokens = split(line, ' ');

        if (tokens.size() > HORIZONTAL_SIZE) {
            throw std::runtime_error("Line in input file is too long");
        }

        for (size_t x = 0; x < tokens.size(); ++x)
        {
            const std::string& token = tokens[x];
            const char tmp = token.at(0);
            std::string letter;
            if (tmp == 'Q') {
                letter = "qu";
            } else {
                letter = ::tolower(tmp);
            }
            const int value = token.at(1) - '0';

            WordMultiplier wordMult = SINGLE_WORD;
            LetterMultiplier letterMult = SINGLE_LETTER;

            if (token.length() == 4)
            {
                const std::string& modifier = token.substr(2);

                if (modifier == "DW") {
                    wordMult = DOUBLE_WORD;
                } else if (modifier == "TW") {
                    wordMult = TRIPLE_WORD;
                } else if (modifier == "DL") {
                    letterMult = DOUBLE_LETTER;
                } else if (modifier == "TL") {
                    letterMult = TRIPLE_LETTER;
                }
            }

            mLetters[y][x] = Letter(letter, value, Coordinate(x, y), 
                                        wordMult, letterMult);
        }

        ++y;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x3b0, %rsp            # imm = 0x3B0
movq %rdi, -0x340(%rbp)
movq %rsi, -0x338(%rbp)
callq 0x31c0
movq -0x340(%rbp), %rdi
movq -0x338(%rbp), %rsi
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x330(%rbp)
movq %rax, %rcx
addq $0x380, %rcx            # imm = 0x380
movq %rcx, -0x328(%rbp)
movq %rax, -0x320(%rbp)
movq -0x320(%rbp), %rdi
movq %rdi, -0x348(%rbp)
callq 0x37f0
jmp 0x42bc
movq -0x328(%rbp), %rcx
movq -0x348(%rbp), %rax
addq $0x38, %rax
cmpq %rcx, %rax
movq %rax, -0x320(%rbp)
jne 0x42a7
movq -0x10(%rbp), %rsi
leaq -0x228(%rbp), %rdi
movl $0x8, %edx
callq 0x3370
jmp 0x42f1
leaq -0x248(%rbp), %rdi
callq 0x3300
movl $0x0, -0x24c(%rbp)
leaq -0x228(%rbp), %rdi
leaq -0x248(%rbp), %rsi
callq 0x3060
movq %rax, -0x350(%rbp)
jmp 0x4323
movq -0x350(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x32b0
movb %al, -0x351(%rbp)
jmp 0x4341
movb -0x351(%rbp), %al
testb $0x1, %al
jne 0x4350
jmp 0x4823
cmpl $0x4, -0x24c(%rbp)
jl 0x443a
movl $0x10, %edi
callq 0x3100
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x360(%rbp)
leaq 0x12c9d(%rip), %rsi     # 0x17018
callq 0x30b0
jmp 0x4382
movq -0x360(%rbp), %rdi
movq 0x1bc60(%rip), %rsi     # 0x1fff0
movq 0x1bc29(%rip), %rdx     # 0x1ffc0
callq 0x33d0
jmp 0x48ac
movq -0x330(%rbp), %rcx
movq %rax, %rsi
movq -0x348(%rbp), %rax
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
cmpq %rax, %rcx
movq %rax, -0x368(%rbp)
je 0x43f6
movq -0x368(%rbp), %rdi
addq $-0x38, %rdi
movq %rdi, -0x370(%rbp)
callq 0x54d0
movq -0x330(%rbp), %rcx
movq -0x370(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x368(%rbp)
jne 0x43c5
jmp 0x48a3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x485c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x4844
movq -0x360(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
callq 0x3190
jmp 0x4844
leaq -0x268(%rbp), %rdi
leaq -0x248(%rbp), %rsi
movl $0x20, %edx
callq 0x3760
jmp 0x4454
leaq -0x268(%rbp), %rdi
callq 0x5500
cmpq $0x4, %rax
jbe 0x44d8
movl $0x10, %edi
callq 0x3100
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x378(%rbp)
leaq 0x12bab(%rip), %rsi     # 0x1702f
callq 0x30b0
jmp 0x448b
movq -0x378(%rbp), %rdi
movq 0x1bb57(%rip), %rsi     # 0x1fff0
movq 0x1bb20(%rip), %rdx     # 0x1ffc0
callq 0x33d0
jmp 0x48ac
movq -0x378(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
callq 0x3190
jmp 0x4815
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x4815
movq $0x0, -0x270(%rbp)
movq -0x270(%rbp), %rax
movq %rax, -0x380(%rbp)
leaq -0x268(%rbp), %rdi
callq 0x5500
movq %rax, %rcx
movq -0x380(%rbp), %rax
cmpq %rcx, %rax
jae 0x47f5
movq -0x270(%rbp), %rsi
leaq -0x268(%rbp), %rdi
callq 0x5540
movq %rax, -0x278(%rbp)
movq -0x278(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x3290
movq %rax, -0x388(%rbp)
jmp 0x4543
movq -0x388(%rbp), %rax
movb (%rax), %al
movb %al, -0x279(%rbp)
leaq -0x2a0(%rbp), %rdi
callq 0x3300
movsbl -0x279(%rbp), %eax
cmpl $0x51, %eax
jne 0x4592
leaq 0x12add(%rip), %rsi     # 0x1704e
leaq -0x2a0(%rbp), %rdi
callq 0x32e0
jmp 0x457f
jmp 0x45b1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x47e7
movsbl -0x279(%rbp), %edi
callq 0x3310
movsbl %al, %esi
leaq -0x2a0(%rbp), %rdi
callq 0x33b0
jmp 0x45af
jmp 0x45b1
movq -0x278(%rbp), %rdi
movl $0x1, %esi
callq 0x3290
movq %rax, -0x390(%rbp)
jmp 0x45cb
movq -0x390(%rbp), %rax
movsbl (%rax), %eax
subl $0x30, %eax
movl %eax, -0x2a4(%rbp)
movl $0x1, -0x2a8(%rbp)
movl $0x1, -0x2ac(%rbp)
movq -0x278(%rbp), %rdi
callq 0x3340
cmpq $0x4, %rax
jne 0x4733
movq -0x278(%rbp), %rsi
leaq -0x2d8(%rbp), %rdi
movl $0x2, %edx
movq $-0x1, %rcx
callq 0x3240
jmp 0x4629
leaq -0x2d8(%rbp), %rax
movq %rax, -0x2b8(%rbp)
movq -0x2b8(%rbp), %rdi
leaq 0x12a0c(%rip), %rsi     # 0x17051
callq 0x5580
movb %al, -0x391(%rbp)
jmp 0x4652
movb -0x391(%rbp), %al
testb $0x1, %al
jne 0x465e
jmp 0x468a
movl $0x2, -0x2a8(%rbp)
jmp 0x4727
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
leaq -0x2d8(%rbp), %rdi
callq 0x3150
jmp 0x47e7
movq -0x2b8(%rbp), %rdi
leaq 0x129bc(%rip), %rsi     # 0x17054
callq 0x5580
movb %al, -0x392(%rbp)
jmp 0x46a5
movb -0x392(%rbp), %al
testb $0x1, %al
jne 0x46b1
jmp 0x46bd
movl $0x3, -0x2a8(%rbp)
jmp 0x4725
movq -0x2b8(%rbp), %rdi
leaq 0x1298c(%rip), %rsi     # 0x17057
callq 0x5580
movb %al, -0x393(%rbp)
jmp 0x46d8
movb -0x393(%rbp), %al
testb $0x1, %al
jne 0x46e4
jmp 0x46f0
movl $0x2, -0x2ac(%rbp)
jmp 0x4723
movq -0x2b8(%rbp), %rdi
leaq 0x1295c(%rip), %rsi     # 0x1705a
callq 0x5580
movb %al, -0x394(%rbp)
jmp 0x470b
movb -0x394(%rbp), %al
testb $0x1, %al
jne 0x4717
jmp 0x4721
movl $0x3, -0x2ac(%rbp)
jmp 0x4723
jmp 0x4725
jmp 0x4727
leaq -0x2d8(%rbp), %rdi
callq 0x3150
movl -0x2a4(%rbp), %eax
movl %eax, -0x398(%rbp)
movl -0x270(%rbp), %esi
movl -0x24c(%rbp), %edx
leaq -0x318(%rbp), %rdi
callq 0x4cf0
jmp 0x4759
movl -0x398(%rbp), %edx
movl -0x2a8(%rbp), %r8d
movl -0x2ac(%rbp), %r9d
movq -0x318(%rbp), %rcx
leaq -0x310(%rbp), %rdi
leaq -0x2a0(%rbp), %rsi
callq 0x38c0
jmp 0x4789
movq -0x330(%rbp), %rdi
movslq -0x24c(%rbp), %rax
imulq $0xe0, %rax, %rax
addq %rax, %rdi
imulq $0x38, -0x270(%rbp), %rax
addq %rax, %rdi
leaq -0x310(%rbp), %rsi
callq 0x55c0
leaq -0x310(%rbp), %rdi
callq 0x54d0
leaq -0x2a0(%rbp), %rdi
callq 0x3150
movq -0x270(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x270(%rbp)
jmp 0x44e3
leaq -0x2a0(%rbp), %rdi
callq 0x3150
jmp 0x4815
movl -0x24c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24c(%rbp)
leaq -0x268(%rbp), %rdi
callq 0x4c90
jmp 0x4307
leaq -0x268(%rbp), %rdi
callq 0x4c90
jmp 0x4844
leaq -0x248(%rbp), %rdi
callq 0x3150
leaq -0x228(%rbp), %rdi
callq 0x3070
addq $0x3b0, %rsp            # imm = 0x3B0
popq %rbp
retq
leaq -0x248(%rbp), %rdi
callq 0x3150
leaq -0x228(%rbp), %rdi
callq 0x3070
movq -0x330(%rbp), %rax
addq $0x380, %rax            # imm = 0x380
movq %rax, -0x3a0(%rbp)
movq -0x3a0(%rbp), %rdi
addq $-0x38, %rdi
movq %rdi, -0x3a8(%rbp)
callq 0x54d0
movq -0x330(%rbp), %rcx
movq -0x3a8(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x3a0(%rbp)
jne 0x4870
jmp 0x48a3
movq -0x18(%rbp), %rdi
callq 0x33f0
nopl (%rax)