1414
1515#include " CornerPiece.h"
1616#include " GameDice.h"
17-
1817#include " Settlement.h"
1918#include " City.h"
2019#include " Wonder.h"
@@ -66,6 +65,16 @@ GameBoard::GameBoard(const vector<std::string>& playerNames) {
6665 }
6766 valid = isValidBoard ();
6867 }
68+ // moveRobber(Coordinate(0,4));
69+ auto it = getResources ().begin ();
70+ while (it != getResources ().end ()) {
71+ if ((it->second )->getType () == DESERT)
72+ moveRobber (it->first );
73+ it++;
74+ }
75+ std::cout << getRobber ().first << " \n " ;
76+ std::cout << getRobber ().second << " \n " ;
77+
6978}
7079
7180/* *
@@ -127,6 +136,9 @@ GameBoard::GameBoard(const std::vector<std::string>& playerNames, const std::map
127136 currentTurn = 0 ;
128137}
129138
139+ GameDice GameBoard::getDice () {
140+ return dice;
141+ }
130142/* *
131143 * Construct a board by reading in an XML representation from a stream.
132144 * @param in The stream to read from.
@@ -400,16 +412,15 @@ std::vector<Settlement*> GameBoard::GetNeighboringSettlements(
400412 * @param location The location to search the neighbors of.
401413 * @return A vector of the corner pieces in the vicinity.
402414 */
403- std::vector<CornerPiece*> GameBoard::GetNeighboringCorners (
404- Coordinate location) const {
405- static Coordinate adjacentCoordDiffs[] = { Coordinate (0 , 1 ), Coordinate (1 ,
406- 0 ), Coordinate (1 , -1 ), Coordinate (0 , -1 ), Coordinate (-1 , 0 ),
407- Coordinate (-1 , 1 ) };
415+ std::vector<CornerPiece*> GameBoard::GetNeighboringCorners (Coordinate location) const {
416+ static Coordinate adjacentCoordDiffs[] = { Coordinate (0 , 1 ), Coordinate (1 ,0 ),
417+ Coordinate (1 , -1 ), Coordinate (0 , -1 ), Coordinate (-1 , 0 ), Coordinate (-1 , 1 ) };
418+
408419 std::vector<CornerPiece*> v;
409420 for (unsigned int i = 0 ; i < 6 ; i++) {
410421 const Coordinate& diff = adjacentCoordDiffs[i];
411- Coordinate adjacentPoint (location.first + diff.first ,
412- location. second + diff. second );
422+ Coordinate adjacentPoint (location.first + diff.first , location. second + diff. second );
423+
413424 auto it = corners.find (adjacentPoint);
414425 if (it != corners.end ()) {
415426 GamePiece* piece = it->second .get ();
@@ -422,6 +433,7 @@ std::vector<CornerPiece*> GameBoard::GetNeighboringCorners(
422433}
423434
424435
436+
425437/* *
426438 * Checks to make sure the coordinate is within bounds of the board and not a resource tile.
427439 * @param coord The coordinate to check.
@@ -516,21 +528,22 @@ bool GameBoard::verifyRoadPlacement(Coordinate start, Coordinate end, Player& Ow
516528 * Move the robber to a new coordinate on the board.
517529 * @param newRobber The coordinate to move the robber to.
518530 */
519- void GameBoard::moveRobber (Coordinate newRobber) {
531+ bool GameBoard::moveRobber (Coordinate newRobber) {
520532
521533 // Bounds check
522- if (resources.count (newRobber) > 0 )
534+ if (resources.find (newRobber) != resources. end ()){
523535 robber = newRobber;
536+ return true ;
537+ }
538+ return false ;
524539}
525540
526541/* *
527- * DOES NOT WORK BECAUSE getNeighboringCorners() does not work
542+ * Returns whether the robber can rob the Player opponent at the recourse tile Coordinate location
543+ * @return true if the robber can rob the opponent, false otherwise
528544 */
529545bool GameBoard::canRobberRob (Player& opponent, Coordinate location){
530- std::cout << GetNeighboringCorners (location).size () << " \n " ;
531-
532546 for (auto corner : GetNeighboringCorners (location)){
533- std::cout << corner->getOwner ().getName () << " derp\n " ;
534547 if (corner->getOwner () == opponent){
535548 return true ;
536549 }
@@ -1102,3 +1115,54 @@ void GameBoard::payoutResources(int roll)
11021115 }
11031116 }
11041117}
1118+
1119+ /* *
1120+ * Buys a card drawn from the deck
1121+ */
1122+ void GameBoard::buyCard (Player& owner){
1123+ if (owner.canBuyCard () && deck.getSize () > 0 ){
1124+
1125+ DevelopmentCard * card_ptr = deck.drawCard ();
1126+
1127+ std::unique_ptr<DevelopmentCard> knight = std::unique_ptr<DevelopmentCard>(new KnightCard ());
1128+ std::unique_ptr<DevelopmentCard> victorypoint = std::unique_ptr<DevelopmentCard>(new VictoryPointCard ());
1129+ std::unique_ptr<DevelopmentCard> monopoly = std::unique_ptr<DevelopmentCard>(new MonopolyCard ());
1130+ std::unique_ptr<DevelopmentCard> yearofplenty = std::unique_ptr<DevelopmentCard>(new YearOfPlentyCard ());
1131+ std::unique_ptr<DevelopmentCard> roadbuilding = std::unique_ptr<DevelopmentCard>(new RoadBuildingCard ());
1132+
1133+ switch (card_ptr->getType ()){
1134+ case KNIGHT:
1135+ owner.buyCard (knight);
1136+ break ;
1137+ case VICTORYPOINT:
1138+ owner.buyCard (victorypoint);
1139+ break ;
1140+ case MONOPOLY:
1141+ owner.buyCard (monopoly);
1142+ break ;
1143+ case YEAROFPLENTY:
1144+ owner.buyCard (yearofplenty);
1145+ break ;
1146+ case ROADBUILDING:
1147+ owner.buyCard (roadbuilding);
1148+ break ;
1149+ default :
1150+ break ;
1151+ }
1152+
1153+ delete (card_ptr);
1154+ }
1155+ }
1156+
1157+ /* *
1158+ * Discards a card back into the deck
1159+ */
1160+ void GameBoard::discardCard (DevelopmentCard * card){
1161+ deck.discard (card);
1162+ }
1163+
1164+
1165+
1166+
1167+
1168+
0 commit comments