Main CPP
Main CPP
h"
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <random>
#include <algorithm>
#include <iomanip>
#include <unordered_set>
#include <map>
#include <chrono>
int main() {
//had lfile fih 3300 word 7 flenth et 5000 word dyal 6 flength
string filename = "11300word-length-7-6-5.txt";
//string filename = "filtered_words_sorted_more_3_letters.txt";
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
std::mt19937 gen(seed);
int grid_size = 7;
int num_puzzles = 20;
vector<string> word_list = load_words_from_file(filename, grid_size);
word_list = filterWordsByLetters(word_list, "sareti");
/*for(int i=0;i<word_list.size();i++){
cout<<word_list[i]<<endl;
}*/
cout<<"---------------------------------"<<endl;
int total_words_used = 0;
int total_horizontal_words = 0;
int total_vertical_words = 0;
// Remove the words used in the current puzzle from the word_list
int words_used_in_puzzle = 0;
int horizontal_words_in_puzzle = 0;
int vertical_words_in_puzzle = 0;
if (info.direction == 0) {
++horizontal_words_in_puzzle;
} else if (info.direction == 1) {
++vertical_words_in_puzzle;
}
}
}
total_words_used += words_used_in_puzzle;
total_horizontal_words += horizontal_words_in_puzzle;
total_vertical_words += vertical_words_in_puzzle;
cout << "Words used in Puzzle " << puzzle_num << ": " <<
words_used_in_puzzle << endl;
cout << "Percentage of Horizontal Words: " << (100.0 *
horizontal_words_in_puzzle / words_used_in_puzzle) << "%" << endl;
cout << "Percentage of Vertical Words: " << (100.0 *
vertical_words_in_puzzle / words_used_in_puzzle) << "%" << endl;
cout<<"---------------------------------------------"<<endl;
}
cout << "Total words used in all puzzles: " << total_words_used << endl;
cout << "Total horizontal words used in all puzzles: " <<
total_horizontal_words << endl;
cout << "Total vertical words used in all puzzles: " << total_vertical_words <<
endl;
cout<<"Fin de Programme"<<endl;
return 0;
}
/*#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <random>
#include <iomanip>
#include <unordered_set>
#include <map>
#include <chrono>
#include <algorithm>
//#include "functions.h"
if (isSubset) {
filteredWords.push_back(word);
}
}
return filteredWords;
}
void calculate_word_percentages(const vector<WordInfo>& word_info, double&
horizontal_percentage, double& vertical_percentage) {
int total_words = word_info.size();
int horizontal_words = 0;
int vertical_words = 0;
std::random_device rd;
std::mt19937 gen(rd());
int words_tried = 0; // Counter for the number of words tried in the current
direction
for (const string& word : shuffled_words) {
bool placed = false;
case 1: // Vertical
x = uniform_int_distribution<int>(0, grid_size - 1)(gen);
y = uniform_int_distribution<int>(0, grid_size - word.length())
(gen);
placed = true;
for (int i = 0; i < word.length(); ++i) {
char intersect_char = grid[y + i][x];
if (intersect_char != ' ' && intersect_char != word[i]) {
placed = false;
break;
}
}
if (placed) {
for (int i = 0; i < word.length(); ++i) {
grid[y + i][x] = word[i];
}
word_info.push_back({word, x, y, direction});
break;
}
break;
}
if (placed) {
// Switch to the other direction
direction = (direction + 1) % num_directions;
words_tried = 0; // Reset the counter
break;
} else {
words_tried++;
if (words_tried > 200) {
// Switch to the other direction
direction = (direction + 1) % num_directions;
words_tried = 0; // Reset the counter
}
}
}
}
return grid;
}
void display_word_search_puzzle(const vector<vector<char>>& grid, const
vector<WordInfo>& word_info, int puzzle_num) {
int grid_size = grid.size();
int main() {
//had lfile fih 3300 word 7 flenth et 5000 word dyal 6 flength
string filename = "11300word-length-7-6-5.txt";
//string filename = "filtered_words_sorted_more_3_letters.txt";
//std::random_device rd;
//std::mt19937 gen(rd());
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
std::mt19937 gen(seed);
int grid_size = 7;
int num_puzzles = 20;
vector<string> word_list = load_words_from_file(filename, grid_size);
word_list = filterWordsByLetters(word_list, "seding");
for(int i=0;i<word_list.size();i++){
cout<<word_list[i]<<endl;
}
cout<<"---------------------------------"<<endl;
int total_words_used = 0;
int total_horizontal_words = 0;
int total_vertical_words = 0;
// Remove the words used in the current puzzle from the word_list
int words_used_in_puzzle = 0;
int horizontal_words_in_puzzle = 0;
int vertical_words_in_puzzle = 0;
if (it != word_list.end()) {
word_list.erase(it);
++words_used_in_puzzle;
if (info.direction == 0) {
++horizontal_words_in_puzzle;
} else if (info.direction == 1) {
++vertical_words_in_puzzle;
}
}
}
total_words_used += words_used_in_puzzle;
total_horizontal_words += horizontal_words_in_puzzle;
total_vertical_words += vertical_words_in_puzzle;
cout << "Words used in Puzzle " << puzzle_num++ << ": " <<
words_used_in_puzzle << endl;
cout << "Percentage of Horizontal Words: " << (100.0 *
horizontal_words_in_puzzle / words_used_in_puzzle) << "%" << endl;
cout << "Percentage of Vertical Words: " << (100.0 *
vertical_words_in_puzzle / words_used_in_puzzle) << "%" << endl;
cout<<"---------------------------------------------"<<endl;
cout<<"Apres "<<i<<" fois"<<endl;
}
cout<<"dans la sortie word_list.size() == "<<word_list.size()<<endl;
cout << "Total words used in all puzzles: " << total_words_used << endl;
cout << "Total horizontal words used in all puzzles: " <<
total_horizontal_words << endl;
cout << "Total vertical words used in all puzzles: " << total_vertical_words <<
endl;
return 0;
}
*/