App-SweeperBot
view release on metacpan or search on metacpan
lib/App/SweeperBot.pm view on Meta::CPAN
use strict;
use warnings;
use Carp;
use NEXT;
use 5.006;
our $VERSION = '0.03';
use Scalar::Util qw(looks_like_number);
use Win32::Process qw(NORMAL_PRIORITY_CLASS);
use constant DEBUG => 0;
use constant VERBOSE => 0;
use constant CHEAT => 1;
use constant UBER_CHEAT => 0;
use constant SMILEY_LENGTH => 26;
# The minimum and maximum top dressings define the range in which
lib/App/SweeperBot.pm view on Meta::CPAN
else {
$this->flag_mines($game_state,[$x,$y]);
}
$altered_board = 1;
}
# Empty squares are dull.
next SQUARE if ($game_state->[$x][$y] eq 0);
# Unpressed/flag squares don't give us any information.
next SQUARE if (not looks_like_number($game_state->[$x][$y]));
my @adjacent_unpressed = $this->adjacent_unpressed_for($game_state,$x,$y);
# If there are no adjacent unpressed squares, then
# this square is boring.
next SQUARE if not @adjacent_unpressed;
my $adjacent_mines = $this->adjacent_mines_for($game_state,$x,$y);
# If the number of mines is equal to the number
# on this square, then stomp on it.
lib/App/SweeperBot.pm view on Meta::CPAN
sub enable_cheats {
SendKeys("xyzzy{ENTER}+ ");
return;
}
=head2 cheat_is_square_safe
if ($sweeperbot->cheat_is_square_safe($x,$y) {
print "($x,$y) looks safe!\n";
} else {
print "($x,$y) has a mine underneath.\n";
}
If cheats are enabled, returns true if the given square looks
safe to step on, or false if it appears to contain a mine.
Note that especially on fast, multi-core systems, it's possible
for this to move the mouse and capture the required pixel before
minesweeper has had a chance to update it. So if you cheat,
you may sometimes be surprised.
=cut
sub cheat_is_square_safe {
lib/App/SweeperBot.pm view on Meta::CPAN
);
# Capture our pixel.
my $pixel = CaptureRect(0,0,1,1);
my $signature = $pixel->Get("signature");
print "Square at @$square has sig of $signature\n" if DEBUG;
if ($signature eq CHEAT_SAFE) {
print "This square (@$square) looks safe\n" if DEBUG;
return 1;
} elsif ($signature eq CHEAT_UNSAFE) {
print "This square (@$square) looks dangerous!\n" if DEBUG;
return;
}
die "Square @$square has unknown cheat-signature\n$signature\n";
}
__END__
=head1 BUGS
Plenty. The code is pretty awful right now. Anything that could go
( run in 0.448 second using v1.01-cache-2.11-cpan-64827b87656 )