5 my $pumpkin = ["255/185/15", "0 0 0"];
6 my $green = ["0/238/118", "1 1 1"];
7 my $red = ["1 0 0", "0 0 0"];
8 my $blue = ["0 .4 1 ", "1 1 1"];
9 my $yellow = ["1 1 0", "0 0 0"];
10 my $moth = [" 0 0 0", "1 1 1"];
11 my $purple = ["145/44/238", "0 0 0"];
12 my $lotus = [("0/245/255",) x 2];
13 my $white = ["1 1 1", "0 0 0"];
15 my $anychip = ['0.8', '0'];
17 our $page_pre = <<END;
26 if ($c =~ m{^(\d+)/(\d+)/(\d+)$}) {
27 return (join ' ', map { $_ / 255.0 } ($1,$2,$3)).' setrgbcolor';
28 } elsif ($c =~ m/[^ 0-9.]/) {
30 } elsif ($c =~ m/^\s*\S+\s*$/) {
32 } elsif ($c =~ m/./) {
33 return "$c setrgbcolor";
39 our $black = colour('0');
42 my ($cary, $pips) = @_; # put in a gsave translate
45 0 0 chip 0.5 mul 0 360 arc
46 gsave 1 setlinewidth $black stroke grestore
47 ${\ colour($cary->[0]) } fill
51 ${\ colour($cary->[1]) }
58 spot 0.5 sqrt mul 1.1 mul dup
65 $spot->( 0, 0) if $pips & 1;
66 $spot->(-1,-1) if $pips & 6;
67 $spot->(+1,+1) if $pips & 6;
68 $spot->(-1,+1) if $pips & 4;
69 $spot->(+1,-1) if $pips & 4;
78 0 chip -0.5 mul translate
80 newpath 0 0 chip 0.5 mul 0 360 arc stroke
81 /Times-Bold findfont 7 scalefont setfont
85 -1 -1 moveto 6 0 rlineto 0 7 rlineto -6 0 rlineto
86 closepath 0.5 setlinewidth stroke
97 chip -0.5 mul $fsz -0.30 mul moveto
98 /Helvetica-Bold findfont $fsz scalefont setfont
99 (Any) dup stringwidth 3 2 roll show
102 ${\ chip($anychip, $pips) }
107 sub ruby () { # put in gsave translate
115 ${\ colour('1 .2 .2') } gsave fill grestore
116 $black 1 setlinewidth stroke
124 /Times-Roman findfont $fontsz scalefont setfont $black
127 my @lines = split /\n/, $text;
128 foreach my $y (0..$#lines) {
130 $l =~ s/[()\\]/\\$&/g;
131 my $yd = $fontsz * (0.5*@lines - $y);
135 ($l) dup stringwidth pop -0.5 mul 0 rmoveto
142 sub num_players ($;$) {
148 -0.94 0.50 dc translate
153 pot_image 18 0 translate
156 $o .= <<END if defined $plus;
158 /Helvetica-Bold findfont 25 scalefont setfont
168 sub general_book ($$) { # put in a gsave
169 my ($this, $costs) = @_;
191 0 thirdlineh dc rlineto
192 -1 thirdlineh dc lineto stroke
194 /thirddivline { % xprop
196 dup -3 div 0 dc moveto
197 -3 div thirdlineh dc lineto stroke
203 $o .= <<END if @$costs == 3;
208 foreach my $costi (0..2) {
211 $cost = $costs->[$costi];
212 $pips = qw(1 2 4)[$costi];
214 next unless $costi == 1;
220 -2.5 $costi add 3 div
222 dup costcirch dc translate
223 ${\ chip($this,$pips) }
225 costtexth exch costtextdx add exch dc moveto
228 dup stringwidth pop -0.5 mul costtextsz neg rmoveto
237 my $o = general_book($green, [qw(5 9 15)]);
240 gsave 0.25 0.15 dc translate ${\ chip($pumpkin,0) } grestore
241 gsave 0.25 0.40 dc translate ${\ chip($green,0) } grestore
246 0.40 0.17 dc moveto (last) show
249 0.40 0.09 dc moveto (3) show
250 /Times-Roman findfont
252 0.45 0.14 dc moveto (}) show
255 0.85 0.275 dc translate
260 $o .= exposition(<<END);
261 For each pumpkin in the last 3 chips,
263 But, not more rubies than the number
264 of green chips in your pot.
271 my $o = general_book($red, [qw(4 9 16)]);
274 gsave 0.35 0.30 dc translate ${\ chip($pumpkin,0) } grestore
278 0.50 0.24 dc moveto (+1) show
282 $o .= exposition(<<END);
283 The next 1/2/4 pumpkins you place are
284 each moved one extra space.
285 (After applying any other special effects;
286 one extra space no matter how many reds)
293 my $o = general_book($blue, [qw(4 10 18)]);
296 /Times-Bold findfont 15 scalefont setfont $black
299 0.50 0.65 dc translate
301 gsave -10 0 translate ${\ chip($pumpkin,1) } grestore
307 my ($that, $pips) = @_;
309 gsave ${\ chip($that, $pips) } grestore
320 my ($y, $pips, $content) = @_;
323 0.16 0.15 0.16 $y mul add dc translate
325 gsave ${\ chip($blue,$pips) } grestore
335 $o .= $exchline->(2, 1, <<END);
336 ${\ $exchip->($green,1) } ${\ $exslash->() }
337 ${\ $exchip->($red, 1) } ${\ $exslash->() }
338 ${\ $exchip->($blue, 1) } ${\ $exslash->() }
339 ${\ $exchip->($yellow, 1) }
342 $o .= $exchline->(1, 2, <<END);
343 ${\ $exchip->($moth,1) } ${\ $exslash->() }
344 ${\ $exchip->($purple,1) } ${\ $exslash->() }
348 $o .= $exchline->(0, 4, <<END);
352 $o .= exposition(<<END);
353 If the previous chip placed was a pumpkin,
354 you may exchange it as follows:
363 my $o = general_book($lotus, [8, 0]);
366 /Times-Bold findfont 15 scalefont setfont $black
369 0.36 0.38 dc translate
371 gsave ${\ chip($lotus,0) } grestore
376 0.20 0.15 dc translate
378 gsave ${\ chip($pumpkin,0) } grestore
379 chip 0.5 mul 0 translate
380 gsave ${\ chip($pumpkin,0) } grestore
382 10 -4.5 moveto (... +1) show
388 0.16 0.20 dc translate
391 gsave ${\ veepsspot(chip($pumpkin, 0)) } grestore
392 gsave 0 20 translate ${\ chip($purple, 1) } grestore
398 $o .= exposition(<<END);
399 The value of this chip is
400 1 higher than the number of pumpkins
401 previously placed in the pot (but max.4)
408 my $o = general_book($purple, [10, 1]);
411 gsave ${\ veepsspot(chip($pumpkin, 0)) } grestore
412 gsave 0 20 translate ${\ chip($purple, 1) } grestore
416 /Times-Bold findfont 15 scalefont setfont $black
418 0.16 0.20 dc translate
422 8 -12 moveto (...) show
428 /Times-Roman findfont
430 0.48 0.14 dc moveto (}) show
434 0.83 0.25 dc translate
436 ${\ chip($anychip, 0) }
440 0.72 0.22 dc translate
442 $black 0 0 moveto (?+?) show
446 $o .= exposition(<<END);
447 For each pumpkin in the pot (but
448 not more than the number of purple chips),
449 add up the VPs of the covered spaces.
450 Buy 1/2 chips of up to that total value.
460 foreach my $dd (ref $d ? @$d : $d) {
461 push @tiles, [ $dd, $index_i ];
475 while (my $di = pop @tiles) {
476 my ($d, $index) = @$di;
487 0 th 10 add $pos mul translate
492 dup th add 0 translate
494 $pos 3 sub mul 0 translate
500 /Courier-Bold findfont 6 scalefont setfont
513 my $o = general_book($yellow, [qw(7 12 19)]);
517 0.50 0.62 dc translate
520 gsave 26 0 translate ${\ chip($anychip,0) } grestore
521 gsave 46 0 translate ${\ chip($pumpkin,0) } grestore
522 gsave -30 rotate bag_image grestore
539 my ($that, $pips) = @_;
541 gsave ${\ chip($that, $pips) } grestore
552 my ($y, $pips, $content) = @_;
555 0.20 0.12 0.16 $y mul add dc translate
557 gsave ${\ chip($yellow,$pips) } grestore
567 $o .= $exchline->(2, 1, <<END);
568 ${\ $exchip->($white,1) } ${\ $exslash->() }
569 ${\ $exchip->($anychip,1) } ${\ $exslash->() }
570 ${\ $exchip->($lotus,0) }
573 $o .= $exchline->(1, 2, <<END);
574 ${\ $exchip->($white,2) } ${\ $exslash->() }
575 ${\ $exchip->($anychip,2) }
578 $o .= $exchline->(0, 4, <<END);
579 ${\ $exchip->($white,3) } ${\ $exslash->() }
580 ${\ $exchip->($anychip,4) }
583 $o .= exposition(<<END);
584 Put a chip, no bigger than the yellow,
585 whose next placed chip is a pumpkin,
594 sub black_common ($) {
597 /Helvetica-Bold findfont 5.5 scalefont setfont
603 3.5 -1 translate .7 dup scale
610 dup stringwidth .5 mul exch .5 mul exch translate
611 dup stringwidth -1 mul exch -1 mul exch moveto show
612 .7 dup scale 7 3 translate
631 newpath 0 0 moveto -18 0 rlineto stroke
634 ${\ chip($pumpkin,0) }
642 sub black_book_pair () {
643 my $o = general_book($moth, [10, 1]);
645 $o .= num_players(2);
646 $o .= black_common('equal:');
648 $o .= exposition(<<END);
649 The player with the shortest distance
650 between a black chip and a pumpkin
651 gets to move their droplet.
653 If tied, both players get a ruby.
659 sub black_book_more () {
660 my $o = general_book($moth, [10, 1]);
662 $o .= num_players(3,'+');
663 $o .= black_common('2nd:');
665 $o .= exposition(<<END);
667 The player(s) with the shortest distance
668 between a black chip and a pumpkin
669 get to move their droplet.
670 If only one player won a droplet, the other
671 players(s) with the next-shortest distance
678 sub arrow_any ($) { <<END;
679 $black 1 setlinewidth
683 arrowhead dup neg exch rmoveto
684 arrowhead dup neg rlineto
685 arrowhead neg dup rlineto
690 print <<END or die $!;
708 /costtextdx -0.03 def
709 /costfont /Heletica-BoldOblique findfont costtextsz scalefont def
713 % diagonal conversion
715 dup th mul % xprop yprop y
716 3 1 roll % y xprop yprop
717 bdiag mul neg % y xprop x-margin-at-this-height
718 tw add % y xprop x-width-at-this-height
719 exch mul % y x-width-at-this-height xprop
724 ${\ arrow_any("0 0 moveto arrowlen 0 rlineto") }
730 my ($ncomps, $name) = @_;
732 my $ext = $ncomps == 1 ? 'pgm' : $ncomps == 3 ? 'ppm' : die;
733 my $oper = $ncomps == 1 ? 'image' :
734 $ncomps == 3 ? 'false 3 colorimage' : die;
735 my $magic = $ncomps == 1 ? 'P2' : $ncomps == 3 ? 'P3' : die;
737 open B, "$name.$ext" or die $!;
738 <B> eq "$magic\n" or die "$name.$ext expected $magic";
740 my @d = split ' ', <B>;
745 my $maxval = shift @d;
746 die unless $maxval eq 255;
751 print <<END, '{<' or die $!;
754 [ -$sz 0 0 -$sz $w 2 div $h 2 div ]
756 for (my $i=0; $i< $w*$h*$ncomps; $i++) {
757 printf "%02x", shift @d or die $!;
759 print <<END or die $!;
767 def_image(3, "droplet");
769 print "gsave\n" or die $!;
778 [black_book_pair(), black_book_more()],