![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| MKGI Chess Club 2.1.0 (Default branch) | iBot | Software Releases - RSS News | 0 | 01-21-2008 09:00 PM |
| Perl questions - more | frustrated1 | Shell Programming and Scripting | 7 | 10-08-2007 06:38 PM |
| perl questions | frustrated1 | Shell Programming and Scripting | 7 | 10-01-2007 05:52 AM |
| Perl: answering automatically to install questions | zaap | Shell Programming and Scripting | 2 | 02-26-2006 12:14 AM |
| bash and Perl interaction questions | deryk | Shell Programming and Scripting | 2 | 10-12-2005 05:25 PM |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
chess perl program questions
Hello guys,
While going over the book, I ran into this chess program and I have few questions 1) on line 40), why is not $chessboard[$startx]->[$starty] ) ??? 40 unless (defined $chessboard[$starty]->[$startx]) { 2) 20 foreach my $i (reverse (0..7)) { #Row 1 #!/usr/bin/perl -w 2 # 3 # 4 5 6 use strict; 7 8 my @chessboard; 9 my @back = qw(R N B Q K N B R); 10 11 foreach (0..7) { 12 $chessboard[0]->[$_] = "W" . $back[$_]; #white Back Row 13 $chessboard[1]->[$_] = "WP" ; #white Pawns 14 $chessboard[6]->[$_] = "BP" ; #Black Pawns 15 $chessboard[7]->[$_] = "B" . $back[$_]; #Black Back Row 16 } 17 18 while (1) { 19 # Print board 20 foreach my $i (reverse (0..7)) { #Row 21 foreach my $j (0..7) { #Column 22 if (defined $chessboard[$i]->[$j]) { 23 print $chessboard[$i]->[$j]; 24 } elsif ( ($i % 2) == ($j % 2) ) { 25 print ".."; 26 } else { 27 print " "; 28 } 29 print " "; #End of cell 30 } 31 print "\n"; #End of row 32 } 33 34 print "\nStarting square [x,y]: "; 35 36 my $move = <>; 37 last unless ($move =~ /^\s*([1-8]),([1-8])/); 38 my $startx = $1-1; my $starty = $2-1; 39 40 unless (defined $chessboard[$starty]->[$startx]) { 41 print "There nothing on that square\n"; 42 next; 43 } 44 45 print "\nEnding square [x,y]: "; 46 $move = <>; 47 48 last unless ($move =~ /([1-8]),([1-8])/); 49 my $endx = $1-1; my $endy = $2-1; 50 51 # put starting square on ending square. 52 $chessboard[$endy]->[$endx] = $chessboard[$starty]->[$startx]; 53 54 #remove from old square 55 undef $chessboard[$starty]->[$startx]; 56 } |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|