Update using player instead of team and matching new file formats

This commit is contained in:
mdiluzio 2014-12-22 20:03:31 +00:00
parent ca78e4bff8
commit 883dad2d48
2 changed files with 23 additions and 23 deletions

View file

@ -17,7 +17,7 @@ NAME
randomPlayer.pl
USAGE
randomPlayer.pl TEAM [OPTIONS]
randomPlayer.pl PLAYER_ID [OPTIONS]
DESCRIPTION
A very random perl AI for ttrts
@ -27,16 +27,16 @@ TEXT
# Exit with usage if not given a number
scalar(@ARGV) or printf $usage_text and exit 1;
# Grab the team
our $team = $ARGV[0];
# Grab the player
our $player = $ARGV[0];
our $turn = 0;
our $gameName;
our $gameX;
our $gameY;
# If team is non-numeric
($team =~ m/\D+/) and printf $usage_text and exit 1;
# If player is non-numeric
($player =~ m/\D+/) and printf $usage_text and exit 1;
# Give random orders to all units
sub OrderEverythingRandom
@ -56,7 +56,7 @@ sub OrderEverythingRandom
}
# Show launch params
printf("Launching with team %i\n",$team);
printf("Launching with player %i\n",$player);
# Stay looping the AI
while ( 1 )
@ -72,8 +72,8 @@ while ( 1 )
my @units = GetUnitsForTurn($turnFile);
my ($gameName,$gameX,$gameY) = GetHeaderForTurn($turnFile);
# Get units on my team
my @myUnits = getUnitsOnTeam($team,@units);
# Get units on my player
my @myUnits = getUnitsOnPlayer($player,@units);
# Generate some commands
my $commands = OrderEverythingRandom(@myUnits);
@ -97,7 +97,7 @@ while ( 1 )
exit 0;
}
OutputCommandsFile $turn,$team,$commands;
OutputCommandsFile $turn,$player,$commands;
$turn++;

View file

@ -8,7 +8,7 @@ our $ttrts_perlai_versioncompat_minor = 1;
# Get information about a unit from it's descriptor
sub getUnit
{
return ($_[0] =~ /UNIT:(\d+) tm:(\d+) vs:([^ ]+) dr:([^ ]+) ps:\[(\d+),(\d+)\]/);
return ($_[0] =~ /UNIT:(\d+) pl:(\d+) vs:([^ ]+) dr:([^ ]+) ps:\[(\d+),(\d+)\]/);
}
# Get the units from a turn file
@ -84,17 +84,17 @@ sub GetHeaderForTurn
return ($gameName,$gameX,$gameY);
}
# Get units from a specific team
sub getUnitsOnTeam
# Get units from a specific player
sub getUnitsOnPlayer
{
my $theTeam = shift;
my $thePlayer = shift;
my @allUnits = @_;
my @myUnits;
for my $unit (@allUnits)
{
my ($unitTeam) = $unit =~ /tm:(\d+)/;
if ( $unitTeam == $theTeam )
my ($unitplayer) = $unit =~ /pl:(\d+)/;
if ( $unitplayer == $thePlayer )
{
push(@myUnits,$unit);
}
@ -114,10 +114,10 @@ sub GetTurnFile
sub GetCommandFile
{
my $turn = shift;
my $team = shift;
my $cmdFileName = "Turn_TURN_Team_TEAM.txt";
my $player = shift;
my $cmdFileName = "Player_PLAYER_Turn_TURN.txt";
$cmdFileName =~ s/TURN/$turn/;
$cmdFileName =~ s/TEAM/$team/;
$cmdFileName =~ s/PLAYER/$player/;
return $cmdFileName;
}
@ -125,11 +125,11 @@ sub GetCommandFile
sub OutputCommandsFile
{
my $turn = shift;
my $team = shift;
my $player = shift;
my $commands = shift;
# Get output file
our $cmdFileName = GetCommandFile($turn,$team);
our $cmdFileName = GetCommandFile($turn,$player);
if (! -e $cmdFileName)
{
@ -172,10 +172,10 @@ sub PrintGameMap
# Fill with units
for my $unit (@units)
{
my ($id,$tm,$vs,$dr,$psx,$psy) = getUnit($unit);
my ($id,$pl,$vs,$dr,$psx,$psy) = getUnit($unit);
$tm += 31;
$vs = "\e[".$tm."m".$vs."\e[0m";
$pl += 31;
$vs = "\e[".$pl."m".$vs."\e[0m";
$map[$psx][$psy] = $vs;
}