Skip to content

Commit 788a1e8

Browse files
committed
Fixed crash
1 parent 25a0e6a commit 788a1e8

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

src/GameBoard.cpp

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -398,31 +398,37 @@ void GameBoard::UpgradeSettlement(Coordinate location){
398398
void GameBoard::accept(GameVisitor& visitor) {
399399
visitor.visit(*this);
400400
for(auto& it : corners) {
401-
it.second->accept(visitor);
401+
if(it.second.get()) {
402+
it.second->accept(visitor);
403+
}
402404
}
403405
for(auto& it : resources) {
404-
it.second->accept(visitor);
406+
if(it.second.get()) {
407+
it.second->accept(visitor);
408+
}
405409
}
406410
for(auto& roadCoordVec : roads) {
407411
for(auto& road : roadCoordVec.second) {
408-
road->accept(visitor);
412+
if(road.get()) {
413+
road->accept(visitor);
414+
}
409415
}
410416
}
411417
for(auto& it : players) {
412-
it->accept(visitor);
418+
if(it.get()) {
419+
it->accept(visitor);
420+
}
413421
}
414422
}
415423

416424
bool GameBoard::operator==(const GameBoard& other) const {
417-
if(corners.size() != other.corners.size()) {
418-
return false;
419-
}
420425
for(auto& it : corners) {
421426
auto otherIt = other.corners.find(it.first);
422427
if(otherIt == other.corners.end()) {
423-
return false; // This location isn't in the other array
424-
}
425-
if(!(*(it.second) == *(otherIt->second))) {
428+
if(it.second.get()) {
429+
return false; // This location isn't in the other array
430+
}
431+
} else if(!(*(it.second) == *(otherIt->second))) {
426432
return false;
427433
}
428434
}
@@ -454,12 +460,10 @@ bool GameBoard::operator==(const GameBoard& other) const {
454460
}
455461
}
456462
if(players.size() != other.players.size()) {
457-
std::cout << "sizes differ" << std::endl;
458463
return false;
459464
}
460465
for(unsigned int i = 0; i < players.size(); i++) {
461466
if(!(*(players[i]) == *(other.players[i]))) {
462-
std::cout << "player " << i << " differs" << std::endl;
463467
return false;
464468
}
465469
}

tests/testSerialization.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,11 @@ TEST(roadSerialization) {
7676

7777
testBoard.PlaceRoad(Coordinate(0,0), Coordinate(-1,1), firstPlayer);
7878
testBoard.PlaceRoad(Coordinate(-1,1), Coordinate(-1,2), secondPlayer);
79-
std::cout << __LINE__ << "\n";
8079

8180
stringstream stream;
8281
testBoard.save(stream);
83-
std::cout << __LINE__ << "\n";
8482

8583
GameBoard copyBoard(stream);
86-
std::cout << __LINE__ << "\n";
8784

8885
CHECK(testBoard == copyBoard);
8986
}

0 commit comments

Comments
 (0)