<commit_before>/*
 * Copyright (C) 2014-2015 <NAME>
 *
 * See the LICENSE file for terms of use.
 */

#include <iomanip>
#include <iostream>
#include <limits>

#include "ConsoleBotView.hpp"

static int numberOfDigits(int number) {
    int digits = 0;
    while (number) {
        number /= 10;
        digits++;
    }
    return digits;
}

void ConsoleBotView::view() {
    while (true) {
        start();
        char mode;
        std::cin >> mode;
        switch (mode) {
            case 't':
                gameWithTime();
                break;
            case 'w':
                gameForWin();
                break;
            case 's':
                gameForScore();
                break;
            case 'q':
                return;
            default:
                sendHelpMessage_impl();
        }
    }
}

void ConsoleBotView::timeNumberMessage() const {
    std::cout << "How many minutes you want to play?" << std::endl;
    std::cout << "Minimum is " << MIN_TIME << " and "
                 "maximum is " << MAX_TIME << std::endl;
    prompt();
}

void ConsoleBotView::winNumberMessage() const {
    int square = getBoardsSquare();
    std::cout << "What score you want to finish the "
                 "game?" << std::endl;
    std::cout << "Minimum is " << square * 2 << " and "
                 "maximum is " << MAX_SCORE << std::endl;
    prompt();
}

void ConsoleBotView::deskSizeMessage() const {
    std::cout << "Please enter size of the game board."
              << std::endl;
    std::cout << "Your board will have x * x square."
              << std::endl;
    std::cout << "(Where x is input size)" << std::endl;
    std::cout << "Minimum size is " << MIN_WIDTH << " and "
                 "maximum is " << MAX_WIDTH << std::endl;
    std::cout << "But try to choose size which "
                 "corresponds to the size of your screen."
              << std::endl;
    prompt();
}

void ConsoleBotView::outputGeneral() const {
    int max = maxDeskNumber();
    int digits = numberOfDigits(max);
    int row_number = game_->desk->getRowNumber();
    for (int i = row_number - 1; i >= 0; i--) {
        std::cout << std::right << std::setw(MAX_INDEX_LENGTH)
                  << i << " ||";
        for (int x = 0; x < row_number; x++) {
            Point point;
            point.col = i;
            point.row = x;
            int width = NUMBER_OF_SPACES + digits;
            std::cout << std::right << std::setw(width)
                      << game_->desk->getDeskNumber(point);
        }
        std::cout << std::endl;
    }
}

void ConsoleBotView::prompt() const {
    std::cout << ">>> ";
}

void ConsoleBotView::typeError() const {
    std::cout << "Error: you must enter the NUMBER" << std::endl;
    std::cout << "Try again: " << std::endl;
    std::cin.clear();
    std::cin.ignore(std::numeric_limits<int>::max(), '\n');
}

void ConsoleBotView::rangeError(TypeOfChecking type) const {
    int max_int = std::numeric_limits<int>::max();
    std::cout << "This number is out of allowable "
                 "range." << std::endl;
    if (type == (SCORE || TIME)) {
        std::cout << "Please enter a POSITIVE INTEGER"
                  << std::endl;
        std::cout << "Maximum is " << max_int << std::endl;
    }
    std::cout << "Try again: " << std::endl;
    std::cin.clear();
    std::cin.ignore(max_int, '\n');
}

bool ConsoleBotView::checkRange(int verifiable,
                                TypeOfChecking type) const {
    switch (type) {
        case BOARDS_SIZE:
            return (verifiable > 0);
        case TIME:
            return (verifiable > 0);
        case SCORE:
            int square = getBoardsSquare();
            return (verifiable >= square * 2);
    }
}

int ConsoleBotView::getBoardsSquare() const {
    int boards_size = game_->desk->getRowNumber();
    return boards_size * boards_size;
}

const GameDesk* ConsoleBotView::getDesk() const {
    return game_->desk.data();
}

void ConsoleBotView::finish_impl(bool fail, int score,
                                 int steps_number) const {
    if (fail) {
        std::cout << "You are loser... Your score is " << score << std::endl;
    } else {
        std::cout << "You are winner! Your score is " << score << std::endl;
    }
    std::cout << "You have completed the game in " << steps_number << " steps." << std::endl;
}<commit_msg>Comment about "cyclic mechanism of ints"<commit_after>/*
 * Copyright (C) 2014-2015 <NAME>
 *
 * See the LICENSE file for terms of use.
 */

#include <iomanip>
#include <iostream>
#include <limits>

#include "ConsoleBotView.hpp"

static int numberOfDigits(int number) {
    int digits = 0;
    while (number) {
        number /= 10;
        digits++;
    }
    return digits;
}

void ConsoleBotView::view() {
    while (true) {
        start();
        char mode;
        std::cin >> mode;
        switch (mode) {
            case 't':
                gameWithTime();
                break;
            case 'w':
                gameForWin();
                break;
            case 's':
                gameForScore();
                break;
            case 'q':
                return;
            default:
                sendHelpMessage_impl();
        }
    }
}

void ConsoleBotView::timeNumberMessage() const {
    std::cout << "How many minutes you want to play?" << std::endl;
    std::cout << "Minimum is " << MIN_TIME << " and "
                 "maximum is " << MAX_TIME << std::endl;
    prompt();
}

void ConsoleBotView::winNumberMessage() const {
    int square = getBoardsSquare();
    std::cout << "What score you want to finish the "
                 "game?" << std::endl;
    std::cout << "Minimum is " << square * 2 << " and "
                 "maximum is " << MAX_SCORE << std::endl;
    prompt();
}

void ConsoleBotView::deskSizeMessage() const {
    std::cout << "Please enter size of the game board."
              << std::endl;
    std::cout << "Your board will have x * x square."
              << std::endl;
    std::cout << "(Where x is input size)" << std::endl;
    std::cout << "Minimum size is " << MIN_WIDTH << " and "
                 "maximum is " << MAX_WIDTH << std::endl;
    std::cout << "But try to choose size which "
                 "corresponds to the size of your screen."
              << std::endl;
    prompt();
}

void ConsoleBotView::outputGeneral() const {
    int max = maxDeskNumber();
    int digits = numberOfDigits(max);
    int row_number = game_->desk->getRowNumber();
    for (int i = row_number - 1; i >= 0; i--) {
        std::cout << std::right << std::setw(MAX_INDEX_LENGTH)
                  << i << " ||";
        for (int x = 0; x < row_number; x++) {
            Point point;
            point.col = i;
            point.row = x;
            int width = NUMBER_OF_SPACES + digits;
            std::cout << std::right << std::setw(width)
                      << game_->desk->getDeskNumber(point);
        }
        std::cout << std::endl;
    }
}

void ConsoleBotView::prompt() const {
    std::cout << ">>> ";
}

void ConsoleBotView::typeError() const {
    std::cout << "Error: you must enter the NUMBER" << std::endl;
    std::cout << "Try again: " << std::endl;
    std::cin.clear();
    std::cin.ignore(std::numeric_limits<int>::max(), '\n');
}

void ConsoleBotView::rangeError(TypeOfChecking type) const {
    int max_int = std::numeric_limits<int>::max();
    std::cout << "This number is out of allowable "
                 "range." << std::endl;
    if (type == (SCORE || TIME)) {
        std::cout << "Please enter a POSITIVE INTEGER"
                  << std::endl;
        std::cout << "Maximum is " << max_int << std::endl;
    }
    std::cout << "Try again: " << std::endl;
    std::cin.clear();
    std::cin.ignore(max_int, '\n');
}

bool ConsoleBotView::checkRange(int verifiable,
                                TypeOfChecking type) const {
    switch (type) {
        case BOARDS_SIZE:
            // By checking that verifiable is greater than
            // zero we make sure that it's less or equal
            // to the allowable maximum for int also.
            // See cyclic mechanism of ints in C++.
            return (verifiable > 0);
        case TIME:
            return (verifiable > 0);
        case SCORE:
            int square = getBoardsSquare();
            return (verifiable >= square * 2);
    }
}

int ConsoleBotView::getBoardsSquare() const {
    int boards_size = game_->desk->getRowNumber();
    return boards_size * boards_size;
}

const GameDesk* ConsoleBotView::getDesk() const {
    return game_->desk.data();
}

void ConsoleBotView::finish_impl(bool fail, int score,
                                 int steps_number) const {
    if (fail) {
        std::cout << "You are loser... Your score is " << score << std::endl;
    } else {
        std::cout << "You are winner! Your score is " << score << std::endl;
    }
    std::cout << "You have completed the game in " << steps_number << " steps." << std::endl;
}
{'fraction_non_alphanumeric': 0.14802887284841754, 'fraction_numerical': 0.003997779011660188, 'mean_word_length': 1.996007984031936, 'pattern_counts': {'":': 0, '<': 253, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '896527', 'n_tokens_mistral': 2751, 'n_tokens_neox': 2654, 'n_words': 745}