| 1 | package Games::Crosswords; | ||||||||||||||
| 2 | 1 | ▶ | use 5.006; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | 1 | our $VERSION = '0.01'; | |||||||||||||
| 6 | |||||||||||||||
| 7 | 0 | ▶ | sub isvalidtable($){ | ||||||||||||
|
Subroutine
isvalidtable: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||
| 8 | 0 | ▶ | caller eq __PACKAGE__ or die; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 9 | 0 | my $len = 0; | |||||||||||||
| 10 | 0 | for my $l (grep {$_} split //, $_[0]){ | |||||||||||||
| 11 | 0 | ▶ | $len = length $l unless $len; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 12 | 0 | ▶ | return 0 unless $len == length $l; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 13 | } | ||||||||||||||
| 14 | 0 | $len; | |||||||||||||
| 15 | } | ||||||||||||||
| 16 | |||||||||||||||
| 17 | 0 | ▶ | sub new { | ||||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||
| 18 | 0 | ▶ | isvalidtable $_[1]->{TABLE} or die "Table is not valid"; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 19 | 0 | bless{ _TABLE => $_[1]->{TABLE}, _LEXICON => $_[1]->{LEXICON} }, $_[0]; | |||||||||||||
| 20 | } | ||||||||||||||
| 21 | |||||||||||||||
| 22 | 0 | ▶ | sub table { | ||||||||||||
|
Subroutine
table: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||
| 23 | 0 | ▶ | isvalidtable $_[1] or die "Table is not valid"; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 24 | 0 | $_[0]->{_TABLE} = $_[1]; | |||||||||||||
| 25 | } | ||||||||||||||
| 26 | |||||||||||||||
| 27 | 0 | ▶ | sub lexicon { $_[0]->{_LEXICON} = $_[1] } | ||||||||||||
|
Subroutine
lexicon: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 28 | |||||||||||||||
| 29 | 0 | ▶ | sub getdim($) { | ||||||||||||
|
Subroutine
getdim: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 30 | 0 | my @table = split /\n/, shift; | |||||||||||||
| 31 | 0 | my ($x) = length ($table[0]); | |||||||||||||
| 32 | 0 | my ($y) = scalar @table; | |||||||||||||
| 33 | 0 | return ($x, $y); | |||||||||||||
| 34 | } | ||||||||||||||
| 35 | |||||||||||||||
| 36 | 0 | ▶ | sub mklexarr { | ||||||||||||
|
Subroutine
mklexarr: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||
| 37 | 0 | ▶ | caller eq __PACKAGE__ or die; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 38 | 0 | @{$_[0]->{_LEXICON_ARR}} = (); | |||||||||||||
| 39 | 0 | for my $o (qw/ACROSS DOWN/){ | |||||||||||||
| 40 | 0 | for my $e (@{$_[0]->{_LEXICON}->{$o}}){ | |||||||||||||
| 41 | 0 | push @{$_[0]->{_LEXICON_ARR}}, [ $e->[0], $e->[1], $o, $e->[2], $e->[3] ]; | |||||||||||||
| 42 | } | ||||||||||||||
| 43 | } | ||||||||||||||
| 44 | } | ||||||||||||||
| 45 | |||||||||||||||
| 46 | |||||||||||||||
| 47 | 0 | ▶ | sub genpuzzle { _generate($_[0], 'puzzle', $_[1]) } | ||||||||||||
|
Subroutine
genpuzzle: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 48 | 0 | ▶ | sub gensolution { _generate($_[0], 'solution', $_[1]) } | ||||||||||||
|
Subroutine
gensolution: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 49 | |||||||||||||||
| 50 | 0 | ▶ | sub _generate { | ||||||||||||
|
Subroutine
_generate: not called CC=17 SCAR=57.2
| |||||||||||||||
| 51 | 0 | ▶ | caller eq __PACKAGE__ or die; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 52 | |||||||||||||||
| 53 | 0 | my $HEAD=<<HEAD; | |||||||||||||
| 54 | \\documentclass[letterpaper]{article} | ||||||||||||||
| 55 | \\usepackage{texdraw} | ||||||||||||||
| 56 | \\begin{document} | ||||||||||||||
| 57 | \\begin{texdraw} | ||||||||||||||
| 58 | HEAD | ||||||||||||||
| 59 | |||||||||||||||
| 60 | 0 | my $FOOT=<<FOOT; | |||||||||||||
| 61 | \\end{texdraw} | ||||||||||||||
| 62 | \\end{document} | ||||||||||||||
| 63 | FOOT | ||||||||||||||
| 64 | |||||||||||||||
| 65 | 0 | my %dim; | |||||||||||||
| 66 | 0 | @dim{qw/x y/} = getdim( $_[0]->{_TABLE}); | |||||||||||||
| 67 | 0 | my $arr; | |||||||||||||
| 68 | 0 | my ($dx, $dy) = (0.9, 0.9); | |||||||||||||
| 69 | 0 | my $tex="\\drawdim{cm} \\linewd 0.03 "; | |||||||||||||
| 70 | |||||||||||||||
| 71 | 0 | my $i=0; | |||||||||||||
| 72 | 0 | for my $L (split /\n/, $_[0]->{_TABLE}){ @{$arr->[$i++]} = split //, $L } | |||||||||||||
| 73 | |||||||||||||||
| 74 | # draws the cells | ||||||||||||||
| 75 | 0 | ▶ | for(my $i=0; $i<$dim{y}; $i++){ | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 76 | 0 | ▶ | for(my $j=0; $j<$dim{x}; $j++){ | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 77 | 0 | $tex.="\\move(@{[$j*$dx]} -@{[$i*$dy]}) "; | |||||||||||||
| 78 | 0 | $tex.="\\rlvec(0 -$dy) \\rlvec($dx 0) \\rlvec(0 $dy) \\rlvec(-$dx 0) "; | |||||||||||||
| 79 | 0 | ▶ | if( $arr->[$i]->[$j] eq '@' ){ | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 80 | 0 | $tex.="\\lfill f:0.1 "; | |||||||||||||
| 81 | } | ||||||||||||||
| 82 | } | ||||||||||||||
| 83 | } | ||||||||||||||
| 84 | |||||||||||||||
| 85 | 0 | mklexarr($_[0]); | |||||||||||||
| 86 | |||||||||||||||
| 87 | 0 | ▶ | if($_[1] eq 'puzzle'){ | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 88 | 0 | $tex.="\\move(0 -@{[(1+$dim{y})*$dy ]}) \\htext{ACROSS} "; | |||||||||||||
| 89 | 0 | $tex.="\\move(7 -@{[(1+$dim{y})*$dy ]}) \\htext{DOWN} "; | |||||||||||||
| 90 | |||||||||||||||
| 91 | 0 | my $j=0; | |||||||||||||
| 92 | 0 | my $i=1; | |||||||||||||
| 93 | 0 | my %i; | |||||||||||||
| 94 | 0 | @i{qw/down across/} = qw/1 1/; | |||||||||||||
| 95 | 0 | my $sno=1; | |||||||||||||
| 96 | 0 | my %sno; | |||||||||||||
| 97 | |||||||||||||||
| 98 | 0 | for my $entry ( | |||||||||||||
| 99 | 0 | sort { $a->[0] <=> $b->[0] } | |||||||||||||
| 100 | 0 | sort { $a->[1] <=> $b->[1] } | |||||||||||||
| 101 | 0 | @{$_[0]->{_LEXICON_ARR}} | |||||||||||||
| 102 | ){ | ||||||||||||||
| 103 | |||||||||||||||
| 104 | $sno = defined $sno{$entry->[0].q/./.$entry->[1]} ? | ||||||||||||||
| 105 | 0 | ▶ | $sno{$entry->[0].q/./.$entry->[1]} : $i; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 106 | |||||||||||||||
| 107 | 0 | ▶ | if($entry->[2] eq 'ACROSS'){ | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 108 | 0 | $tex.="\\move(0 -@{[(1+($i{across})*0.5+$dim{y})*$dy]}) "; | |||||||||||||
| 109 | 0 | $tex.="\\small \\htext{$sno $entry->[3]} "; | |||||||||||||
| 110 | 0 | $i{across}++; | |||||||||||||
| 111 | } | ||||||||||||||
| 112 | elsif($entry->[2] eq 'DOWN'){ | ||||||||||||||
| 113 | 0 | $tex.="\\move(7 -@{[(1+($i{down})*0.5+$dim{y})*$dy]}) "; | |||||||||||||
| 114 | 0 | $tex.="\\small \\htext{$sno $entry->[3]} "; | |||||||||||||
| 115 | 0 | $i{down}++; | |||||||||||||
| 116 | } | ||||||||||||||
| 117 | |||||||||||||||
| 118 | 0 | $tex.="\\move(@{[$entry->[1]*$dx + 0.1]} -@{[$entry->[0]*$dy + 0.4]}) "; | |||||||||||||
| 119 | 0 | $tex.="\\htext{$sno} "; | |||||||||||||
| 120 | |||||||||||||||
| 121 | 0 | ▶ | unless($sno{$entry->[0].q/./.$entry->[1]}){ | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 122 | 0 | $sno{$entry->[0].q/./.$entry->[1]} = $i; | |||||||||||||
| 123 | 0 | $i++; | |||||||||||||
| 124 | } | ||||||||||||||
| 125 | } | ||||||||||||||
| 126 | |||||||||||||||
| 127 | } | ||||||||||||||
| 128 | elsif($_[1] eq 'solution'){ | ||||||||||||||
| 129 | 0 | for my$entry ( @{$_[0]->{_LEXICON_ARR}} ){ | |||||||||||||
| 130 | 0 | my $i=0; | |||||||||||||
| 131 | 0 | for my $letter (split //, $entry->[4]){ | |||||||||||||
| 132 | 0 | ▶ | $tex .= $entry->[2] eq 'ACROSS' ? | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 133 | 0 | "\\move(@{[($entry->[1]+$i++)*$dx + 0.2]} -@{[$entry->[0]*$dy + 0.65]}) " : "\\move(@{[$entry->[1]*$dx + 0.2]} -@{[($entry->[0]+$i++)*$dy + 0.65]}) " ; | |||||||||||||
| 134 | |||||||||||||||
| 135 | 0 | $tex.="\\LARGE \\htext{@{[uc$letter]}} "; | |||||||||||||
| 136 | } | ||||||||||||||
| 137 | |||||||||||||||
| 138 | } | ||||||||||||||
| 139 | } | ||||||||||||||
| 140 | |||||||||||||||
| 141 | 0 | ▶ | if($_[2]){ | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 142 | 0 | open F, '>', $_[2]; | |||||||||||||
| 143 | 0 | print F $HEAD.$tex.$FOOT; | |||||||||||||
| 144 | 0 | close F; | |||||||||||||
| 145 | } | ||||||||||||||
| 146 | else{ | ||||||||||||||
| 147 | 0 | $HEAD.$tex.$FOOT; | |||||||||||||
| 148 | } | ||||||||||||||
| 149 | } | ||||||||||||||
| 150 | |||||||||||||||
| 151 | |||||||||||||||
| 152 | 1 | 1; | |||||||||||||
| 153 | __END__ | ||||||||||||||