doodul/source/doodul/wordlist.d

43 lines
780 B
D

module doodul.wordlist;
import std.file : readText;
import std.algorithm : filter, all, fold;
import std.array : array;
import std.functional : not;
import std.random : choice, randomSample;
import std.uni : isWhite;
import std.string : splitLines, capitalize;
WordList defaultWordList;
class WordList
{
string name;
string path;
string[] words;
this(string name, string path)
{
this.name = name;
this.path = path;
this.words = path.readText.splitLines;
}
string getRandomNickname()
{
return words.filter!(all!(not!isWhite)).array.choice;
}
string getRandomLobbyId()
{
return words.filter!(all!(not!isWhite)).array.randomSample(4).fold!((a,b) => a ~ b.capitalize)("");
}
}
static this()
{
defaultWordList = new WordList("English", "./wordlist");
}