#include <cstring>
#include "GuessCorrector.hpp"

GuessCorrector::GuessCorrector(const char *word)
        : m_word(word),
          m_word_length(strlen(word)),
          m_parts_guessed(std::make_shared<std::optional<char>[]>(m_word_length)) {
    for (std::ptrdiff_t i = 0; i < m_word_length; i++) {
        m_parts_guessed[i] = std::nullopt;
    }
}

bool GuessCorrector::has_char(const char to_check) const {
    for (int i = 0; i < m_word_length; ++i) {
        char c = m_word[i];
        if (c == to_check)
            return true;
    }

    return false;
}

void GuessCorrector::add(const char to_add) {
    for (int i = 0; i < m_word_length; i++) {
        char c = m_word[i];
        if (c == to_add)
            m_parts_guessed[i] = to_add;
    }
}

bool GuessCorrector::is_filled_out() const {
    for (int i = 0; i < m_word_length; i++)
        if (m_parts_guessed[i] == std::nullopt)
            return false;

    return true;
}

std::weak_ptr<std::optional<char>[]> GuessCorrector::guessed() const {
    return m_parts_guessed;
}



