@@ -40,6 +40,8 @@ GameBoard::GameBoard(const vector<std::string>& playerNames) {
4040 }
4141
4242 currentTurn = 0 ;
43+ maxVictoryPoints = 10 ;
44+ winner = -1 ;
4345
4446 std::srand (std::time (0 ));
4547
@@ -74,7 +76,8 @@ GameBoard::GameBoard(const vector<std::string>& playerNames) {
7476 }
7577 std::cout << getRobber ().first << " \n " ;
7678 std::cout << getRobber ().second << " \n " ;
77-
79+
80+ maxVictoryPoints = 10 ;
7881}
7982
8083/* *
@@ -134,6 +137,8 @@ GameBoard::GameBoard(const std::vector<std::string>& playerNames, const std::map
134137 throw std::runtime_error (" Board is invalid." );
135138 }
136139 currentTurn = 0 ;
140+ maxVictoryPoints = 10 ;
141+ winner = -1 ;
137142}
138143
139144GameDice GameBoard::getDice () {
@@ -267,7 +272,9 @@ GameBoard::GameBoard(istream& in) {
267272 throw std::runtime_error (" Board is invalid." );
268273 }
269274
270- currentTurn = 0 ; // have to update <<--
275+ currentTurn = 0 ; // have to update
276+ maxVictoryPoints = 0 ;
277+ winner = -1 ;
271278}
272279
273280/* *
@@ -328,8 +335,12 @@ ResourceTile& GameBoard::getResourceTile(Coordinate location) const
328335 */
329336void GameBoard::endTurn ()
330337{
338+ std::cout << currentTurn << std::endl;
331339 if (getCurrentPlayer ().getVictoryPoints () >= getMaxVictoryPoints ())
332- std::cout<<" GG Bitches" ;
340+ {
341+ // std::cout<<"GG Bitches";
342+ winner = currentTurn;
343+ }
333344
334345 currentTurn++;
335346 if (currentTurn >= getNoOfPlayers ())
@@ -873,6 +884,43 @@ bool GameBoard::buyUpgradeOnSettlement(Coordinate location, Player& owner) {
873884 return false ;
874885}
875886
887+ /* *
888+ * Whether a settlement/city at a location can be upgraded to a wonder.
889+ */
890+ bool GameBoard::canUpgradeToWonder (Coordinate location, const Player& owner) const {
891+ auto it = corners.find (location);
892+ if (it == corners.end ()) {
893+ std::cout << " there's nothing there" << std::endl;
894+ return false ;
895+ }
896+ if (!it->second ) {
897+ std::cout << " null ptr there" << std::endl;
898+ return false ;
899+ }
900+ if (!(it->second ->getOwner () == owner)) {
901+ std::cout << " wrong owner" << std::endl;
902+ return false ;
903+ }
904+ if (dynamic_cast <const Settlement*>(it->second .get ()) == 0 && dynamic_cast <const City*>(it->second .get ()) == 0 ) {
905+ std::cout << " this isn't a settlement or city" << std::endl;
906+ return false ;
907+ }
908+ return true ;
909+ }
910+
911+ bool GameBoard::buyUpgradeOnWonder (Coordinate location, Player& owner) {
912+ if (canUpgradeToWonder (location, owner) && owner.canBuyCity ()) {
913+ if (!owner.buyWonder ()) {
914+ std::cout << " wat" << std::endl;
915+ return false ;
916+ }
917+ UpgradeToWonder (location);
918+ return true ;
919+ }
920+ std::cout << " failed for some reason" << std::endl;
921+ return false ;
922+ }
923+
876924/* *
877925 * Place a city on the board.
878926 * @param location Where to place it on the board.
@@ -1056,6 +1104,31 @@ Player& GameBoard::getCurrentPlayer() const
10561104 return *players[currentTurn];
10571105}
10581106
1107+
1108+
1109+ /* *
1110+ * @return true if game has a winner, false otherwise
1111+ */
1112+ bool GameBoard::hasWinner ()
1113+ {
1114+ if (winner == -1 )
1115+ return false ;
1116+ return true ;
1117+ }
1118+
1119+
1120+ /* *
1121+ * @return reference to the winner if there is one, null otherwise
1122+ */
1123+ Player& GameBoard::getWinner () const
1124+ {
1125+ if (winner != -1 && winner < players.size ())
1126+ return *players[winner];
1127+
1128+ return *players[0 ];
1129+ }
1130+
1131+
10591132/* *
10601133 * @return no of players
10611134 */
0 commit comments