Skip to content

Commit

Permalink
Merge pull request #14 from Databean/settlement_fix
Browse files Browse the repository at this point in the history
Fixed settlement issues
  • Loading branch information
PickledMonkey committed Mar 31, 2014
2 parents 4ab3d62 + d6e5385 commit 9ba73b9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
1 change: 1 addition & 0 deletions include/GameBoard.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class GameBoard {

void save(std::ostream& out);

ResourceTile& getResourceTile(Coordinate location) const;

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

Expand Down
12 changes: 11 additions & 1 deletion src/GameBoard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,13 @@ const map<Coordinate, unique_ptr<ResourceTile>>& GameBoard::getResources() const
return resources;
}

ResourceTile& GameBoard::getResourceTile(Coordinate location) const
{
//return resources.at(location);

return *(resources.find(location)->second);
}

std::vector<Settlement*> GameBoard::GetNeighboringSettlements(
Coordinate location) const {
static Coordinate adjacentCoordDiffs[] = { Coordinate(0, 1), Coordinate(1,
Expand Down Expand Up @@ -463,7 +470,9 @@ int GameBoard::FindLongestRoad_FromPoint(Coordinate curr, const Player & owner,


void GameBoard::PlaceSettlement(Coordinate location, Player& Owner){
corners[location] = std::unique_ptr<CornerPiece>(new Settlement(*this, location, Owner));
if(resources.find(location) == resources.end() && !outOfBounds(location))
corners[location] = std::unique_ptr<CornerPiece>(new Settlement(*this, location, Owner));

}

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

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

Expand Down
11 changes: 6 additions & 5 deletions tests/test_GameBoard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,21 +183,22 @@ TEST(longest_road_simple){
}

TEST(payout_simple) {
/*std::vector<std::unique_ptr<Player>> players {};
std::vector<std::unique_ptr<Player>> players {};
players.emplace_back(new Player("tester"));
Player& test_player = *players[0];
GameBoard * test_board = new GameBoard(std::move(players));

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


std::map<Coordinate, std::unique_ptr<ResourceTile>>::iterator it =
test_board->getResources().find(Coordinate(0,1));
//test_board->getResources().at(Coordinate(0,1)).Payout(); WTF

test_board->getResourceTile(Coordinate(0,1)).Payout();


CHECK(!(test_player.getWheat() || test_player.getWood() ||
test_player.getOre() || test_player.getBrick() || test_player.getWool()));
delete test_board;
delete &test_player;*/
//delete &test_player;

}

Expand Down

0 comments on commit 9ba73b9

Please sign in to comment.