This repository has been archived by the owner on Sep 5, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyBot.pl
executable file
·82 lines (61 loc) · 1.47 KB
/
MyBot.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env perl
use strict;
use warnings;
use FindBin;
use Carp qw(carp croak verbose);
use Time::HiRes ();
use lib "$FindBin::Bin/lib-ex";
use Devel::StackTrace;
use lib "$FindBin::Bin";
use lib "$FindBin::Bin/lib";
use lib "$FindBin::Bin/bots";
use AIAnts::Game;
BEGIN {
my $bot_impl = $ARGV[0] || '';
if ( $bot_impl ne '' ) {
require $bot_impl;
} else {
require 'MyBot.pm';
}
}
my $log_fpath = $ARGV[1] || undef; # log file path
my $ver = $ARGV[2] // 1; # verbose level
my $in_fpath = $ARGV[3]; # input (game commands) file path
# make unbuffered
select STDIN; $| = 1;
select STDERR; $| = 1;
select STDOUT; $| = 1;
if ( $ver >= 1 ) {
binmode(STDOUT, ":utf8"); # utf8 output (usefull for debug mode)
}
if ( $ver >= 5 ) {
print "input file: $in_fpath\n";
print "verbose level: $ver\n";
print "log to file: $log_fpath\n";
}
$SIG{__DIE__} = sub {
my $st = Devel::StackTrace->new();
print STDERR "--- s " . Time::HiRes::time() . ' ' . ('-' x 90) . "\n";
print STDERR $st->as_string();
print STDERR "--- e " . ('-' x 100) . "\n";
#die;
#exit; # bot crashed
};
my $bot = MyBot->new(
ver => $ver,
log_fpath => $log_fpath,
map => {
o_utf8 => 0,
},
);
my %game_conf = (
bot => $bot,
ver => $ver,
in_fpath => $in_fpath,
control_turntime => 1,
);
my $game = new AIAnts::Game( %game_conf );
$game->run;
if ( $ver >= 5 ) {
print $game->bot->map->dump(1);
}