You are on page 1of 5

Word Search Puzzle Generator (WSPG)

Task: Write a program that will generate a word search puzzle like described
below.
1. The puzzle must be randomly generated.
2. The direction of each word is randomly selected to go in 8 different
directions.
3. The words may intersect with another at a common letter.
4. Randomly fill in the blanks with a random character.
5. Functions must be used to place the words.
6. Use Global arrays to simplify coding.
7. OPTIONAL: A recursive function must be implemented.
8. You must use fstream to input the words and output the puzzle to
another file.
9. The puzzle's words must printed along with the puzzle
10. Use at least 25 words that fit snugly into the grid

US States - 50 Words (up to 13 characters) in a 26x26


grid

N E B R A S K A - - - V I R G I N I A M A B A L A N N E B R A S K A A A Z V I R G I N I A M A B A L A N
- - - - - - - I P P I S S I S S I M - - - - - - E O E N E E L O W I P P I S S I S S I M S I S B S V E O
- - - - - - - K E N T U C K Y - - - K - - - - E - R X R R F K E N K E N T U C K Y X O D K H A J F E Y R
- - - - - - - - - - A G N I M O Y W - R - U S - - T G L V T U V R T H Y A G N I M O Y W I R P U S T Q T
M - - - - - - - - - R - O K L A H O M A O S T - - H M V M U F C A Q R D R R O K L A H O M A O S T C D H
I - - - - - - - - - I - I L L I N O I S E Y - A - C I J O R F D P O J T I O I L L I N O I S E Y E A Q C
N - - - N E V A D A Z - - A K S A L A N - - W - H A N G M Y N E V A D A Z L J A K S A L A N R X W J H A
N M D N A L S I E D O H R - - - - - N V - - - E - R N M D N A L S I E D O H R L F T W Y N V A B I E B R
E - I N O G E R O - N - - - T - - E - E M - - C N O E L I N O G E R O V N Y X M T G I E W E M L V C N O
S - A S - - - - - - A - - E - - T - - R A - S A - L S U A S L W K M M R A Q K E T B T W I R A O S A H L
O - A W S W - - - - - - X N - - A - - M R H T L A I O G A W S W I P V Q J H X N B E A T S M R H T L A I
T - - N O O A - - - - A - - E R - - - O Y A T I I N T U P N O O A G C M T A B Y E R J C A O Y A T I I N
A - - - A I U S - - S - - C K W - - - N L W E F N A A X J L A I U S O D S B X C K W C J B N L W E F N A
- - - - - T - R H - - - O A - M J - - T A A S O I - L M F Q U T D R H O N S O A F M J A I T A A S O I M
- N E - - - N - I I - N N E I - - E - - N I U R G S A N E A K T N O I I E N N E I L D E E H N I U R G S
F O N - - - - O - - N S - C R - - - R - D I H N R O F O N S B A W O L J N S X C R C L C R F D I H N R O
L R I O H A D I M E A G H - - A - - I S - - C I I U L R I O H A D I M E A G H V U A P L I S E B C I I U
O T A - O - - - C S - I T - - - W - - N E - A A V T O T A T O V D U C S H I T E P V W D S N E P A A V T
R H M - H - - T - - G - - O - - - A - - D Y S - T H R H M V H J Q T I K G J G O G V I A S U D Y S L T H
I D - - I - I - - A - - - - N - - - L - - I S - S D I D V W I Z I D X A A P P B N U Q I L Z A I S J S D
D A - - O C - - N - A N A I S I U O L E - - A - E A D A Z T O C I E N I A N A I S I U O L E W Y A N E A
A K - - U A N I L O R A C H T U O S - - D - M N W K A K N I U A N I L O R A C H T U O S D T D X M N W K
- O - T - K A N S A S - - - C O L O R A D O - - A O I O V T Q K A N S A S G A T C O L O R A D O R Y A O
- T - - - - - G E O R G I A W I S C O N S I N - - T J T D G P L Z G E O R G I A W I S C O N S I N O W T
- A A I N A V L Y S N N E P - - O C I X E M W E N A V A A I N A V L Y S N N E P L T O C I X E M W E N A
- - - - - - - - - - - - N E W H A M P S H I R E - - U C I A C P B C C A P S N E W H A M P S H I R E N Y

ALABAMA
ALASKA
ARIZONA
ARKANSAS
CALIFORNIA
COLORADO
CONNECTICUT
DELAWARE
FLORIDA
GEORGIA
HAWAII
IDAHO
ILLINOIS
INDIANA
IOWA
KANSAS
KENTUCKY
LOUISIANA
MAINE
MARYLAND
MASSACHUSETTS
MICHIGAN
MINNESOTA
MISSISSIPPI
MISSOURI
MONTANA
NEBRASKA
NEVADA
NEWHAMPSHIRE
NEWJERSEY
NEWMEXICO
NEWYORK
NORTHCAROLINA
NORTHDAKOTA
OHIO
OKLAHOMA
OREGON
PENNSYLVANIA
RHODEISLAND
SOUTHCAROLINA
SOUTHDAKOTA
TENNESSEE
TEXAS
UTAH
VERMONT
VIRGINIA
WASHINGTON
WESTVIRGINIA
WISCONSIN
WYOMING

#include <iostream>
#include <fstream>
using namespace std;

// Global variables
const int gridSize = 25; // constant value. Cannot be changed later
char grid[gridSize][gridSize];
ofstream fout;

void reset(){
for(int r=0; r<gridSize; r++){
for(int c=0; c<gridSize; c++){
grid[r][c] = '-';
}
}
}

void display(){
for(int r=0; r<gridSize; r++){
for(int c=0; c<gridSize; c++){
cout << grid[r][c] <<" ";
}
cout << endl;
}
}

void printout(){
for(int r=0; r<gridSize; r++){
for(int c=0; c<gridSize; c++){
fout << grid[r][c] <<" ";
}
fout << endl;
}
}

int main(){
fout.open("puzzle_p4.txt");
reset();
// display();
// printout();
//grid[][]
string word = "abcdefgh";
int wordIndex = 0;
int rowStart = 1;
int colStart = 1;
for(int i = 0; i < word.length(); i++){
grid[rowStart][colStart + i] = word[wordIndex++];
}
display();
}

/*

Task:
1. Randomize the starting location of placing the word
horizontally from left to right. Ensure that the spot
chosen does not cause the word to go out of bounds.
2. Modify and add the algorithm to place the word
horizontally from right to left.
3. Modify and add the algorithm to place the word randomly
vertically down and up.
4. Modify and add the algorithm to place the word in the 4
diagonal directions. (Hint: start at the corners to
determine the proper range.)
5. Randomize the 8 directions to place the word.
6. Collect all of the placement algorithms of this board
into a void function called placeWord(string s);
7. Use placeWord() to place multiple words onto the board.
8. Note that words may run into each other. Write a
function isSafe(row,col,word) that determines if the
[row][col] spot chosen "isSafe" for the word being
placed.
9. Use the isSafe() function to help generate valid
[row][col] spot values that will safely place the word
without inappropriately running into other words.
10. Note that the words are not crossing into one another
through a common character. Modify the isSafe() function
to allow the word to intersect with a placed word just
as long as the point of intersection is a common
character.
11. Test and ensure that all the words placed are
satisfactory. Ensure no improper run-ins and out of
bound errors.
12. Gather up a collection of 20+ words from a file and
place them on the grid.
13. Note that there are spaces that are not populated
with an alphabetic character. Replace all '-' characters
with a random alphabetic character to complete the
puzzle generator.
14. Output BOTH the puzzle (with AND without random
characters) and the list of words you placed inside.
15. Submit through google classroom. (doc and
YOURNAME_WSPG_P#.cpp file)
*/

You might also like