Sponsored Content
Full Discussion: chess perl program questions
Top Forums Shell Programming and Scripting chess perl program questions Post 302124433 by hankooknara on Saturday 30th of June 2007 10:19:57 PM
Old 06-30-2007
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 }
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

bash and Perl interaction questions

hi. i´m working in bash and am trying to create a Perl daemon that controls bash´s behavior. this is actually in preparation for a later project i´ll be working on. basically, i´m looking for a way to have the Perl daemon tell bash what to do. i already have a small daemon that simply prints... (2 Replies)
Discussion started by: deryk
2 Replies

2. Shell Programming and Scripting

Perl: answering automatically to install questions

Hi everybody, I have been looking for an answer to this issue both on google and on the forum, but I couldn't find anything. please help me :eek: As part of an automated (in perl) install of Solaris 9, I would like to be able to answer automaticaly to the question the installer asks.... (2 Replies)
Discussion started by: zaap
2 Replies

3. Shell Programming and Scripting

perl questions

New to perl and a few questions - usually used to shell scripting but have to write a script to check a few things on windows server and need help.. 1. Check for file missing in sequence.. ie. list of file in directory as follows: file0001.txt file0002.txt file0004.txt file0005.txt... (7 Replies)
Discussion started by: frustrated1
7 Replies

4. Shell Programming and Scripting

Perl questions - more

More questions for Perl on Windows (again I apologize its on windows... ) 1. How can I check free disk space on a drive in windows using perl command in a script? 2. How can I check processes running using perl command (as I would normally be able to see in task manager for example) 3. I... (7 Replies)
Discussion started by: frustrated1
7 Replies

5. Shell Programming and Scripting

How to answer the Questions in Perl .

I need to write a script to telnet or ssh a device the execute some commands in device then copy the output in a file, I wrote the script but I faced one issue, when you execute some commands the device asked me a Question, for example : device # copy run tftp device # Source filename ? ... (3 Replies)
Discussion started by: DarkSoul
3 Replies

6. Shell Programming and Scripting

Perl newbie questions!

Hi, So I started to learn perl a few days ago, and I have some problems... One of my problems... #!C:\Perl64\bin\perl.exe -w use LWP::Simple; print "Content-Type: Text/Plain\n\n"; sub pagelinks { return @all = get($_) =~ /href\s*=\s*"?(+)/gis; } @a =... (5 Replies)
Discussion started by: byte1918
5 Replies

7. Homework & Coursework Questions

Calling compiled C program with Perl program

Long story short: I'm working inside of a Unix SSH under a bash shell. I have to code a C program that generates a random number. Then I have to call the compiled C program with a Perl program to run the C program 20 times and put all the generated random #s into a text file, then print that text... (1 Reply)
Discussion started by: jdkirby
1 Replies

8. UNIX for Dummies Questions & Answers

Two questions. First one; What are the ways in which a program starts to run.

This is my first post here so hello everyone! I know that a command of the programs name can start a program and clicking on a icon in GUI can as well as a startup shell script but how do I educate myself of the method that starts an application? Does the GUI run a script? What are the ways/ way... (2 Replies)
Discussion started by: theKbStockpiler
2 Replies

9. Shell Programming and Scripting

Perl Debug Stepping Answering Questions

I am new to perl and want to get a little better understanding of debugging code in perl. I have a perl script that has questions to be answered like: he following PERL modules are recommended: Crypt::DES Crypt::PasswdMD5 IO::Pty Net::Write::Layer2 String::CRC32 Attempt to install... (0 Replies)
Discussion started by: metallica1973
0 Replies

10. Shell Programming and Scripting

Perl program get a response before the program quits

I created a program, so a kid can practice there math on it. It dispenses varies math problems and the kid must input an answer. I also want it to grade the work they have done, but I can't find the best place for it to print out the grade. I have: if ( $response =~ m/^/ ) { $user_wants_to_quit... (1 Reply)
Discussion started by: germany1517
1 Replies
cdk_draw(3)						     Library Functions Manual						       cdk_draw(3)

NAME
cdk_draw - Cdk Drawing Functions SYNOPSIS
cc [ flag ... ] file ... -lcdk [ library ... ] #include <cdk.h> void boxWindow ( WINDOW *window, chtype attr); void attrbox ( WINDOW *win, chtype tlc, chtype trc, chtype blc, chtype brc, chtype horz, chtype vert, chtype attr); void drawObjBox ( WINDOW *win, CDKOBJS *object); void drawLine ( WINDOW *window, int startx, int starty, int endx, int endy, chtype line); void drawShadow ( WINDOW *shadowWin); void writeBlanks ( WINDOW *window, int xpos, int ypos, int align, int start, int end); void writeChar ( WINDOW *window, int xpos, int ypos, char *string, int align, int start, int end); void writeCharAttrib ( WINDOW *window, int xpos, int ypos, char *string, chtype attr, int align, int start, int end); void writeChtype ( WINDOW *window, int xpos, int ypos, chtype *string, int align, int start, int end); void writeChtypeAttrib ( WINDOW *window, int xpos, int ypos, chtype *string, chtype attr, int align, int start, int end); DESCRIPTION
These functions perform useful drawing and attribute operations. AVAILABLE FUNCTIONS
boxWindow draw a box with on the window win. Like attrbox, this function ORs attr with each character as it draws the box. attrbox draw a box with on the window win letting the caller define each element of the box. The parameters tlc, trc, blc, brc are used for the top-left, top-right, bottom-left and bottom-right corners respectively. The param- eters horz and vert are used for the horizontal and vertical sides of the box. Any of these parameters may be zero. In that case, the function skips the corresponding element of the box. The function ORs attr with each character as it draws the box. drawObjBox Draw a box around the given window win using the object's defined line-drawing characters. drawLine draw a line on the given window. The parameters starty, startx are the starting coordinates. The parameters endy, endx are the ending coordinates. The function writes the data in line to each coordinate in that range including the start/end coordinates. The function handles lines other than vertical or horizontal, but normally it is used for that, e.g., with line set to ACS_HLINE or ACS_VLINE. drawShadow draw a shadow on the right and bottom edges of a window. writeBlanks write a string of blanks, using writeChar. The parameters are passed to writeChar as is. There is no corresponding writeBlanksAttrib function. writeChar writes out a char * string without adding attributes. The parameters are passed to writeCharAttrib as is. writeCharAttrib writes out a char * string with the given attributes added. The string is written to the given window, using its relative screen coordinates ypos and xpos. Compare with writeChtypeAttrib, which writes a chtype * string. The function ORs the attribute attr with each item from the string. For instance, it may be A_BOLD. The align parameter controls whether it is written horizontally (HORIZONTAL) or vertically (VERTICAL). Finally, only a subset of the string is written, i.e., from indices start to end. writeChtype writes out a chtype * string without adding attributes. The parameters are passed to writeChtypeAttrib as is. writeChtypeAttrib writes out a chtype * string with the given attributes added. The string is written to the given window, using its relative screen coordinates ypos and xpos. You would normally construct the string from a char * string using char2Chtype (3). The function ORs the attribute attr with each item from the string. For instance, it may be A_BOLD. The align parameter controls whether it is written horizontally (HORIZONTAL) or vertically (VERTICAL). Finally, only a subset of the string is written, i.e., from indices start to end. SEE ALSO
cdk(3), cdk_util(3) cdk_draw(3)
All times are GMT -4. The time now is 03:57 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy