Skip to content

Commit 3ebb958

Browse files
Merge pull request #854 from kbrannen/86-target-perl
86 target perl
2 parents 5d4ad7f + 1e5a045 commit 3ebb958

File tree

2 files changed

+113
-0
lines changed

2 files changed

+113
-0
lines changed

86_Target/perl/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
Original source downloaded [from Vintage Basic](http://www.vintage-basic.net/games.html)
22

33
Conversion to [Perl](https://www.perl.org/)
4+
5+
Modified so that if the user enters "quit" or "stop" for the input, the program will exit.
6+
This way the user doesn't have to enter Contorl-C to quit.
7+
8+
Target values can be space and/or comma separated, so "1 2 3" is valid, as is "1,2,3" or even "1, 2, 3".
9+
I believe the original Basic program wanted "1,2,3" or else each on a separate line.

86_Target/perl/target.pl

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
#!/usr/bin/perl
2+
3+
# Target program in Perl
4+
# Modified so that if the user enters "quit" or "stop" for the input, the program will exit.
5+
# Values can be space and/or comma separated.
6+
# Translated by Kevin Brannen (kbrannen)
7+
8+
use strict;
9+
use warnings;
10+
11+
# globals
12+
my $R = 1;
13+
my $R1 = 57.296;
14+
my $Pi = 3.14159;
15+
16+
print "\n";
17+
print " " x 33, "TARGET\n";
18+
print " " x 15, "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY\n\n\n";
19+
20+
print "YOU ARE THE WEAPONS OFFICER ON THE STARSHIP ENTERPRISE\n";
21+
print "AND THIS IS A TEST TO SEE HOW ACCURATE A SHOT YOU\n";
22+
print "ARE IN A THREE-DIMENSIONAL RANGE. YOU WILL BE TOLD\n";
23+
print "THE RADIAN OFFSET FOR THE X AND Z AXES, THE LOCATION\n";
24+
print "OF THE TARGET IN THREE DIMENSIONAL RECTANGULAR COORDINATES,\n";
25+
print "THE APPROXIMATE NUMBER OF DEGREES FROM THE X AND Z\n";
26+
print "AXES, AND THE APPROXIMATE DISTANCE TO THE TARGET.\n";
27+
print "YOU WILL THEN PROCEEED TO SHOOT AT THE TARGET UNTIL IT IS\n";
28+
print "DESTROYED!\n\n";
29+
print "GOOD LUCK!!\n\n";
30+
31+
while (1)
32+
{
33+
my $A = rand(1) * 2 * $Pi;
34+
my $B = rand(1) * 2 * $Pi;
35+
my $P1 = 100000 * rand(1) + rand(1);
36+
my $X = sin($B) * cos($A) * $P1;
37+
my $Y = sin($B) * sin($A) * $P1;
38+
my $Z = cos($B) * $P1;
39+
print "RADIANS FROM X AXIS = $A FROM Z AXIS = $B\n";
40+
print "TARGET SIGHTED: APPROXIMATE COORDINATES: X=$X Y=$Y Z=$Z\n";
41+
42+
while (1)
43+
{
44+
my $P3;
45+
$R++;
46+
47+
if ($R == 1) { $P3 = int($P1 * .05) * 20; }
48+
elsif ($R == 2) { $P3 = int($P1 * .1) * 10; }
49+
elsif ($R == 3) { $P3 = int($P1 * .5) * 2; }
50+
elsif ($R == 4) { $P3 = int($P1); }
51+
else { $P3 = $P1; }
52+
53+
print " ESTIMATED DISTANCE: $P3\n\n";
54+
print "INPUT ANGLE DEVIATION FROM X, DEVIATION FROM Z, DISTANCE: ";
55+
chomp(my $ans = lc(<>));
56+
exit(0) if ($ans eq "quit" || $ans eq "stop");
57+
58+
my ($A1, $B1, $P2) = split(/[,\s]+/, $ans);
59+
print "\n";
60+
61+
if ($P2 >= 20)
62+
{
63+
$A1 /= $R1;
64+
$B1 /= $R1;
65+
print "RADIANS FROM X AXIS = $A1 FROM Z AXIS = $B1\n";
66+
my $X1 = $P2 * sin($B1) * cos($A1);
67+
my $Y1 = $P2 * sin($B1) * sin($A1);
68+
my $Z1 = $P2 * cos($B1);
69+
my $D = (($X1 - $X) ** 2 + ($Y1 - $Y) ** 2 + ($Z1 - $Z) ** 2) ** (0.5);
70+
71+
if ($D <= 20)
72+
{
73+
print "\n * * * HIT * * * TARGET IS NON-FUNCTIONAL\n";
74+
print "\nDISTANCE OF EXPLOSION FROM TARGET WAS $D KILOMETERS.\n";
75+
print "\nMISSION ACCOMPLISHED IN $R SHOTS.\n";
76+
last;
77+
}
78+
else
79+
{
80+
my $X2 = $X1 - $X;
81+
my $Y2 = $Y1 - $Y;
82+
my $Z2 = $Z1 - $Z;
83+
84+
if ($X2 < 0) { print "SHOT BEHIND TARGET ", -$X2, " KILOMETERS.\n"; }
85+
else { print "SHOT IN FRONT OF TARGET $X2 KILOMETERS.\n"; }
86+
87+
if ($Y2 < 0) { print "SHOT TO RIGHT OF TARGET ", -$Y2, " KILOMETERS.\n"; }
88+
else { print "SHOT TO LEFT OF TARGET $Y2 KILOMETERS.\n"; }
89+
90+
if ($Z2 < 0) { print "SHOT BELOW TARGET ", -$Z2, " KILOMETERS.\n"; }
91+
else { print "SHOT ABOVE TARGET $Z2 KILOMETERS.\n"; }
92+
93+
print "APPROX POSITION OF EXPLOSION: X=$X1 Y=$Y1 Z=$Z1\n";
94+
print " DISTANCE FROM TARGET = $D\n\n\n";
95+
next;
96+
}
97+
}
98+
else
99+
{
100+
print "YOU BLEW YOURSELF UP!!\n";
101+
last;
102+
}
103+
}
104+
105+
$R = 0;
106+
print "\n\n\n\n\nNEXT TARGET...\n\n";
107+
}

0 commit comments

Comments
 (0)