1010#include " GameVisitor.h"
1111#include " Serialization.h"
1212#include " tinyxml2.h"
13+ #include " CornerPiece.h"
14+ #include " City.h"
1315
1416using std::shared_ptr;
1517using std::random_shuffle;
@@ -111,12 +113,12 @@ void GameBoard::save(ostream& out) {
111113 out << printer.CStr ();
112114}
113115
114- const map<Coordinate, unique_ptr<GamePiece >>& GameBoard::getResources () const {
116+ const map<Coordinate, unique_ptr<ResourceTile >>& GameBoard::getResources () const {
115117 return resources;
116118}
117119
118120std::vector<Settlement*> GameBoard::GetNeighboringSettlements (
119- Coordinate location) {
121+ Coordinate location) const {
120122 static Coordinate adjacentCoordDiffs[] = { Coordinate (0 , 1 ), Coordinate (1 ,
121123 0 ), Coordinate (1 , -1 ), Coordinate (0 , -1 ), Coordinate (-1 , 0 ),
122124 Coordinate (-1 , 1 ) };
@@ -125,8 +127,8 @@ std::vector<Settlement*> GameBoard::GetNeighboringSettlements(
125127 const Coordinate& diff = adjacentCoordDiffs[i];
126128 Coordinate adjacentPoint (location.first + diff.first ,
127129 location.second + diff.second );
128- auto it = resources .find (adjacentPoint);
129- if (it != resources .end ()) {
130+ auto it = corners .find (adjacentPoint);
131+ if (it != corners .end ()) {
130132 GamePiece* piece = it->second .get ();
131133 if (dynamic_cast <Settlement*>(piece)) {
132134 v.push_back (static_cast <Settlement*>(piece));
@@ -136,6 +138,28 @@ std::vector<Settlement*> GameBoard::GetNeighboringSettlements(
136138 return v;
137139}
138140
141+ std::vector<CornerPiece*> GameBoard::GetNeighboringCorners (
142+ Coordinate location) const {
143+ static Coordinate adjacentCoordDiffs[] = { Coordinate (0 , 1 ), Coordinate (1 ,
144+ 0 ), Coordinate (1 , -1 ), Coordinate (0 , -1 ), Coordinate (-1 , 0 ),
145+ Coordinate (-1 , 1 ) };
146+ std::vector<CornerPiece*> v;
147+ for (unsigned int i = 0 ; i < 6 ; i++) {
148+ const Coordinate& diff = adjacentCoordDiffs[i];
149+ Coordinate adjacentPoint (location.first + diff.first ,
150+ location.second + diff.second );
151+ auto it = resources.find (adjacentPoint);
152+ if (it != resources.end ()) {
153+ GamePiece* piece = it->second .get ();
154+ if (dynamic_cast <CornerPiece*>(piece)) {
155+ v.push_back (static_cast <CornerPiece*>(piece));
156+ }
157+ }
158+ }
159+ return v;
160+ }
161+
162+
139163/* *
140164 * Checks to make sure the coordinate is within bounds of the board
141165 */
@@ -195,15 +219,15 @@ bool GameBoard::roadExists(Coordinate start, Coordinate end) {
195219 * Checks to make sure the road being placed at a valid point according to the rules
196220 */
197221bool GameBoard::isRoadConnectionPoint (Coordinate start, Coordinate end, Player& Owner){
198- /* * Need to figure out the CornerPiece/GamePiece predicament
199- CornerPiece * corner = corners[start];
200- if(corner != NULL){
201- if (corner ->getOwner() == Owner)
222+
223+ // std::unique_ptr<GamePiece> corner = corners[start];
224+ if (corners[start] != NULL ){
225+ if (corners[start] ->getOwner () == Owner)
202226 return true ;
203227 }
204228 return false ;
205- * */
206- return true ;
229+
230+
207231}
208232
209233/* *
@@ -347,9 +371,15 @@ void GameBoard::init_resources()
347371}
348372
349373void GameBoard::PlaceSettlement (Coordinate location, Player& Owner){
350- corners[location] = std::unique_ptr<GamePiece>(new Settlement (*this , location, Owner));
374+ corners[location] = std::unique_ptr<CornerPiece>(new Settlement (*this , location, Owner));
375+ }
376+
377+ void GameBoard::UpgradeSettlement (Coordinate location){
378+ corners[location] = std::unique_ptr<CornerPiece>(new City (*corners[location])); // TODO test for memory leak
351379}
352380
381+
382+
353383void GameBoard::accept (GameVisitor& visitor) {
354384 visitor.visit (*this );
355385 for (auto & it : corners) {
@@ -430,7 +460,7 @@ bool GameBoard::operator==(const GameBoard& other) const {
430460 */
431461void GameBoard::addResource (int x, int y, resourceType res, int val)
432462{
433- this ->resources [Coordinate (x,y)] = std::unique_ptr<GamePiece >(new ResourceTile (*this , Coordinate (x,y), res, val));
463+ this ->resources [Coordinate (x,y)] = std::unique_ptr<ResourceTile >(new ResourceTile (*this , Coordinate (x,y), res, val));
434464}
435465
436466/*
0 commit comments