// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2d8, %rsp            # imm = 0x2D8
movq %rsi, %rbx
movq %rdi, -0x30(%rbp)
callq 0x2180
xorl %r15d, %r15d
movq -0x30(%rbp), %rax
leaq (%rax,%r15), %rdi
callq 0x261c
addq $0x38, %r15
cmpq $0x380, %r15            # imm = 0x380
jne 0x2c27
leaq -0x2f8(%rbp), %rdi
pushq $0x8
popq %rdx
movq %rbx, %rsi
callq 0x22c0
leaq -0xa8(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
xorl %r14d, %r14d
leaq -0xb8(%rbp), %rbx
leaq -0x58(%rbp), %r12
movq -0x30(%rbp), %r15
movq %r15, -0x40(%rbp)
leaq -0x2f8(%rbp), %rdi
movq %rbx, %rsi
callq 0x2060
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x2eb6
cmpq $0x4, %r14
je 0x2ee0
movq %r12, %rdi
movq %rbx, %rsi
pushq $0x20
popq %rdx
callq 0x25ca
movq -0x58(%rbp), %r13
movq -0x50(%rbp), %rax
movq %rax, %rcx
subq %r13, %rcx
cmpq $0x80, %rcx
ja 0x2f12
movq %r14, -0x60(%rbp)
shlq $0x20, %r14
movq %r14, -0x68(%rbp)
movq -0x40(%rbp), %r12
movq $0x0, -0x38(%rbp)
xorl %ebx, %ebx
subq %r13, %rax
sarq $0x5, %rax
movq %rbx, -0x78(%rbp)
cmpq %rax, %rbx
jae 0x2e8f
movq -0x38(%rbp), %rax
leaq (%rax,%r13), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x2230
movsbl (%rax), %edi
andq $0x0, -0x90(%rbp)
leaq -0x88(%rbp), %rax
movq %rax, -0x98(%rbp)
movb $0x0, -0x88(%rbp)
cmpl $0x51, %edi
jne 0x2d4a
leaq -0x98(%rbp), %rdi
leaq 0x52f7(%rip), %rsi      # 0x803a
callq 0x2370
jmp 0x2d5e
callq 0x2270
movsbl %al, %esi
leaq -0x98(%rbp), %rdi
callq 0x2300
movq %r14, %rdi
pushq $0x1
popq %rsi
callq 0x2230
movq %r12, -0x70(%rbp)
movsbl (%rax), %r15d
movq -0x38(%rbp), %rax
cmpq $0x4, 0x8(%r13,%rax)
pushq $0x1
popq %r12
movl %r12d, %r8d
jne 0x2e20
leaq -0xf0(%rbp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
pushq $0x2
popq %rdx
pushq $-0x1
popq %rcx
callq 0x21f0
movl %r15d, %r13d
movq %rbx, %rdi
leaq 0x5290(%rip), %rsi      # 0x803d
callq 0x3485
pushq $0x2
popq %r15
pushq $0x1
popq %r14
movl %r14d, %r12d
testb %al, %al
jne 0x2e12
movq %rbx, %rdi
leaq 0x5275(%rip), %rsi      # 0x8040
callq 0x3485
pushq $0x3
popq %r15
movl %r14d, %r12d
testb %al, %al
jne 0x2e12
movq %rbx, %rdi
leaq 0x525e(%rip), %rsi      # 0x8043
callq 0x3485
movl %r14d, %r15d
pushq $0x2
popq %r12
testb %al, %al
jne 0x2e12
movq %rbx, %rdi
leaq 0x5247(%rip), %rsi      # 0x8046
callq 0x3485
movzbl %al, %eax
leal 0x1(,%rax,2), %r12d
movl %r14d, %r15d
movq %rbx, %rdi
callq 0x20f0
movl %r15d, %r8d
movl %r13d, %r15d
movl %r15d, %edx
movq -0x38(%rbp), %r15
addl $-0x30, %edx
movq -0x78(%rbp), %rbx
movl %ebx, %ecx
orq -0x68(%rbp), %rcx
leaq -0xf0(%rbp), %r13
movq %r13, %rdi
leaq -0x98(%rbp), %r14
movq %r14, %rsi
movl %r12d, %r9d
callq 0x268e
movq -0x70(%rbp), %r12
movq %r12, %rdi
movq %r13, %rsi
callq 0x34ac
movq %r13, %rdi
callq 0x20f0
movq %r14, %rdi
callq 0x20f0
incq %rbx
movq -0x58(%rbp), %r13
movq -0x50(%rbp), %rax
addq $0x20, %r15
movq %r15, -0x38(%rbp)
addq $0x38, %r12
movq -0x30(%rbp), %r15
jmp 0x2cea
movq -0x60(%rbp), %r14
incq %r14
leaq -0x58(%rbp), %r12
movq %r12, %rdi
callq 0x31fa
addq $0xe0, -0x40(%rbp)
leaq -0xb8(%rbp), %rbx
jmp 0x2c7c
leaq -0xb8(%rbp), %rdi
callq 0x20f0
leaq -0x2f8(%rbp), %rdi
callq 0x2070
addq $0x2d8, %rsp            # imm = 0x2D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x10
popq %rdi
callq 0x2110
movq %rax, %rbx
leaq 0x5112(%rip), %rsi      # 0x8004
movq %rax, %rdi
callq 0x20b0
movq 0xa0ef(%rip), %rsi      # 0xcff0
movq 0xa0b8(%rip), %rdx      # 0xcfc0
movq %rbx, %rdi
callq 0x2310
jmp 0x2f42
pushq $0x10
popq %rdi
callq 0x2110
movq %rax, %rbx
leaq 0x50f7(%rip), %rsi      # 0x801b
movq %rax, %rdi
callq 0x20b0
movq 0xa0bd(%rip), %rsi      # 0xcff0
movq 0xa086(%rip), %rdx      # 0xcfc0
movq %rbx, %rdi
callq 0x2310
movq %rax, %r14
movq -0x30(%rbp), %r15
jmp 0x2fe4
movq %rax, %r14
jmp 0x2f5e
movq %rax, %r14
movq %rbx, %rdi
callq 0x2150
movq -0x30(%rbp), %r15
jmp 0x2fc3
movq %rax, %r14
jmp 0x2f74
movq %rax, %r14
movq %rbx, %rdi
callq 0x2150
movq -0x30(%rbp), %r15
jmp 0x2fcc
jmp 0x2f7c
movq %rax, %r14
jmp 0x2fcc
movq %rax, %r14
testq %r15, %r15
je 0x2ffc
movq -0x30(%rbp), %rbx
addq $-0x38, %rbx
leaq (%rbx,%r15), %rdi
callq 0x20f0
addq $-0x38, %r15
jne 0x2f91
jmp 0x2ffc
jmp 0x2fa4
movq %rax, %r14
movq -0x30(%rbp), %r15
jmp 0x2fb2
jmp 0x2faf
movq %rax, %r14
leaq -0x98(%rbp), %rdi
callq 0x20f0
jmp 0x2fc3
movq %rax, %r14
leaq -0x58(%rbp), %rdi
callq 0x31fa
leaq -0xb8(%rbp), %rdi
callq 0x20f0
leaq -0x2f8(%rbp), %rdi
callq 0x2070
movl $0x348, %ebx            # imm = 0x348
leaq (%r15,%rbx), %rdi
callq 0x20f0
addq $-0x38, %rbx
cmpq $-0x38, %rbx
jne 0x2fe9
movq %r14, %rdi
callq 0x2330