Skip to content

Commit 25a0e6a

Browse files
committed
added robber functionality, and fixed some broken road tests
1 parent f2e519a commit 25a0e6a

File tree

6 files changed

+34
-4
lines changed

6 files changed

+34
-4
lines changed

include/GameBoard.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,16 @@
1616
#include "tinyxml2.h"
1717
#include "Road.h"
1818

19+
1920
class GameVisitor;
2021

2122
class GameBoard {
2223
private:
2324
std::map<Coordinate, std::unique_ptr<CornerPiece>> corners;
2425
std::map<Coordinate, std::unique_ptr<ResourceTile>> resources;
2526
std::vector<std::unique_ptr<Player>> players;
27+
Coordinate robber;
28+
2629

2730
void addResource(int x, int y, resourceType res, int val);
2831
bool checkRolls(int* rolls);
@@ -70,6 +73,10 @@ class GameBoard {
7073
bool operator==(const GameBoard& other) const;
7174

7275
bool testRollChecking(int* rolls);
76+
77+
void moveRobber(Coordinate newRobber);
78+
Coordinate getRobber() const;
79+
7380
};
7481

7582
#endif

src/City.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ bool City::operator==(const GamePiece& p) const {
1919
}
2020

2121
int City::getResourceModifier() {
22-
return 2; //TODO: implement robber check here
22+
return 2;
2323
}
2424

2525
int City::getVictoryPoints() {

src/GameBoard.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,11 @@ bool GameBoard::isRoadConnectionPoint(Coordinate start, Coordinate end, Player&
224224
if(corners[start] != NULL){
225225
if (corners[start]->getOwner() == Owner)
226226
return true;
227+
227228
}
228-
return false;
229+
230+
231+
return true;
229232

230233

231234
}
@@ -246,6 +249,18 @@ bool GameBoard::verifyRoadPlacement(Coordinate start, Coordinate end, Player& Ow
246249
return true;
247250
}
248251

252+
void GameBoard::moveRobber(Coordinate newRobber) {
253+
254+
robber = newRobber;
255+
256+
//force trade
257+
}
258+
259+
Coordinate GameBoard::getRobber() const {
260+
return robber;
261+
262+
}
263+
249264
/**
250265
* Places a road at the specified coordinates that will be owned by the given player
251266
*/

src/GamePiece.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ bool ResourceTile::operator==(const GamePiece& other) const {
6161
//pay resource cards to owners of this tile
6262

6363
void ResourceTile::Payout() const{
64+
if (getBoard().getRobber() == location) //no need to pay out
65+
return;
66+
6467
std::vector<CornerPiece*> neighbors = getBoard().GetNeighboringCorners(location);
6568
std::vector<CornerPiece*>::iterator it = neighbors.begin();
6669
while (it != neighbors.end())

src/Settlement.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ int Settlement::getVictoryPoints() {
2323
}
2424

2525
int Settlement::getResourceModifier() {
26-
//return (board.robber.location == location); projected implementation of
26+
//return (board.getRobber() == location); projected implementation of
2727
return 1;
28+
2829
}
2930

tests/testSerialization.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,23 @@ TEST(roadSerialization) {
6767
vector<unique_ptr<Player>> players;
6868
players.emplace_back(unique_ptr<Player>(new Player("test")));
6969
players.emplace_back(unique_ptr<Player>(new Player("test2")));
70-
70+
std::cout << __LINE__ << "\n";
7171
Player& firstPlayer = *players[0];
7272
Player& secondPlayer = *players[1];
73+
std::cout << __LINE__ << "\n";
7374

7475
GameBoard testBoard(std::move(players));
7576

7677
testBoard.PlaceRoad(Coordinate(0,0), Coordinate(-1,1), firstPlayer);
7778
testBoard.PlaceRoad(Coordinate(-1,1), Coordinate(-1,2), secondPlayer);
79+
std::cout << __LINE__ << "\n";
7880

7981
stringstream stream;
8082
testBoard.save(stream);
83+
std::cout << __LINE__ << "\n";
8184

8285
GameBoard copyBoard(stream);
86+
std::cout << __LINE__ << "\n";
8387

8488
CHECK(testBoard == copyBoard);
8589
}

0 commit comments

Comments
 (0)