rnbqkbnr pppppppp 10101010 01010101 10101010 01010101 PPPPPPPP RNBQKBNR 1 #### #!/usr/bin/perl -w use CGI; $q = new CGI; $fx = $q->param('fx'); $fy = $q->param('fy'); $tx = $q->param('tx'); $ty = $q->param('ty'); $mesg = $q->param('mesg'); $fx--; #Because the average non-geek doesn't like thinking in $tx--; #terms of 0-7. $fy--; $ty--; print "Content-type: text/html\n\n"; $dir[0] = '/home/httpd/html/chess/board1'; $dir[1] = '/home/httpd/html/chess/board1.intransit'; $dir[2] = '/home/httpd/html/chess/log.html'; $dir[3] = '/home/httpd/html/chess/newboard1.html'; $dir[4] = '/home/httpd/html/chess/board1.html'; open (BRD, "$dir[0]") or die "Can't open that one sir!$!\n"; open (nBRD, ">$dir[1]") or die "Can't write to that one sir$!!\n"; open (LOG, ">>$dir[2]") or die "Can't write the log!$!\n"; open (NB, ">$dir[3]") or die "Can't write the new board!$!\n"; for (0..8) #Read in the ACSII version of the board { #and assemble the structure. $in = ; chop $in; push @board, split //, $in; } $piece = $board[$fy*8+$fx]; #Sanity Czechs. if (($piece =~ /[bknpqr]/)&&($board[64]==1)) {¬_your_turn;} if (($piece =~ /[BKNPRQ]/)&&($board[64]==0)) {¬_your_turn;} if ($piece =~ /[01]/) {&no_piece_there;} if (($fx>7)||($fy>7)||($tx>7)||($ty>7)) {&out_of_bounds;} if (($fx<0)||($fy<0)||($tx<0)||($ty<0)) {&out_of_bounds;} $board[$ty*8+$tx] = $piece; if (($fy%2)xor($fx%2)) {$board[$fy*8+$fx] = 0;} else {$board[$fy*8+$fx] = 1;} if ($board[64]==1){print LOG "White ";} elsif ($board[64]==0){print LOG "Black ";} print NB <<"endhere";
endhere $linecount=1; for(0..63) #Build the html of the new board. { $_ = $board[$_]; print nBRD $_; if ($_ eq '0'){print NB "\n"} elsif ($_ eq '1'){print NB "\n"} elsif ($_ eq 'p'){print NB "\n"} elsif ($_ eq 'P'){print NB "\n"} elsif ($_ eq 'n'){print NB "\n"} elsif ($_ eq 'N'){print NB "\n"} elsif ($_ eq 'r'){print NB "\n"} elsif ($_ eq 'R'){print NB "\n"} elsif ($_ eq 'b'){print NB "\n"} elsif ($_ eq 'B'){print NB "\n"} elsif ($_ eq 'q'){print NB "\n"} elsif ($_ eq 'Q'){print NB "\n"} elsif ($_ eq 'k'){print NB "\n"} elsif ($_ eq 'K'){print NB "\n"} $count++; if ($count==8) { $count=0; $linecount++; if($linecount<9){print nBRD "\n"; print NB "";} } } if (!$board[64]){$board[64]=1;} elsif ($board[64]){$board[64]=0;} {print nBRD "\n$board[64]\n";} print NB <<"end_of_text";
1
$linecount
 
1
2
3
4
5
6
7
8
PERLMONKS CHESS
"I once held the opinion that magnificent pieces allowed a person to play a magnificent game. I quickly learned that my opinion was wrong." --Wombat
Black square White square
Pawn Rook
Knight Bishop
Queen King
See the log of moves and dialogue.


From Y: From X:
To Y: To X:
Do you have anything to say to your opponent?
end_of_text if ($piece =~ '[pP]'){print LOG "Pawn --";} if ($piece =~ '[bB]'){print LOG "Bishop --";} if ($piece =~ '[kK]'){print LOG "King --";} if ($piece =~ '[nN]'){print LOG "Knight --";} if ($piece =~ '[rR]'){print LOG "Rook --";} if ($piece =~ '[qQ]'){print LOG "Queen --";} $fy++;$fx++;$ty++;$tx++; print LOG "$fy x $fx to $ty x $tx
\n"; print LOG "$mesg



\n"; $cmd = "mv $dir[3] $dir[4]"; system ($cmd); $cmd = "mv $dir[1] $dir[0]"; system ($cmd); print <<"HTML"; Okay! You moved, have a nice day.
Click here to return to the board HTML sub no_piece_there { print "There isn't any piece there. Do not smoke crack while playing chess.\$ exit (0); } sub not_your_turn { print "Not your turn, go away. :-P\n"; exit (0); } sub out_of_bounds { print "Invalid move, try again."; exit (0); }