11#include " GameBoard.h"
22
3-
43#include < map>
54#include < memory>
65
76using std::map;
87using std::unique_ptr;
98
10- #define ADD_RESOURCE (x, y, res, val ) (resources[Coordinate(x,y)] = \
9+ #include < ctime>
10+ #include < algorithm>
11+
12+ #define ADD_RESOURCE (x, y, res, val ) (this ->resources[Coordinate(x,y)] = \
1113std::unique_ptr<GamePiece>(new ResourceTile(*this , Coordinate(x,y), res, val)))
1214#define DUMMY_BOARD // define to instantiate dummy board for debugging
1315
16+ using std::random_shuffle;
17+ using std::time;
18+
1419GameBoard::GameBoard () {
1520 init_resources ();
1621}
@@ -90,14 +95,42 @@ std::vector<Settlement*> GameBoard::GetNeighboringSettlements(Coordinate locatio
9095 return v;
9196}
9297
93- /* initialize board with a set of resources. Right now, just creates a static tile arrangement to test
94- URL: http://images.fanpop.com/images/image_uploads/Differents-Boards-settlers-of-catan-521934_1157_768.jpg*/
98+ /* initialize board with a set of resources. Currently only the standard configuration (no custom shapes or expansion packs) is implemented. Board tiles and roll numbers are randomized.
99+ @todo Change the dummy board to the actual board
100+ */
95101
96102void GameBoard::init_resources ()
97103{
104+ std::srand (std::time (0 ));
105+
106+ resourceType resources[] = {BRICK, BRICK, BRICK, STONE, STONE, STONE, WHEAT, WHEAT, WHEAT, WHEAT, WOOD, WOOD, WOOD, WOOD, SHEEP, SHEEP, SHEEP, SHEEP, DESERT};
107+ random_shuffle (&resources[0 ], &resources[19 ]);
108+
109+ int rolls[] = {2 , 3 , 3 , 4 , 4 , 5 , 5 , 6 , 6 , 7 , 7 , 8 , 8 , 9 , 9 , 10 , 10 , 11 };
110+ random_shuffle (&rolls[0 ], &rolls[18 ]);
111+
112+ int xcoords[] = {0 , -2 , 2 , -3 , -1 , 1 , 3 , -4 , 2 , 0 , 2 , 4 , -3 , -1 , 1 , 3 , -2 , 0 , 2 };
113+ int ycoords[] = {1 , 2 , 0 , 3 , 3 , 2 , 1 , 6 , 5 , 4 , 3 , 2 , 7 , 6 , 5 , 4 , 8 , 7 , 6 };
98114
99-
100- #ifdef DUMMY_BOARD
115+
116+ #ifdef DUMMY_BOARD
117+ int rollCount = 0 ;
118+ for (int i = 0 ; i<19 ; i++)
119+ {
120+ if (resources[i]==DESERT)
121+ {
122+ ADD_RESOURCE (xcoords[i], ycoords[i], resources[i], 0 );
123+ }
124+ else
125+ {
126+ ADD_RESOURCE (xcoords[i], ycoords[i], resources[i], rolls[rollCount]);
127+ rollCount++;
128+ }
129+ }
130+ #endif
131+
132+ /*
133+ #ifdef DUMMY_BOARD
101134 ADD_RESOURCE(0, 1, BRICK, 2);
102135 ADD_RESOURCE(-2, 2, SHEEP, 5);
103136 ADD_RESOURCE(2, 0, WOOD, 6);
@@ -118,7 +151,9 @@ void GameBoard::init_resources()
118151 ADD_RESOURCE(0, 7, STONE, 12);
119152 ADD_RESOURCE(2, 6, WHEAT, 9);
120153 #endif
154+ */
121155
156+
122157
123158}
124159
0 commit comments