MCPcopy Create free account
hub / github.com/Gecode/gecode / generate

Function generate

examples/black-hole.cpp:58–82  ·  view source on GitHub ↗

\brief Generates\ref layout. * * This function generates the layout and initializes \ref layer and * \ref pile from it. The layout is randomly generated from the * supplied seed. */

Source from the content-addressed store, hash-verified

56 * supplied seed.
57 */
58 void generate(int seed) {
59 // The layout consists of 17 piles of 3 cards each
60 layout = vector<vector<int> >(17, vector<int>(3));
61 // Deck without the Ace of Spades
62 vector<int> deck(51);
63 for (int i = 51; i--; ) deck[i] = i+1;
64 Support::RandomGenerator rnd(seed+1);
65 std::shuffle(deck.begin(), deck.end(), rnd);
66
67 // Place cards from deck
68 int pos = 0;
69 for (int i = 17; i--; )
70 for (int j = 3; j--; )
71 layout[i][j] = deck[pos++];
72
73 // Location-information for each card
74 layer = vector<int>(52);
75 pile = vector<int>(52);
76 for (int i = 17; i--; ) {
77 for (int j = 3; j--; ) {
78 layer[layout[i][j]] = j;
79 pile[ layout[i][j]] = i;
80 }
81 }
82 }
83}
84
85/**

Callers 1

mainFunction · 0.70

Calls 2

beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected