set data to NULL by default
This commit is contained in:
parent
76a1ddd26a
commit
388a52eca1
54
main.cpp
54
main.cpp
@ -17,9 +17,11 @@ struct myPair {
|
|||||||
T1 first;
|
T1 first;
|
||||||
T2 second;
|
T2 second;
|
||||||
|
|
||||||
myPair() : first(), second() {}
|
myPair() : first(), second() {
|
||||||
|
}
|
||||||
|
|
||||||
myPair(const T1 &first, const T2 &second) : first(first), second(second) {}
|
myPair(const T1 &first, const T2 &second) : first(first), second(second) {
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// -------- END PAIR IMPL --------
|
// -------- END PAIR IMPL --------
|
||||||
@ -60,6 +62,7 @@ string toString(int x) {
|
|||||||
int max(int a, int b) {
|
int max(int a, int b) {
|
||||||
return a > b ? a : b;
|
return a > b ? a : b;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------- END HELPER FUNCTIONS --------
|
// -------- END HELPER FUNCTIONS --------
|
||||||
|
|
||||||
// -------- START RAII HELPERS--------
|
// -------- START RAII HELPERS--------
|
||||||
@ -111,6 +114,7 @@ public:
|
|||||||
myVec() {
|
myVec() {
|
||||||
capacity = 0;
|
capacity = 0;
|
||||||
length = 0;
|
length = 0;
|
||||||
|
data = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
myVec(size_t size) {
|
myVec(size_t size) {
|
||||||
@ -284,7 +288,7 @@ void bubbleSort(myPair<char, myPair<int, bool> > *a) {
|
|||||||
|
|
||||||
void printScores(int *points, char blacklist) {
|
void printScores(int *points, char blacklist) {
|
||||||
myPair<char, myPair<int, bool> > *arr = static_cast<myPair<char, myPair<int, bool> > *>(alloc(
|
myPair<char, myPair<int, bool> > *arr = static_cast<myPair<char, myPair<int, bool> > *>(alloc(
|
||||||
26 * sizeof(myPair<char, myPair<int, bool> >)));
|
26 * sizeof(myPair<char, myPair<int, bool> >)));
|
||||||
|
|
||||||
for (int i = 0; i < 26; i++) {
|
for (int i = 0; i < 26; i++) {
|
||||||
myPair<char, myPair<int, bool> > p;
|
myPair<char, myPair<int, bool> > p;
|
||||||
@ -316,10 +320,10 @@ void printScores(int *points, char blacklist) {
|
|||||||
for (int i = 25; i > -1; i--) {
|
for (int i = 25; i > -1; i--) {
|
||||||
if (arr[i].second.first != -1) {
|
if (arr[i].second.first != -1) {
|
||||||
pt "Player " << arr[i].first << " has " << arr[i].second.first << " boxes" << (
|
pt "Player " << arr[i].first << " has " << arr[i].second.first << " boxes" << (
|
||||||
(i == 25 || arr[i].second.second) && arr[i].first != blacklist
|
(i == 25 || arr[i].second.second) && arr[i].first != blacklist
|
||||||
? arr[i].second.second
|
? arr[i].second.second
|
||||||
? " (tie)\n"
|
? " (tie)\n"
|
||||||
: " (win)\n"
|
: " (win)\n"
|
||||||
: nl);
|
: nl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -333,11 +337,11 @@ bool isValidMove(int x, int y, char **board) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void addPoint(
|
void addPoint(
|
||||||
int *points,
|
int *points,
|
||||||
char **board,
|
char **board,
|
||||||
int x,
|
int x,
|
||||||
int y,
|
int y,
|
||||||
char player
|
char player
|
||||||
) {
|
) {
|
||||||
if (board[x][y] == ' ') {
|
if (board[x][y] == ' ') {
|
||||||
if (points[normalize(player)] == -1) {
|
if (points[normalize(player)] == -1) {
|
||||||
@ -350,13 +354,13 @@ void addPoint(
|
|||||||
}
|
}
|
||||||
|
|
||||||
void solveVertical(
|
void solveVertical(
|
||||||
int moveX,
|
int moveX,
|
||||||
int moveY,
|
int moveY,
|
||||||
char **board,
|
char **board,
|
||||||
int *points,
|
int *points,
|
||||||
int x,
|
int x,
|
||||||
int y,
|
int y,
|
||||||
char player
|
char player
|
||||||
) {
|
) {
|
||||||
// TODO: fix ambiguity:
|
// TODO: fix ambiguity:
|
||||||
// -
|
// -
|
||||||
@ -384,12 +388,12 @@ void solveVertical(
|
|||||||
}
|
}
|
||||||
|
|
||||||
void solveHorizontal(
|
void solveHorizontal(
|
||||||
int moveX,
|
int moveX,
|
||||||
int moveY,
|
int moveY,
|
||||||
char **board,
|
char **board,
|
||||||
int *points,
|
int *points,
|
||||||
int y,
|
int y,
|
||||||
char player
|
char player
|
||||||
) {
|
) {
|
||||||
if (moveY) {
|
if (moveY) {
|
||||||
if (moveY == y - 1) {
|
if (moveY == y - 1) {
|
||||||
@ -409,7 +413,7 @@ void solveHorizontal(
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (board[moveX][moveY + 2] != ' ' && (board[moveX + 1][moveY + 1] != ' ' && board[moveX - 1][moveY + 1] !=
|
if (board[moveX][moveY + 2] != ' ' && (board[moveX + 1][moveY + 1] != ' ' && board[moveX - 1][moveY + 1] !=
|
||||||
' ')) {
|
' ')) {
|
||||||
addPoint(points, board, moveX, moveY + 1, player);
|
addPoint(points, board, moveX, moveY + 1, player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user