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

View file

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