Skip to content

Commit 9ba73b9

Browse files
committed
Merge pull request #14 from Databean/settlement_fix
Fixed settlement issues
2 parents 4ab3d62 + d6e5385 commit 9ba73b9

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

include/GameBoard.h

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class GameBoard {
6767

6868
void save(std::ostream& out);
6969

70+
ResourceTile& getResourceTile(Coordinate location) const;
7071

7172
const std::map<Coordinate, std::unique_ptr<ResourceTile>>& getResources() const;
7273

src/GameBoard.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,13 @@ const map<Coordinate, unique_ptr<ResourceTile>>& GameBoard::getResources() const
224224
return resources;
225225
}
226226

227+
ResourceTile& GameBoard::getResourceTile(Coordinate location) const
228+
{
229+
//return resources.at(location);
230+
231+
return *(resources.find(location)->second);
232+
}
233+
227234
std::vector<Settlement*> GameBoard::GetNeighboringSettlements(
228235
Coordinate location) const {
229236
static Coordinate adjacentCoordDiffs[] = { Coordinate(0, 1), Coordinate(1,
@@ -463,7 +470,9 @@ int GameBoard::FindLongestRoad_FromPoint(Coordinate curr, const Player & owner,
463470

464471

465472
void GameBoard::PlaceSettlement(Coordinate location, Player& Owner){
466-
corners[location] = std::unique_ptr<CornerPiece>(new Settlement(*this, location, Owner));
473+
if(resources.find(location) == resources.end() && !outOfBounds(location))
474+
corners[location] = std::unique_ptr<CornerPiece>(new Settlement(*this, location, Owner));
475+
467476
}
468477

469478
void GameBoard::PlaceCity(Coordinate location, Player& Owner){
@@ -472,6 +481,7 @@ void GameBoard::PlaceCity(Coordinate location, Player& Owner){
472481
}
473482

474483
void GameBoard::UpgradeSettlement(Coordinate location){
484+
if(corners.find(location) != corners.end())
475485
corners[location] = std::unique_ptr<CornerPiece>(new City(*corners[location])); //TODO test for memory leak
476486
}
477487

tests/test_GameBoard.cpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -183,21 +183,22 @@ TEST(longest_road_simple){
183183
}
184184

185185
TEST(payout_simple) {
186-
/*std::vector<std::unique_ptr<Player>> players {};
186+
std::vector<std::unique_ptr<Player>> players {};
187187
players.emplace_back(new Player("tester"));
188188
Player& test_player = *players[0];
189189
GameBoard * test_board = new GameBoard(std::move(players));
190190

191191
test_board->PlaceSettlement(Coordinate(0,2), test_player);
192192

193193

194-
std::map<Coordinate, std::unique_ptr<ResourceTile>>::iterator it =
195-
test_board->getResources().find(Coordinate(0,1));
196-
//test_board->getResources().at(Coordinate(0,1)).Payout(); WTF
194+
195+
test_board->getResourceTile(Coordinate(0,1)).Payout();
196+
197+
197198
CHECK(!(test_player.getWheat() || test_player.getWood() ||
198199
test_player.getOre() || test_player.getBrick() || test_player.getWool()));
199200
delete test_board;
200-
delete &test_player;*/
201+
//delete &test_player;
201202

202203
}
203204

0 commit comments

Comments
 (0)