7 Commits
Author SHA1 Message Date
owner 05ba979f58 Testing roll combination validation 2025-03-26 12:44:11 +01:00
owner 8fdd4c18fd Validate if roll is higher than 10, and lower than 0 2025-03-26 12:05:45 +01:00
owner c14a29a070 Add comment 2025-03-19 11:58:53 +01:00
owner 3420815c74 Update README.md 2025-03-19 10:56:40 +00:00
owner f076e0e35c Remove unused text file 2025-03-19 11:51:10 +01:00
owner ceddebcd80 Merge pull request 'Remove unused folder' (#5) from cleanup into main
Reviewed-on: #5
2025-03-19 10:50:03 +00:00
owner b285704ae1 Merge pull request 'cleanup' (#4) from cleanup into main
Reviewed-on: #4
2025-03-19 10:48:15 +00:00
9 changed files with 39 additions and 4 deletions
+3 -3
View File
@@ -1,11 +1,11 @@
FROM gcc:latest FROM gcc:latest
RUN g++ src/*.cpp -o Bowling
WORKDIR /app WORKDIR /app
COPY rolls.txt /app/ COPY rolls.txt /app/
COPY include/* /app/include/
COPY src/* /app/src/
RUN g++ src/*.cpp -o Bowling #RUN g++ src/*.cpp -o Bowling
CMD ["./Bowling", "rolls.txt"] CMD ["./Bowling", "rolls.txt"]
+1
View File
@@ -2,6 +2,7 @@
To run the project, simply follow these steps: To run the project, simply follow these steps:
1. `git clone https://git.rbwr.dk/owner/Bowling.git` 1. `git clone https://git.rbwr.dk/owner/Bowling.git`
2. `cd Bowling/`
2. `docker build -t bowling .` 2. `docker build -t bowling .`
3. `docker run --rm bowling` 3. `docker run --rm bowling`
+1
View File
@@ -13,6 +13,7 @@ class NumberHelper {
~NumberHelper() = default; ~NumberHelper() = default;
static vector<int> getRolls(string csv); static vector<int> getRolls(string csv);
static bool validateRolls(vector<int> rolls);
}; };
-1
View File
@@ -1 +0,0 @@
10, 3, 2, 2, 3, 5, 4, 9, 1, 2, 5, 3, 2, 4, 2, 3, 3, 4, 6
+1
View File
@@ -0,0 +1 @@
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10
+1
View File
@@ -0,0 +1 @@
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5
+1
View File
@@ -7,6 +7,7 @@ string FileReader::getFile(char *path){
string line; string line;
// There is only one line in the file
getline(file, line); getline(file, line);
file.close(); file.close();
+27
View File
@@ -1,4 +1,5 @@
#include "../include/NumberHelper.h" #include "../include/NumberHelper.h"
#include <iostream>
#include <string> #include <string>
#include <sstream> #include <sstream>
#include <vector> #include <vector>
@@ -14,4 +15,30 @@ vector<int> NumberHelper::getRolls(string csv){
} }
return rolls; return rolls;
}
bool NumberHelper::validateRolls(vector<int> rolls){
int rollCount = rolls.size();
for(int i = 0; i < rollCount; ++i) {
if(rolls[i] > 10 || rolls[i] < 0) {
cerr << "Number: " << rolls[i] << " is invalid.";
return false;
}
}
// A game can not have less than 12 rolls, and more than 21.
if (rollCount < 12 || rollCount > 21) {
cerr << "Incorrect amount of rolls.";
return false;
}
// 10th frame rule.
if (rollCount == 21) {
if (rolls[18] != 10 && rolls[18] + rolls[19] != 10) {
return false;
}
}
return true;
} }
+4
View File
@@ -22,6 +22,10 @@ int main(int argc, char *argv[]) {
string file = FileReader::getFile(argv[1]); string file = FileReader::getFile(argv[1]);
vector<int> rolls = NumberHelper::getRolls(file); vector<int> rolls = NumberHelper::getRolls(file);
if (!NumberHelper::validateRolls(rolls)) {
return 0;
}
PrintFrames::printHeader(rolls); PrintFrames::printHeader(rolls);
PrintFrames::printValue(rolls); PrintFrames::printValue(rolls);