The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 06-30-2007
hankooknara hankooknara is offline
Registered User
  
 

Join Date: Dec 2006
Posts: 80
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
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:14 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0