Last night I evaluated random things on IRC (freenode), but that is probably not a surprise to most. Someone else came along and did it too for the numbers 1 through 4. I also like the Lingua::EN::Inflect module. So, I took the person's random 1-4 and wrapped it in NUMWORDS and ORD. When I ran it through buubot the first time, I didn't get any fourths. I thought then said that no one made it home, referring to baseball.
About a month ago, Leverage, one of my favorite television programs, was centered around baseball. That is probably where the whole baseball thing came from.
So, here is where the oddball script comes into play. I wrote a little script that will randomly generate half an inning. The odder thing is, I don't like sports, so writing a script for baseball is really out there.
I have been told that I should work with other people on a project. I have gone about as far as I want to with this script. If anyone wants to tweak what is currently there or expand it, go for it. I am not a fan of baseball, so I don't know all the rules. What I have below is extraordinarily simplistic. All I know is that it was fun to write, and as fun to watch the results.
This script is notable because it is the first script that I have written from scratch that includes recursion. All other work with recursion I have done is with the help of others. That I recursed this one without help is one reason that I am so happy with and wanted to share it.
So, where did the idea for an oddball script you wrote come from? :)
use strict; use warnings; use Lingua::EN::Inflect qw(ORD NUMWORDS); my $pitch = 1; my $balls = 0; my $strikes = 0; my $outs = 0; my $score = 0; sub pitch { my $player = shift; my @pitch_results = qw(hit ball strike); my $pitch_result = $pitch_results[rand @pitch_results]; my $pitch_text = ucfirst ORD($pitch)." pitch:"; if ($pitch_result eq "ball") { ++$balls; if ($balls == 4) { my $base = ORD(NUMWORDS(1)); print "$pitch_text $player walks to $base base.\n"; } else { print "$pitch_text Ball ".NUMWORDS($balls)."\n"; ++$pitch; pitch($player); } } elsif ($pitch_result eq "strike") { ++$strikes; if ($strikes == 3) { print "$pitch_text $player stikes out!\n"; ++$outs; } else { print "$pitch_text Strike ".NUMWORDS($strikes)."!\n"; ++$pitch; pitch($player); } } else { my @hits = qw(good bad); my $hit = $hits[rand @hits]; if ($hit eq "bad") { my $strike_text = ""; if ($strikes < 2) { ++$strikes; $strike_text = "Strike ".NUMWORDS($strikes); } print "$pitch_text Foul ball! $strike_text\n"; ++$pitch; pitch($player); } else { my $base_num = (1..4)[rand 4]; my @bases = (1..$base_num); print "$pitch_text $player hits!\n"; for my $base (@bases) { my @tags = qw(yes no); my $tag = $tags[rand @tags]; if ($tag eq "no") { if ($base == 4) { print "\tHOME RUN!"; } else { print "\t$player makes it to ".NUMWORDS(ORD($base))." base +.\n"; } } else { if ($base == 4) { print "\t$player is out at the home plate.\n"; } else { print "\t$player is out at ".NUMWORDS(ORD($base))." base.\ +n"; ++$outs; last; } } } } } $pitch = 1; $balls = 0; $strikes = 0; } sub team { my $player_up = 1; until ($outs == 3) { print "Player ".NUMWORDS($player_up)."\n\n"; pitch("Player ".NUMWORDS($player_up)); print "\n"; ++$player_up; } print "Score: ".$score."\n"; $outs = 0; } team();
So, how did I do? :)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Where ideas for oddball scripts come from...
by JavaFan (Canon) on Mar 16, 2010 at 14:26 UTC | |
by Lady_Aleena (Priest) on Mar 16, 2010 at 23:06 UTC | |
|
Re: Where ideas for oddball scripts come from...
by hangon (Deacon) on Mar 16, 2010 at 19:35 UTC | |
by Lady_Aleena (Priest) on Mar 16, 2010 at 23:16 UTC | |
|
Re: Where ideas for oddball scripts come from...
by Lady_Aleena (Priest) on Mar 16, 2010 at 23:03 UTC |