Skip to content

Commit a576b2c

Browse files
committed
Fixed an error where the desert tile was not being handled properly in the roll tile checking, added test cases for the roll tile checking
1 parent 4194099 commit a576b2c

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

include/GameBoard.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ class GameBoard
4343
void PlaceSettlement(Coordinate location, Player& Owner);
4444

4545
void init_resources();
46+
47+
bool testRollChecking(int* rolls);
4648
};
4749

4850
#endif

src/GameBoard.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,10 @@ void GameBoard::init_resources()
101101
{
102102
std::srand(std::time(0));
103103

104-
resourceType resources[] = {BRICK, BRICK, BRICK, STONE, STONE, STONE, WHEAT, WHEAT, WHEAT, WHEAT, WOOD, WOOD, WOOD, WOOD, SHEEP, SHEEP, SHEEP, SHEEP, DESERT};
104+
resourceType resources[] = {BRICK, BRICK, BRICK, STONE, STONE, STONE, WHEAT, WHEAT, WHEAT, WHEAT, WOOD, WOOD, WOOD, WOOD, SHEEP, SHEEP, SHEEP, SHEEP};
105105
random_shuffle(&resources[0], &resources[19]);
106106

107-
int rolls[] = {2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11};
107+
int rolls[] = {0, 2, 3, 3, 4, 4, 5, 5, 6, 6, 8, 8, 9, 9, 10, 10, 11, 11, 12};
108108
while (!checkRolls(rolls))
109109
{
110110
random_shuffle(&rolls[0], &rolls[18]);
@@ -115,17 +115,17 @@ void GameBoard::init_resources()
115115

116116

117117

118-
int rollCount = 0;
118+
int resourceCount = 0;
119119
for (int i = 0; i<19; i++)
120120
{
121-
if (resources[i]==DESERT)
121+
if (rolls[i] == 0)
122122
{
123-
addResource(xcoords[i], ycoords[i], resources[i], 0);
123+
addResource(xcoords[i], ycoords[i], DESERT, 0);
124124
}
125125
else
126126
{
127-
addResource(xcoords[i], ycoords[i], resources[i], rolls[rollCount]);
128-
rollCount++;
127+
addResource(xcoords[i], ycoords[i], resources[resourceCount], rolls[i]);
128+
resourceCount++;
129129
}
130130
}
131131

@@ -317,3 +317,8 @@ bool GameBoard::checkRolls(int* rolls)
317317

318318
return true;
319319
}
320+
321+
bool GameBoard::testRollChecking(int* rolls)
322+
{
323+
return checkRolls(rolls);
324+
}

tests/test_GameBoard.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,17 @@ TEST(loadFile_simple){
2020
CHECK(test_board->load_Board("test_1") == 0);
2121
delete(test_board);
2222
}
23+
24+
TEST(randomize_rolls_fail)
25+
{
26+
GameBoard * test_board = new GameBoard;
27+
CHECK(test_board->testRollChecking({0, 2, 3, 3, 4, 4, 5, 5, 6, 6, 8, 8, 9, 9, 10, 10, 11, 11, 12}) == false);
28+
delete(test_board);
29+
}
30+
31+
TEST(randomize_rolls_pass)
32+
{
33+
GameBoard * test_board = new GameBoard;
34+
CHECK(test_board->testRollChecking({9, 11, 5, 4, 0, 3, 4, 2, 10, 8, 3, 6, 9, 11, 5, 10, 6, 12, 8}) == true);
35+
delete(test_board);
36+
}

0 commit comments

Comments
 (0)