Some addded functionality to simplePlayer
This commit is contained in:
parent
a66408602c
commit
c0ef1f88b6
1 changed files with 61 additions and 15 deletions
|
@ -14,6 +14,16 @@ DESCRIPTION
|
|||
|
||||
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];
|
||||
our $turn = 0;
|
||||
|
||||
# If team is non-numeric
|
||||
($team =~ m/\D+/) and printf $usage_text and exit 1;
|
||||
|
||||
# Wait for a file to exist
|
||||
sub WaitForFile
|
||||
{
|
||||
|
@ -25,19 +35,59 @@ sub WaitForFile
|
|||
}
|
||||
}
|
||||
|
||||
# Exit with usage if not given a number
|
||||
scalar(@ARGV) or printf $usage_text and exit 1;
|
||||
# Get the units from a turn file
|
||||
sub GetUnitsForTurn
|
||||
{
|
||||
my $turnFile = $_[0];
|
||||
|
||||
# Grab the team
|
||||
our $team = $ARGV[0];
|
||||
# Open the turn file
|
||||
open (my $TURNHANDLE, '<', $turnFile) or die "Could not open '$turnFile' $!";
|
||||
|
||||
# Pull in the header information
|
||||
my $headerLine = <$TURNHANDLE>;
|
||||
chomp $headerLine;
|
||||
my $sizeLine = <$TURNHANDLE>;
|
||||
chomp $sizeLine;
|
||||
my $turnLine = <$TURNHANDLE>;
|
||||
chomp $turnLine;
|
||||
( <$TURNHANDLE> =~ m/~~~~/ ) or die "Gamestate file did not match expected format";
|
||||
|
||||
# If team is non-numeric
|
||||
($team =~ m/\D+/) and printf $usage_text and exit 1;
|
||||
my @units;
|
||||
while( my $unitLine = <$TURNHANDLE> )
|
||||
{
|
||||
chomp $unitLine;
|
||||
push(@units,$unitLine);
|
||||
}
|
||||
|
||||
return @units;
|
||||
}
|
||||
|
||||
# Output the commands file
|
||||
sub OutputCommandsFile
|
||||
{
|
||||
my $commands = $_[0];
|
||||
|
||||
# Get output file
|
||||
our $orderFile = "Turn_TURN_Team_TEAM.txt";
|
||||
$orderFile =~ s/TURN/$turn/;
|
||||
$orderFile =~ s/TEAM/$team/;
|
||||
|
||||
system ("echo $commands > $orderFile");
|
||||
}
|
||||
|
||||
# Get commands for a turn
|
||||
sub GetCommandsForTurn
|
||||
{
|
||||
my @units = @_;
|
||||
|
||||
# perform AI here
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
# Show launch params
|
||||
printf("Launching with team %i\n",$team);
|
||||
|
||||
our $turn = 0;
|
||||
|
||||
# Stay looping the AI
|
||||
while ( 1 )
|
||||
{
|
||||
|
@ -49,16 +99,12 @@ while ( 1 )
|
|||
WaitForFile $turnFile;
|
||||
|
||||
# Read in the game state from turnFile
|
||||
my @units = GetUnitsForTurn($turnFile);
|
||||
|
||||
# Generate some commands
|
||||
my $commands = "";
|
||||
my $commands = GetCommandsForTurn @units;
|
||||
|
||||
# Get output file
|
||||
our $orderFile = "Turn_TURN_Team_TEAM.txt";
|
||||
$orderFile =~ s/TURN/$turn/;
|
||||
$orderFile =~ s/TEAM/$team/;
|
||||
|
||||
system ("echo $commands > $orderFile");
|
||||
OutputCommandsFile $commands;
|
||||
|
||||
$turn++;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue