I agree. I would say it's the best way. My comment was about the "free course" you posted a link to, and only that. My apology if I sounded too critical of your post. I am sure people will find it useful as a tool to learn basic perl and cgi progamming.![]()
Regards,
Kevin
wow, there is a perl forum![]()
I scripted a game in perl, tic tac toe if anyone is intrested send me a pm![]()
A perl forum?What is the link of the link to your tic tac toe game? How long did it take to create?
#!/usr/local/bin/perl
use strict;
use warnings;
################################################## #############################################
# Created by Klumpi #
# #
# Italy/South Tirol #
# #
# #
# # #
# #
# #
# # #
################################################## #############################################
# Output imediatly
$|=1;
my $A1;
my $A2;
my $A3;
my $B1;
my $B2;
my $B3;
my $C1;
my $C2;
my $C3;
my $X;
my $O;
#
#Zuweisung der Felder den Koordinaten!
#
$A1="Feld1";
$A2="Feld2";
$A3="Feld3";
$B1="Feld4";
$B2="Feld5";
$B3="Feld6";
$C1="Feld7";
$C2="Feld8";
$C3="Feld9";
my $AMOGLICHKEITEN;
my $EINGABE=1;
#
#"Grafischer" Programmstart mit Entwicklung, Gebung der Namen und Auswahl des
#Spielers "X" oder "O"
#
print "Welcome to Tic Tac Toe created by Klumpi WARNING:Es kann zu Fehlern
w?§hrend des Spiels kommen!!\n";
print "Ok, lets begin\n";
print "What's your name?\n";
chomp(my $name= <STDIN>);
print "Hi, $name\n";
print "What would you like to be?\n";
print "X or O\n";
$AMOGLICHKEITEN= <STDIN>;
chomp $AMOGLICHKEITEN;
$AMOGLICHKEITEN =~ tr/a-z/A-Z/;
my $Player;
my $CPU;
do
{
if ($AMOGLICHKEITEN eq "X")
{
$Player = "X";
$CPU = "O";
}
elsif ($AMOGLICHKEITEN eq "O")
{
$Player = "O";
$CPU = "X";
}
else
{
print "Wrong input (X or O): ";
$AMOGLICHKEITEN= <STDIN>;
chomp $AMOGLICHKEITEN;
$AMOGLICHKEITEN =~ tr/a-z/A-Z/;
}
}
until (defined $Player);
print "Ok, you are $Player\n";
print "lets begin now, pick out between this capabilities\n\n";
#
#Schreiben der Felder im Skript mit Koords.
#
format STDOUT =
@||||| | @|||||| | @||||||
$A1, $B1, $C1,
--------------------------
@||||| | @|||||| | @||||||
$A2, $B2, $C2,
--------------------------
@||||| | @|||||| | @||||||
$A3, $B3, $C3
.
write;
print "\n";
#
#In der While Schleife spielt sich alles ab. Von der erweiterten Gebung der
#Zeilen bis hin zum Case Statement mit den
#verschiedenen Moglichkeiten zum Sieg zu gelange. Die einzelnen Zügeund
#dessen Moglichkei derinerseits und
#gegenuber des CPU
#
my @Feld;
my $rand;
while (1)
{
SWITCH:
{
chomp($EINGABE = <STDIN>);
my @felder = qw(Feld1 Feld2 Feld3 Feld4 Feld5 Feld6 Feld7 Feld8 Feld9);
my @ref = (\$A1, \$A2, \$A3, \$B1, \$B2, \$B3, \$C1, \$C2, \$C3);
my $i = 0;
unless ($EINGABE =~ /Feld(1|2|3|4|5|6|7|8|9)/)
{
print "Wrong input: ";
chomp($EINGABE = <STDIN>);
}
foreach (@felder)
{
if ($EINGABE eq "$_" )
{
print "$i.Durchgang: ${$ref[$i]}\n";
if (${$ref[$i]} eq "$_") #dereferenzieren der Referenzen in @ref
{
${$ref[$i]} = $AMOGLICHKEITEN;
print "Choice: $_\n";
last SWITCH;
}
else
{
print "Noob, already used!! ";
goto SWITCH;
}
}
$i++;
}
} #SWITCH Ende
&finish();
print "Now the computer is moving";
for (my $i=0;$i<5;$i++) { print ". "; sleep 1; }
print "\n";
&compmove;
#
#Das Drucken der aktualisierten Felder mit den X und O Variablen
#
print "\n";
write;
print "\n";
}
#
#Die If Schleifen die dan bekannt geben wenn du gewonnen hast oder der CPU
#Auf die If Schleife wird wie Vorhergesehen mit den elsif "geantwortet"
#Sollte das Spiel entschieden sein und der Sieger festliegt,
#steigt das Programm mit den Befehl im unteren Teil= exit 0 aus.
#
&finish();
sub finish
{
if ($A1 eq "X" && $A2 eq "X" && $A3 eq "X") {
print "X wins\n";
exit 0;}
elsif ($B1 eq "X" && $B2 eq "X" && $B3 eq "X") {
print "X WINS \n";
exit 0;}
elsif ($C1 eq "X" && $C2 eq "X" && $C3 eq "X") {
print "X WINS\n";
exit 0;}
elsif ($A1 eq "X" && $B1 eq "X" && $C1 eq "X") {
print "X WINS\n";
exit 0;}
elsif ($A2 eq "X" && $B2 eq "X" && $C2 eq "X") {
print "X WINS\n";
exit 0;}
elsif ($A3 eq "X" && $B3 eq "X" && $C3 eq "X") {
print "X WINS\n";
exit 0;}
elsif ($A1 eq "X" && $B2 eq "X" && $C3 eq "X") {
print "X WINS!!\n";
exit 0;}
elsif ($C1 eq "X" && $B2 eq "X" && $A3 eq "X") {
print "X WINS!!\n";
exit 0;}
#
#Die if Schleifen die angeben ob der Computer gewonnen hat oder auch nicht
#
if ($A1 eq "O" && $A2 eq "O" && $A3 eq "O") {
print "O wins\n";
exit 0;}
elsif ($B1 eq "O" && $B2 eq "O" && $B3 eq "O") {
print "O WINS \n";
exit 0;}
elsif ($C1 eq "O" && $C2 eq "O" && $C3 eq "O") {
print "O WINS\n";
exit 0;}
elsif ($A1 eq "O" && $B1 eq "O" && $C1 eq "O") {
print "O WINS\n";
exit 0;}
elsif ($A2 eq "O" && $B2 eq "O" && $C2 eq "O") {
print "O WINS\n";
exit 0;}
elsif ($A3 eq "O" && $B3 eq "O" && $C3 eq "O") {
print "O WINS\n";
exit 0;}
elsif ($A1 eq "O" && $B2 eq "O" && $C3 eq "O") {
print "O WINS!!\n";
exit 0;}
elsif ($C1 eq "O" && $B2 eq "O" && $A3 eq "O") {
print "O WINS!!\n";
exit 0;}
}
#
#Sub ist der Pseudoalgorythmus der in Tic Tac Toe den Gegner simuliert.
#
sub compmove
{
my $gefunden = 0;
do
{
@Feld = (\$A1, \$A2, \$A3, \$B1, \$B2, \$B3, \$C1, \$C2, \$C3);
$rand= int(rand 9);
unless (${$Feld[$rand]} eq "X" || ${$Feld[$rand]} eq "O")
{
print "CPU: ${$Feld[$rand]}\n";
${$Feld[$rand]} = $CPU;
$gefunden = 1;
}
}
until ($gefunden == 1);
}
It's an older script! and the most of it is in german![]()
Sorry, my Englisch is not the best
it's not really nice of you to "hijack" this thread. You could have started a new thread if you wanted to share your tic-tac-toe script. This thread is about a perl tutorial.
Sorry, but he asked for it
Thanks for posting that..and I don't mind that you posted in my thread since my question initiated your response..Keep up the good work![]()
So the topic was free perl tutorial.are there more out there?
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks