#!/usr/bin/perl use strict; # multiplayer upwords use warnings; use 5.016; use Path::Tiny; use Data::Dump; ## paths and constraints @ARGV or @ARGV = qw( one two three four ); # for testing my $abs = path(__FILE__)->absolute; my $path1 = Path::Tiny->cwd; my %var; #main data structure my $ref_var = \%var; $var{abs} = $abs; $var{cwd} = $path1; $ref_var = init_vars($ref_var); my ( $board, $heights ) = create_board($ref_var); my @dictwords = create_dict($ref_var); my @drawpile = create_draw_pile(); ### re-wire for H2O use Util::H2O; my $hash = h2o $ref_var; print $hash->max_tiles, "\n"; #$var{max_tiles} * @ARGV > @drawpile and die "too many players for tiles\n"; # Can I get past this line? $hash->max_tiles* @ARGV > @drawpile and die "too many players for tiles\n"; say "survived to read this"; #$hash->x("z"); # setter dd $hash; sub x { my $value = shift; say "$value"; } sub init_vars { use Path::Tiny; use Data::Dump; use 5.016; use warnings; use POSIX qw(strftime); my $rvars = shift; my %vars = %$rvars; my $script = $vars{abs}; my $path1 = $vars{cwd}; my $games = "games"; my $path2 = path( $path1, $games ); say "abs is $abs"; say "path1 is $path1"; say "path2 is $path2"; print "This script will build the above path2. Proceed? (y|n)"; my $prompt = ; chomp $prompt; die unless ( $prompt eq "y" ); $vars{side} = 9; $vars{d_file} = path( "my_data", 'enable1.txt' ); $vars{ca_name} = path( "my_data", "words.11108138.$vars{side}" ); my $munge = strftime( "%d-%m-%Y-%H-%M-%S", localtime ); $munge .= ".txt"; $vars{save_file} = path( $path2, $munge )->touchpath; $vars{save_file}->append_utf8("Script executing is $script\n"); # other initializations $vars{max_tiles} = 7; $vars{n_1} = $vars{side} + 1; $rvars = \%vars; #dd $rvars; say "exiting init"; return ($rvars); } sub create_board { use warnings; use 5.016; my $rvars = shift; my %vars = %$rvars; my $board = ( '.' x $vars{side} . "\n" ) x $vars{side}; my $heights = $board =~ tr/./0/r; return ( $board, $heights ); } sub create_dict { my $rvars = shift; my %vars = %$rvars; use strict; # was 7.word.pl before becoming subroutine use warnings; use Path::Tiny; use Data::Dump; use 5.016; use POSIX qw(strftime); my $cachefilename = path( "my_data", "upwords." . $vars{n_1} ); my $download_file = '/home/hogan/Documents/hogan/my_data/1.english.txt'; unless ( -s $cachefilename && -s $download_file ) { use LWP::Simple; my $url = 'https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/dotnetperls-controls/enable1.txt'; say "execution was here"; getstore( $url, $download_file ); } ## substitute q for qu my $dictionaryfile = path($download_file); my @dictwords; if ( -s $cachefilename ) { @dictwords = path($cachefilename)->lines( { chomp => 1 } ); } unless ( -s $cachefilename ) { print "sub q for qu"; @dictwords = path($dictionaryfile)->lines( { chomp => 1 } ); s/qu/q/g for @dictwords; # some words shortened # cache the ones of maxtiles length @dictwords = grep( /^[a-z]{2,$vars{n_1}}\z/, @dictwords ); $cachefilename->spew( join "\n", @dictwords, '' ); } my $refDict = \@dictwords; return @dictwords; } sub create_draw_pile { use List::Util qw( shuffle ); use warnings; use 5.016; my @drawpile = shuffle + # thanks to GrandFather 11108145 ('a') x 7, ('b') x 3, ('c') x 4, ('d') x 5, ('e') x 8, ('f') x 3, ('g') x 3, ('h') x 3, ('i') x 7, ('j') x 1, ('k') x 2, ('l') x 5, ('m') x 5, ('n') x 5, ('o') x 7, ('p') x 3, ('q') x 1, ('r') x 5, ('s') x 6, ('t') x 5, ('u') x 5, ('v') x 2, ('w') x 2, ('x') x 1, ('y') x 2, ('z') x 1; return @drawpile; } __END__