-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWordGenerator.pm
82 lines (74 loc) · 2.28 KB
/
WordGenerator.pm
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/perl
package RegolfDB;
use strict;
use warnings;
require Exporter;
our @ISA = qw( Exporter );
our @EXPORT = qw( word_grab word_generate @good @bad $wordlist $roundwordlist );
our $wordlist = '/usr/share/dict/words'; # This is our big dictionary of words to pick from. ideally we will make the words similar in some way.
our $roundwordlist;
our @good = ();
our @bad = (); # two lists
my $usefilters = 0;
my @filters = ();
if($usefilters){
@filters = ('(\w{3}).*\1', '^_0.*_0$', '^[qwertyuiopasdfghjkl]+$', '^[a-f]+$', '=', '_0_1_2', '^(.)(.)(.?)(.?)(.?)(.?).?\6\5\4\3\2\1$');
} else {
@filters = ('.');
}
my @characters = ("a".."z");
sub word_grab {
my ($self, $amt) = @_;
my @words = ();
my $f = undef;
while(@words <= ($amt * 2)){
@words = ();
$f = $filters[rand @filters];
if( $f eq "="){
my $num = int(rand(7)+2);
print STDOUT $num;
for my $n(1000..100000){
push @words, $n if $n % $num == 0;
}
} else {
for my $j (0..9) {
my $letter = $characters[rand @characters];
$f =~ s/_$j/$letter/g;
}
print STDOUT "$f\n";
open WORDS, '<', $roundwordlist or die "Cannot open $roundwordlist:$!";
while(my $word = <WORDS>){
chomp($word);
push @words, $word if $word =~ /^[a-z]{2,}$/i and $word =~ /$f/i; # filter out names with capitol letters as well as apostrophes and stuff; apply a certain filter
}
close WORDS;
}
}
return (\@words, $f);
}
sub word_generate {
my $self = shift;
print STDOUT "Generating words.\n";
my $amt = int(rand(5)+3); # from 3-8 words
if(int(rand(15)) == 10 && $usefilters){
print STDOUT "Special round! Using two different sets this time.";
my ($word_ref, $f) = $self->wordset($amt);
my @words = @{$word_ref};
@words = shuffle(@words);
@good = @words[0 .. ($amt-1)]; # get the first <x> words
@words = $self->wordset($amt);
@words = shuffle(@words);
@bad = @words[0 .. ($amt-1)];
for my $bd (@bad){
@good = grep {$_ ne $bd} @good;
}
db_round_init($f, \@good, \@bad);
} else {
my ($word_ref, $f) = $self->wordset($amt * 2);
my @words = shuffle(@{$word_ref});
@good = @words[0 .. ($amt - 1)];
@bad = @words[$amt .. (($amt * 2) - 1)];
db_round_init($f, \@good, \@bad);
}
}
1;