176 lines
6.6 KiB
C++
176 lines
6.6 KiB
C++
/*
|
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
|
* Click nbfs://nbhost/SystemFileSystem/Templates/cppFiles/main.cc to edit this template
|
|
*/
|
|
|
|
/*
|
|
* File: main.cpp
|
|
* Author: caleb
|
|
*
|
|
* Created on March 4, 2024, 7:18 PM
|
|
*/
|
|
|
|
#include <iostream>
|
|
#include <ncurses.h>
|
|
#include <vector>
|
|
#include <map>
|
|
#include <algorithm>
|
|
|
|
using namespace std;
|
|
#include "rockPaperScissors.h"
|
|
#include "main.h"
|
|
#include "2DArrayOperations.h"
|
|
#include "binarySearch.h"
|
|
|
|
int main(){
|
|
|
|
std::vector<std::vector<int>> vector;
|
|
std::vector<std::tuple<int, int>> highlightTuple; // collection of tuples to highlight
|
|
std::tuple result = {0, 0};
|
|
int currentResult;
|
|
int ch;
|
|
static int selection = 0;
|
|
static int * selectionPointer = &selection;
|
|
initscr();
|
|
raw();
|
|
keypad(stdscr, TRUE);
|
|
noecho();
|
|
//clear();
|
|
|
|
do {
|
|
switch(ch) {
|
|
case KEY_UP:
|
|
--selection;
|
|
break;
|
|
|
|
case KEY_DOWN:
|
|
++selection;
|
|
break;
|
|
case '\n':
|
|
getch();
|
|
endwin();
|
|
|
|
switch (selection) {
|
|
case 0:
|
|
gameLoop();
|
|
break;
|
|
case 1:
|
|
attrset(A_NORMAL);
|
|
endwin();
|
|
cout << "\033[2J\033[1;1H"; // Clear screen unicode sequence
|
|
highlightTuple.clear();
|
|
vector = random2DArray(10, 10);
|
|
std::sort(vector.begin(), vector.end());
|
|
//printf("2D Vector: %s \n", printVector(vector).c_str());
|
|
printf("Linear search is being used to locate the tuples to highlight!\n");
|
|
printf("getAverage: %i\n", getAverage(vector));
|
|
printf("getRowTotal 0: %i\n", getRowTotal(vector, 0));
|
|
printf("getColumnTotal 0: %i\n", getColumnTotal(vector, 0));
|
|
|
|
currentResult = getHighestInRow(vector, 0);
|
|
highlightTuple.emplace_back(linearSearch(vector, currentResult));
|
|
printf("getHighestInRow 0: %i\n", currentResult);
|
|
printf("tuple result: %i, %i\n", get<0>(highlightTuple[0]), get<1>(highlightTuple[0]));
|
|
|
|
|
|
currentResult = getHighestInColumn(vector, 0);
|
|
highlightTuple.emplace_back(linearSearch(vector, currentResult));
|
|
printf("getHighestInColumn 0: %i\n", currentResult);
|
|
printf("tuple result: %i, %i\n", get<0>(highlightTuple[1]), get<1>(highlightTuple[1]));
|
|
|
|
currentResult = getLowestInRow(vector, 3);
|
|
highlightTuple.emplace_back(linearSearch(vector, currentResult));
|
|
printf("getLowestInRow 3: %i\n", getLowestInRow(vector, 3));
|
|
printf("tuple result: %i, %i\n", get<0>(highlightTuple[2]), get<1>(highlightTuple[2]));
|
|
|
|
currentResult = getLowestInColumn(vector, 3);
|
|
highlightTuple.emplace_back(linearSearch(vector, currentResult));
|
|
printf("getLowestInColumn 3: %i\n", getLowestInColumn(vector, 3));
|
|
printf("tuple result: %i, %i\n", get<0>(highlightTuple[3]), get<1>(highlightTuple[3]));
|
|
|
|
printf("2D Vector: %s \n", printVector(vector, highlightTuple).c_str());
|
|
cout << "Press Enter to Continue";
|
|
getchar();
|
|
attron(A_NORMAL);
|
|
break;
|
|
case 2:
|
|
attrset(A_NORMAL);
|
|
endwin();
|
|
cout << "\033[2J\033[1;1H"; // Clear screen unicode sequence
|
|
vector = random2DArray(10, 10);
|
|
std::sort(vector.begin(), vector.end());
|
|
printf("2D Vector:\n%s\n", printVector(vector).c_str());
|
|
printf("getHighestInRow 0: %i\n", getHighestInRow(vector, 0));
|
|
result = binarySearch(vector, getHighestInRow(vector, 0));
|
|
printf("binary search for results from getHigestInARow(0): %i, %i\n", get<0>(result), get<1>(result));
|
|
cout << "Press Enter to Continue";
|
|
getchar();
|
|
attron(A_NORMAL);
|
|
break;
|
|
case 3:
|
|
attrset(A_NORMAL);
|
|
endwin();
|
|
cout << "\033[2J\033[1;1H"; // Clear screen unicode sequence
|
|
printf("Highlighting every other tuple...\n");
|
|
vector = random2DArray(10, 10);
|
|
std::sort(vector.begin(), vector.end());
|
|
highlightTuple = highlightEveryOther(10, 10);
|
|
printf("2D Vector:\n%s\n", printVector(vector, highlightTuple).c_str());
|
|
cout << "Press Enter to Continue";
|
|
getchar();
|
|
attron(A_NORMAL);
|
|
break;
|
|
|
|
}
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
// Ensure selection stays within bounds
|
|
selection = (selection < 0) ? 0 : selection;
|
|
selection = (selection > 2) ? 3 : selection;
|
|
//std::system("clear");
|
|
move(0, 0);
|
|
printw("%s", printMenu(selectionPointer).c_str());
|
|
refresh();
|
|
} while ((ch = getch()) != '#');
|
|
|
|
|
|
|
|
getch();
|
|
endwin();
|
|
}
|
|
|
|
|
|
std::string printMenu(int* selection) {
|
|
const int ARRAY_SIZE = 4;
|
|
std::string outputString = "";
|
|
std::string cursor[ARRAY_SIZE] = {"> ", " ", " ", " "};
|
|
std::string menu[ARRAY_SIZE] = {"Rock Paper Scissors", "2D Arrays (demonstrates linear search, too!)", "Binary Search", "Test color highlighting"};
|
|
//printf("%i", *selection);
|
|
/*
|
|
if (*selection >= ARRAY_SIZE - 1) {
|
|
*selection = 0;
|
|
}
|
|
if (*selection < 0) {
|
|
*selection = ARRAY_SIZE - 1;
|
|
}
|
|
*/
|
|
|
|
std::string temp;
|
|
for (int j = 0; j < *selection; ++j) {
|
|
temp = cursor[j];
|
|
cursor[j] = cursor[j + 1];
|
|
cursor[j + 1] = temp;
|
|
}
|
|
//cursor[0] = temp;
|
|
outputString.append("Use the arrow keys to navigate the menu. Press # to exit.\n");
|
|
for (int i = 0; i < ARRAY_SIZE; ++i) {
|
|
outputString.append(cursor[i]);
|
|
outputString.append(menu[i]);
|
|
outputString.append("\n");
|
|
}
|
|
return outputString;
|
|
}
|