From c268da3ea10636163de2ff6e980f7acacfa0c9fa Mon Sep 17 00:00:00 2001 From: lzwdgc Date: Sun, 4 Oct 2015 21:38:54 +0300 Subject: [PATCH] Add name generator. --- CMakeLists.txt | 6 +- src/CMakeLists.txt | 3 + src/name_generator/name_generator.cpp | 80 +++++++++++++++++++++++++++ 3 files changed, 86 insertions(+), 3 deletions(-) create mode 100644 src/name_generator/name_generator.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 680b43a..6945906 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,13 +16,13 @@ if (MSVC) set(disable_msvc_warnings "/W1 /wd4996") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MP ${disable_msvc_warnings}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP ${disable_msvc_warnings}") - - #set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd") - #set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT") else() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --std=c++14") endif(MSVC) +add_definitions(-DPOLYGON4_TOOLS=1) +add_definitions(-DPOLYGON4_STATIC=1) + if (NOT DATABASE_MANAGER_DIR) message(STATUS "DATABASE_MANAGER_DIR variable is not set! Some targets won't be built") else() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 23c0dfe..89c8bcc 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -34,4 +34,7 @@ file(GLOB tm_converter_src "tm_converter/*") add_executable(tm_converter ${tm_converter_src}) target_link_libraries(tm_converter common) +file(GLOB name_generator_src "name_generator/*") +add_executable(name_generator ${name_generator_src}) + add_subdirectory(common) \ No newline at end of file diff --git a/src/name_generator/name_generator.cpp b/src/name_generator/name_generator.cpp new file mode 100644 index 0000000..9e9878d --- /dev/null +++ b/src/name_generator/name_generator.cpp @@ -0,0 +1,80 @@ +/* +* AIM name_generator +* Copyright (C) 2015 lzwdgc +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +*/ + +#include +#include +#include + +class NameGenerator +{ + static const int letmin = 2; + static const int letmax = 3; + +public: + NameGenerator() + : rng(std::random_device()()) + { + } + + std::string generate(int sylmin = 2, int sylmax = 3) + { + static const std::string consonants = "bcdfghjklmnpqrstvwxz"; + static const std::string vowels = "aeiouy"; + std::uniform_int_distribution<> c_distr(0, consonants.size() - 1); + std::uniform_int_distribution<> v_distr(0, vowels.size() - 1); + std::uniform_int_distribution<> cv_distr(0, 1); + auto n_syllables = std::uniform_int_distribution<>(sylmin, sylmax)(rng); + std::uniform_int_distribution<> let_distr(letmin, letmax); + std::string name; + for (int s = 0; s < n_syllables; s++) + { + auto n_letters = let_distr(rng); + int n_consonants = 0, n_vowels = 0; + std::string syllable; + for (int l = 0; l < n_letters; l++) + { + auto vowel = cv_distr(rng); + syllable += vowel ? vowels[v_distr(rng)] : consonants[c_distr(rng)]; + n_consonants += !vowel; + n_vowels += vowel; + } + if (n_consonants == n_letters) + { + auto pos = std::uniform_int_distribution<>(0, n_letters - 1)(rng); + syllable[pos] = vowels[v_distr(rng)]; + } + else if (n_vowels == n_letters) + { + auto pos = std::uniform_int_distribution<>(0, n_letters - 1)(rng); + syllable[pos] = consonants[c_distr(rng)]; + } + name += syllable; + } + return name; + } + +private: + std::mt19937 rng; +}; + +int main() +{ + NameGenerator ng; + std::cout << ng.generate(); + return 0; +}