dgtdrv git
Status: Beta
Brought to you by:
arwagner
#!/usr/local/bin/perl -w
#
# Announce a move from Crafty using some soundfiles
#
# The program used for Sound Output
my $playprg = "/usr/bin/aplay -q";
# Where the sound files are located
my $soundpath = "/opt/chess/share/sound";
# Which language to use (each supported language is in a separate
# subdir of $soundpath)
my $language = "english";
# Delay between the announcements (only full seconds, 1 is ok)
my $delay = 1;
# The move sent e.g. by dgtdrv or crafty
my $move = $ARGV[0];
# Set soundpath to the correct language
$soundpath = $soundpath . "/" . $language;
# First check some specials
if ( ($move =~ m/O-O/)
|| ($move eq "Stalemate")
|| ($move eq "Drawaccept")
|| ($move eq "Drawoffer")
|| ($move eq "Resign")
|| ($move eq "Checkmate")
)
{
system("$playprg $soundpath/$move.wav");
}
else
{
# Handle all normal moves. All that needs to be done is announced
# each character sent by crafty alone. Set some pause beteween each
# char for clearer understanding.
#
# NOTE 1: Crafty uses short notation, so short notation is
# announced. For long notation announcements the crafty engine has
# to be hacked and pgn output as well as logging would get broken.
#
# NOTE 2: There has to exist a sound file named for each row,
# column and piece. That is there has to be sound files like a.wav,
# 1.wav, R.wav and so on. One can easily rename the files
# distributed for free eg. at the "Arena" Website
# (http://www.playwitharena.com). Soundfiles from Fritz are not
# suitable, at the moment, but the script can easily be rewritten
# to handle them as well.
for (my $i=0; $i<length($move); $i++)
{
my $char = substr $move, $i, 1;
if ($i == length($move)-1) {
# the last character of a move can only then match a letter
# if it is a promotion. Replace eventually passed lower case
# chars by their upper case.
if ($char eq 'q') { $char = 'Q'; }
if ($char eq 'b') { $char = 'B'; }
if ($char eq 'n') { $char = 'N'; }
if ($char eq 'r') { $char = 'R'; }
}
if ($char =~ m/[^=+]/)
{
if ($char =~ m/#/)
{
system("$playprg $soundpath/Checkmate.wav");
}
else {
system("$playprg $soundpath/$char".".wav");
sleep($delay);
}
}
}
}