-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathboggle_generator.cpp
51 lines (37 loc) · 1.16 KB
/
boggle_generator.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <time.h>
using namespace std;
//based on http://boardgamegeek.com/thread/300883/letter-distribution
const int NUM_GROUPS = 11;
const string LETTER_GROUPS[NUM_GROUPS] = {"e","t","ar","ino","s","d","chl","fmpu","gy","w","bjkqvxz"};
const int LETTER_GROUP_FREQ[NUM_GROUPS] = {19,13,12,11,9,6,5,4,3,2,1};
void generate(int board_size, string fname){
string tileBag;
char letter;
ofstream file;
file.open( fname.c_str() );
for(int i = 0; i < NUM_GROUPS; i++){
int freq = LETTER_GROUP_FREQ[i];
for(int j = 0; j < freq; j++){
tileBag += LETTER_GROUPS[i];
}
}
srand( time(NULL) );
//setup random board
for(int i = 0; i < board_size; i++){
letter = tileBag[rand() % tileBag.length()];
file << letter;
}
file.close();
}
int main(int argc, char* argv[]){
int size = 4;
string fname = "boggle.txt";
if( argc > 1 ) size = atoi(argv[1]);
if( argc > 2 ) fname = argv[2];
int board_size = size * size;
generate(board_size, fname);
cout << "Created boggle board " << fname << endl;
}