Compare commits
14
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8fdd4c18fd | ||
|
|
c14a29a070 | ||
|
|
3420815c74 | ||
|
|
f076e0e35c | ||
|
|
ceddebcd80 | ||
|
|
8ed07d0334 | ||
|
|
b285704ae1 | ||
|
|
3fd7328f66 | ||
|
|
5b61f0e5d9 | ||
|
|
5f8cabb56a | ||
|
|
67d8fa370d | ||
|
|
5ec8a150cd | ||
|
|
de703651f7 | ||
|
|
d655c852fa |
@@ -86,3 +86,5 @@ dkms.conf
|
|||||||
*.out
|
*.out
|
||||||
*.app
|
*.app
|
||||||
|
|
||||||
|
# Custom
|
||||||
|
bin/*
|
||||||
|
|||||||
+6
-2
@@ -2,6 +2,10 @@ FROM gcc:latest
|
|||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
COPY bin/Bowling /app/
|
COPY rolls.txt /app/
|
||||||
|
COPY include/* /app/include/
|
||||||
|
COPY src/* /app/src/
|
||||||
|
|
||||||
CMD ["./Bowling"]
|
RUN g++ src/*.cpp -o Bowling
|
||||||
|
|
||||||
|
CMD ["./Bowling", "rolls.txt"]
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
#ifndef FILEHELPER_H
|
|
||||||
#define FILEHELPER_H
|
|
||||||
|
|
||||||
class FileHelper {
|
|
||||||
public:
|
|
||||||
FileHelper();
|
|
||||||
|
|
||||||
~FileHelper();
|
|
||||||
|
|
||||||
static bool FileExists(char *path);
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
#ifndef FILEREADER_H
|
|
||||||
#define FILEREADER_H
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
class FileReader {
|
|
||||||
public:
|
|
||||||
FileReader();
|
|
||||||
|
|
||||||
~FileReader();
|
|
||||||
|
|
||||||
static std::string GetFile(char *path);
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
#ifndef NUMBERHELPER_H
|
|
||||||
#define NUMBERHELPER_H
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
class NumberHelper {
|
|
||||||
public:
|
|
||||||
NumberHelper();
|
|
||||||
|
|
||||||
~NumberHelper();
|
|
||||||
|
|
||||||
static vector<int> GetNumbers(string csv);
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
#ifndef PRINTFRAMES_H
|
|
||||||
#define PRINTFRAMES_H
|
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
class PrintFrames {
|
|
||||||
public:
|
|
||||||
PrintFrames();
|
|
||||||
|
|
||||||
~PrintFrames();
|
|
||||||
|
|
||||||
static void PrintHeader(vector<int> rolls);
|
|
||||||
static void PrintValue(vector<int> rolls);
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,3 +1,9 @@
|
|||||||
# Bowling
|
# Bowling
|
||||||
|
|
||||||
If you want to try out the project, please use git clone with the HTTPS link to the repo, and not the SSH link, as only the owner can pull and push via SSH.
|
To run the project, simply follow these steps:
|
||||||
|
1. `git clone https://git.rbwr.dk/owner/Bowling.git`
|
||||||
|
2. `cd Bowling/`
|
||||||
|
2. `docker build -t bowling .`
|
||||||
|
3. `docker run --rm bowling`
|
||||||
|
|
||||||
|
To change bowling score, simply edit the `rolls.txt` file, and build the docker image again.
|
||||||
BIN
Binary file not shown.
@@ -0,0 +1,13 @@
|
|||||||
|
#ifndef FILEHELPER_H
|
||||||
|
#define FILEHELPER_H
|
||||||
|
|
||||||
|
class FileHelper {
|
||||||
|
public:
|
||||||
|
FileHelper() = default;
|
||||||
|
|
||||||
|
~FileHelper() = default;
|
||||||
|
|
||||||
|
static bool fileExists(char *path);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
#ifndef FILEREADER_H
|
||||||
|
#define FILEREADER_H
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
class FileReader {
|
||||||
|
public:
|
||||||
|
FileReader() = default;
|
||||||
|
|
||||||
|
~FileReader() = default;
|
||||||
|
|
||||||
|
static string getFile(char *path);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
#ifndef NUMBERHELPER_H
|
||||||
|
#define NUMBERHELPER_H
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
class NumberHelper {
|
||||||
|
public:
|
||||||
|
NumberHelper() = default;
|
||||||
|
|
||||||
|
~NumberHelper() = default;
|
||||||
|
|
||||||
|
static vector<int> getRolls(string csv);
|
||||||
|
static bool validateRolls(vector<int> rolls);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
#ifndef PRINTFRAMES_H
|
||||||
|
#define PRINTFRAMES_H
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
class PrintFrames {
|
||||||
|
public:
|
||||||
|
PrintFrames() = default;
|
||||||
|
|
||||||
|
~PrintFrames() = default;
|
||||||
|
|
||||||
|
static void printHeader(vector<int> rolls);
|
||||||
|
static void printValue(vector<int> rolls);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -8,11 +8,11 @@ using namespace std;
|
|||||||
|
|
||||||
class ScoreCalculator {
|
class ScoreCalculator {
|
||||||
public:
|
public:
|
||||||
ScoreCalculator();
|
ScoreCalculator() = default;
|
||||||
|
|
||||||
~ScoreCalculator();
|
~ScoreCalculator() = default;
|
||||||
|
|
||||||
static int GetScore(vector<int> rolls);
|
static int getScore(vector<int> rolls);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -1,4 +1 @@
|
|||||||
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5
|
2, 3, 5, 4, 9, 1, 2, 5, 3, 2, 4, 2, 3, 3, 4, 6, 10, 3, 2,
|
||||||
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10
|
|
||||||
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 9, 1
|
|
||||||
2, 3, 5, 4, 9, 1, 2, 5, 3, 2, 4, 2, 3, 3, 4, 6, 10, 3, 2
|
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
10, 3, 2, 2, 3, 5, 4, 9, 1, 2, 5, 3, 2, 4, 2, 3, 3, 4, 6
|
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5
|
||||||
+2
-5
@@ -1,10 +1,7 @@
|
|||||||
#include "../Include/FileHelper.h"
|
#include "../include/FileHelper.h"
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
FileHelper::FileHelper() {};
|
bool FileHelper::fileExists(char *path){
|
||||||
FileHelper::~FileHelper() {};
|
|
||||||
|
|
||||||
bool FileHelper::FileExists(char *path){
|
|
||||||
struct stat s;
|
struct stat s;
|
||||||
|
|
||||||
// Check if file exists, and if it isn't a folder.
|
// Check if file exists, and if it isn't a folder.
|
||||||
|
|||||||
+6
-8
@@ -1,16 +1,14 @@
|
|||||||
#include "../Include/FileReader.h"
|
#include "../include/FileReader.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
FileReader::FileReader() {};
|
string FileReader::getFile(char *path){
|
||||||
FileReader::~FileReader() {};
|
ifstream file(path);
|
||||||
|
|
||||||
std::string FileReader::GetFile(char *path){
|
|
||||||
std::ifstream file(path);
|
|
||||||
|
|
||||||
std::string line;
|
string line;
|
||||||
|
|
||||||
std::getline(file, line);
|
// There is only one line in the file
|
||||||
|
getline(file, line);
|
||||||
|
|
||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
|
|||||||
+18
-10
@@ -1,19 +1,27 @@
|
|||||||
#include "../Include/NumberHelper.h"
|
#include "../include/NumberHelper.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
NumberHelper::NumberHelper() {};
|
vector<int> NumberHelper::getRolls(string csv){
|
||||||
NumberHelper::~NumberHelper() {};
|
vector<int> rolls;
|
||||||
|
stringstream ss(csv);
|
||||||
std::vector<int> NumberHelper::GetNumbers(std::string csv){
|
string number;
|
||||||
std::vector<int> rolls;
|
|
||||||
std::stringstream ss(csv);
|
|
||||||
std::string number;
|
|
||||||
|
|
||||||
while (std::getline(ss, number, ',')) {
|
// Get number from the CSV file, split by comma, and convert to int.
|
||||||
rolls.push_back(std::stoi(number));
|
while (getline(ss, number, ',')) {
|
||||||
|
rolls.push_back(stoi(number));
|
||||||
}
|
}
|
||||||
|
|
||||||
return rolls;
|
return rolls;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool NumberHelper::validateRolls(vector<int> rolls){
|
||||||
|
for(int i = 0; i < rolls.size(); ++i) {
|
||||||
|
if(rolls[i] > 10 || rolls[i] < 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
+8
-8
@@ -1,10 +1,7 @@
|
|||||||
#include "../Include/PrintFrames.h"
|
#include "../include/PrintFrames.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
PrintFrames::PrintFrames() {};
|
void PrintFrames::printHeader(vector<int> rolls){
|
||||||
PrintFrames::~PrintFrames() {};
|
|
||||||
|
|
||||||
void PrintFrames::PrintHeader(vector<int> rolls){
|
|
||||||
int frame = 0;
|
int frame = 0;
|
||||||
int i = 1;
|
int i = 1;
|
||||||
|
|
||||||
@@ -13,7 +10,7 @@ void PrintFrames::PrintHeader(vector<int> rolls){
|
|||||||
|
|
||||||
// Strike
|
// Strike
|
||||||
if (rolls[frame] == 10) {
|
if (rolls[frame] == 10) {
|
||||||
// If we're on our last frame, and roll a 10.
|
// If we're on our last frame, and roll a strike, we're given two bonus rolls.
|
||||||
if (frame + 3 == rolls.size() && rolls[frame - 3] == 10) {
|
if (frame + 3 == rolls.size() && rolls[frame - 3] == 10) {
|
||||||
cout << " f" << i << " |" << endl;
|
cout << " f" << i << " |" << endl;
|
||||||
break;
|
break;
|
||||||
@@ -25,6 +22,7 @@ void PrintFrames::PrintHeader(vector<int> rolls){
|
|||||||
|
|
||||||
// Spare
|
// Spare
|
||||||
else if (rolls[frame] + rolls[frame + 1] == 10) {
|
else if (rolls[frame] + rolls[frame + 1] == 10) {
|
||||||
|
// If we're on our last frame, and roll a spare, we're given a bonus roll.
|
||||||
if (frame + 3 == rolls.size() && rolls[frame] + rolls[frame + 1] == 10)
|
if (frame + 3 == rolls.size() && rolls[frame] + rolls[frame + 1] == 10)
|
||||||
{
|
{
|
||||||
cout << " f" << i << " |" << endl;
|
cout << " f" << i << " |" << endl;
|
||||||
@@ -43,6 +41,7 @@ void PrintFrames::PrintHeader(vector<int> rolls){
|
|||||||
|
|
||||||
++i;
|
++i;
|
||||||
|
|
||||||
|
// No more frames
|
||||||
if (frame == rolls.size()) {
|
if (frame == rolls.size()) {
|
||||||
cout << "|" << endl;
|
cout << "|" << endl;
|
||||||
break;
|
break;
|
||||||
@@ -50,7 +49,7 @@ void PrintFrames::PrintHeader(vector<int> rolls){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrintFrames::PrintValue(vector<int> rolls){
|
void PrintFrames::printValue(vector<int> rolls){
|
||||||
int frame = 0;
|
int frame = 0;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
@@ -58,7 +57,7 @@ void PrintFrames::PrintValue(vector<int> rolls){
|
|||||||
|
|
||||||
// Strike
|
// Strike
|
||||||
if (rolls[frame] == 10) {
|
if (rolls[frame] == 10) {
|
||||||
// If we're on our last frame, and roll a 10.
|
// If we're on our last frame, and roll a strike, we're given two bonus rolls.
|
||||||
if (frame + 3 == rolls.size() && rolls[frame - 3] == 10) {
|
if (frame + 3 == rolls.size() && rolls[frame - 3] == 10) {
|
||||||
if (rolls[frame + 1] == 10 && rolls[frame + 2] == 10) {
|
if (rolls[frame + 1] == 10 && rolls[frame + 2] == 10) {
|
||||||
cout << "X, X, X|" << endl;
|
cout << "X, X, X|" << endl;
|
||||||
@@ -85,6 +84,7 @@ void PrintFrames::PrintValue(vector<int> rolls){
|
|||||||
|
|
||||||
// Spare
|
// Spare
|
||||||
else if (rolls[frame] + rolls[frame + 1] == 10) {
|
else if (rolls[frame] + rolls[frame + 1] == 10) {
|
||||||
|
// If we're on our last frame, and roll a spare, we're given a bonus roll.
|
||||||
if (frame + 3 == rolls.size() && rolls[frame] + rolls[frame + 1] == 10)
|
if (frame + 3 == rolls.size() && rolls[frame] + rolls[frame + 1] == 10)
|
||||||
{
|
{
|
||||||
cout << rolls[frame] << ", /" << ", " << rolls[frame + 1] << "|" << endl;
|
cout << rolls[frame] << ", /" << ", " << rolls[frame + 1] << "|" << endl;
|
||||||
|
|||||||
+10
-11
@@ -1,16 +1,13 @@
|
|||||||
#include "../Include/ScoreCalculator.h"
|
#include "../include/ScoreCalculator.h"
|
||||||
|
|
||||||
ScoreCalculator::ScoreCalculator() {};
|
int ScoreCalculator::getScore(vector<int> rolls) {
|
||||||
ScoreCalculator::~ScoreCalculator() {};
|
|
||||||
|
|
||||||
int ScoreCalculator::GetScore(vector<int> rolls) {
|
|
||||||
int score = 0;
|
int score = 0;
|
||||||
int frame = 0;
|
int frame = 0;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
// Strike
|
// Strike
|
||||||
if (rolls[frame] == 10) {
|
if (rolls[frame] == 10) {
|
||||||
// If we're on our last frame, and roll a 10.
|
// If we're on our last frame, and roll a strike, we're given two bonus rolls.
|
||||||
if (frame + 3 == rolls.size() && rolls[frame - 3] == 10) {
|
if (frame + 3 == rolls.size() && rolls[frame - 3] == 10) {
|
||||||
score += 10 + rolls[frame + 1] + rolls[frame + 2];
|
score += 10 + rolls[frame + 1] + rolls[frame + 2];
|
||||||
break;
|
break;
|
||||||
@@ -18,11 +15,11 @@ int ScoreCalculator::GetScore(vector<int> rolls) {
|
|||||||
|
|
||||||
score += 10 + rolls[frame + 1] + rolls[frame + 2];
|
score += 10 + rolls[frame + 1] + rolls[frame + 2];
|
||||||
frame += 1;
|
frame += 1;
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Spare
|
// Spare
|
||||||
if (rolls[frame] + rolls[frame + 1] == 10) {
|
else if (rolls[frame] + rolls[frame + 1] == 10) {
|
||||||
|
// If we're on our last frame, and roll a spare, we're given a bonus roll.
|
||||||
if (frame + 3 == rolls.size() && rolls[frame] + rolls[frame + 1] == 10)
|
if (frame + 3 == rolls.size() && rolls[frame] + rolls[frame + 1] == 10)
|
||||||
{
|
{
|
||||||
score += 10 + rolls[frame + 1];
|
score += 10 + rolls[frame + 1];
|
||||||
@@ -31,13 +28,15 @@ int ScoreCalculator::GetScore(vector<int> rolls) {
|
|||||||
|
|
||||||
score += 10 + rolls[frame + 2];
|
score += 10 + rolls[frame + 2];
|
||||||
frame += 2;
|
frame += 2;
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open Frame
|
// Open Frame
|
||||||
score += rolls[frame] + rolls[frame + 1];
|
else {
|
||||||
frame += 2;
|
score += rolls[frame] + rolls[frame + 1];
|
||||||
|
frame += 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// No more frames
|
||||||
if (frame == rolls.size()) {
|
if (frame == rolls.size()) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
+16
-11
@@ -1,10 +1,10 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "../Include/FileReader.h"
|
#include "../include/FileReader.h"
|
||||||
#include "../Include/FileHelper.h"
|
#include "../include/FileHelper.h"
|
||||||
#include "../Include/NumberHelper.h"
|
#include "../include/NumberHelper.h"
|
||||||
#include "../Include/ScoreCalculator.h"
|
#include "../include/ScoreCalculator.h"
|
||||||
#include "../Include/PrintFrames.h"
|
#include "../include/PrintFrames.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@@ -14,18 +14,23 @@ int main(int argc, char *argv[]) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!FileHelper::FileExists(argv[1])) {
|
if (!FileHelper::fileExists(argv[1])) {
|
||||||
cerr << "Filepath: " << argv[1] << " doesn't exist.";
|
cerr << "Filepath: " << argv[1] << " doesn't exist.";
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
string file = FileReader::GetFile(argv[1]);
|
string file = FileReader::getFile(argv[1]);
|
||||||
vector<int> rolls = NumberHelper::GetNumbers(file);
|
vector<int> rolls = NumberHelper::getRolls(file);
|
||||||
|
|
||||||
PrintFrames::PrintHeader(rolls);
|
if (!NumberHelper::validateRolls(rolls)) {
|
||||||
PrintFrames::PrintValue(rolls);
|
cerr << "Non-valid number in rolls.";
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int score = ScoreCalculator::GetScore(rolls);
|
PrintFrames::printHeader(rolls);
|
||||||
|
PrintFrames::printValue(rolls);
|
||||||
|
|
||||||
|
int score = ScoreCalculator::getScore(rolls);
|
||||||
cout << "Score: " << score << endl;
|
cout << "Score: " << score << endl;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user