Skip to content

Commit e77ef1f

Browse files
committed
*DO NOT MERGE* Implemented randomization of the board, but I'm getting some Make errors. I think it's a problem with my machine, and not the code, however this branch may break the program's functionality
1 parent 4f083e9 commit e77ef1f

File tree

2 files changed

+46
-3
lines changed

2 files changed

+46
-3
lines changed

include/GameBoard.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <vector>
66
#include <memory>
77
#include <utility>
8+
#include <algorithm>
89

910
#include "Util.h"
1011
#include "GamePiece.h"
@@ -18,6 +19,7 @@ class GameBoard {
1819
std::map<Coordinate, std::unique_ptr<GamePiece>> corners;
1920
std::map<Coordinate, std::unique_ptr<GamePiece>> resources;
2021
std::vector<std::unique_ptr<const Road>> roads;
22+
2123
public:
2224
GameBoard();
2325
GameBoard(GameBoard&) = delete;

src/GameBoard.cpp

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,42 @@ std::vector<Settlement*> GameBoard::GetNeighboringSettlements(Coordinate locatio
3232
return v;
3333
}
3434

35-
/* initialize board with a set of resources. Right now, just creates a static tile arrangement to test
36-
URL: http://images.fanpop.com/images/image_uploads/Differents-Boards-settlers-of-catan-521934_1157_768.jpg*/
35+
/* 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.
36+
@todo Change the dummy board to the actual board
37+
*/
3738

3839
void GameBoard::init_resources()
3940
{
41+
std::srand(std::time(0));
42+
43+
resourceType resources[] = {BRICK, BRICK, BRICK, STONE, STONE, STONE, WHEAT, WHEAT, WHEAT, WHEAT, WOOD, WOOD, WOOD, WOOD, SHEEP, SHEEP, SHEEP, SHEEP, DESERT};
44+
random_shuffle(&resources[0], &resources[19]);
45+
46+
int rolls[] = {2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11};
47+
random_shuffle(&rolls[0], &rolls[18]);
48+
49+
int xcoords[] = {0, -2, 2, -3, -1, 1, 3, -4, 2, 0, 2, 4, -3, -1, 1, 3, -2, 0, 2};
50+
int ycoords[] = {1, 2, 0, 3, 3, 2, 1, 6, 5, 4, 3, 2, 7, 6, 5, 4, 8, 7, 6};
4051

52+
53+
#ifdef DUMMY_BOARD
54+
int rollCount = 0;
55+
for (int i = 0; i<19, i++)
56+
{
57+
if (resources[i]==DESERT)
58+
{
59+
ADD_RESOURCE(xcoords[i], ycoords[i], resources[i], 0);
60+
}
61+
else
62+
{
63+
ADD_RESOURCE(xcoords[i], ycoords[i], resources[i], rolls[rollCount]);
64+
rollCount++;
65+
}
66+
}
67+
#endif
4168

42-
#ifdef DUMMY_BOARD
69+
/*
70+
#ifdef DUMMY_BOARD
4371
ADD_RESOURCE(0, 1, BRICK, 2);
4472
ADD_RESOURCE(-2, 2, SHEEP, 5);
4573
ADD_RESOURCE(2, 0, WOOD, 6);
@@ -60,10 +88,23 @@ void GameBoard::init_resources()
6088
ADD_RESOURCE(0, 7, STONE, 12);
6189
ADD_RESOURCE(2, 6, WHEAT, 9);
6290
#endif
91+
*/
6392

93+
6494

6595
}
6696

6797
void GameBoard::PlaceSettlement(Coordinate location, Player& Owner){
6898
corners[location] = std::unique_ptr<GamePiece>(new Settlement(*this, location, Owner));
99+
}
100+
101+
resourceType* randomizeBoard(resourceType* resources)
102+
{
103+
std::srand(std::time(0));
104+
105+
}
106+
107+
int* randomizeRolls(int* rolls)
108+
{
109+
69110
}

0 commit comments

Comments
 (0)