Example #1
0
NCurseGui::NCurseGui(std::pair<std::size_t, std::size_t> dim)
{
  struct winsize w;
  if ((ioctl(0, TIOCGWINSZ, &w)) == -1)
    throw ResolutionException("Unable to get terminal resolution.");
  if (dim.first <= 5 || dim.second <= 5
      || dim.first > w.ws_row || dim.second > w.ws_col / 2)
    throw ResolutionException("Invalid resolution.");
  _paused = false;
  _width = dim.first * 2;
  _height = dim.second;
  initscr();
  start_color();
  init_pair(1, COLOR_BLACK, COLOR_GREEN);
  init_pair(2, COLOR_BLACK, COLOR_RED);
  init_pair(3, COLOR_BLACK, COLOR_BLUE);
  init_pair(4, COLOR_BLACK, COLOR_CYAN);
  init_pair(5, COLOR_BLACK, COLOR_YELLOW);
  raw();
  noecho();
  cbreak();
  curs_set(0);
  keypad(stdscr, TRUE);
  refresh();
  if (!(_win = newwin(_height + 1, _width + 2, 0, 0)))
    throw NCurseException("Unable to open the window.");
  box(_win, 0, 0);
}
void TestCampaign::resolveOneCube(RubikColor colors[]) {
    Robot robot;

    Rubik rubik = makeRubik();
    rubik.resolve(colors, &robot);

    Rubik rubik2 = makeRubik();

    std::vector<std::string> moves = rubik.getMoves();
    rubik2.applyMoves(moves);

    rubik2.changeReferential(colors[4]);

    if (rubik2.verifyRubikColors(colors))
    {
        this->passed++;
        this->nbMoves += rubik.getMoves().size();
        robot.sendRubikMoves(rubik2.getMoves());
        this->nbRobotMoves += robot.getRobotMoves().size();
    }
    else {
        this->failed++;
        std::cout << setcolor(RubikColor::RED) << "FAILED" << setcolor(RubikColor::WHITE) << "(passed " << this->passed << ", failed " << this->failed << ")" << std::endl;
        std::cout << "Expected colors :" << std::endl;
        for (int i = 0; i < 9; i++) {
            std::cout << setcolor(colors[i]) << "#";
            if (i % 3 == 2) {
                std::cout << std::endl;
            }
        }

        std::cout << setcolor(RubikColor::WHITE) << std::endl;
        std::cout << "Moves :";
        std::vector<std::string> moves = rubik.getMoves();
        int size = moves.size();
        for (int i = 0; i < size; i++) {
            std::cout << " " << moves[i];
        }
        std::cout << std::endl;

        std::cout << setcolor(RubikColor::WHITE) << "---------------------------------------------" << std::endl;
        std::cout << "Rubik2:" << std::endl;
        rubik2.printCube();
        throw ResolutionException("Incorrect resolution", colors);
    }
}