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
|
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
|
# Wait for a file to exist
|
||||||
sub WaitForFile
|
sub WaitForFile
|
||||||
{
|
{
|
||||||
|
@ -25,19 +35,59 @@ sub WaitForFile
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Exit with usage if not given a number
|
# Get the units from a turn file
|
||||||
scalar(@ARGV) or printf $usage_text and exit 1;
|
sub GetUnitsForTurn
|
||||||
|
{
|
||||||
|
my $turnFile = $_[0];
|
||||||
|
|
||||||
# Grab the team
|
# Open the turn file
|
||||||
our $team = $ARGV[0];
|
open (my $TURNHANDLE, '<', $turnFile) or die "Could not open '$turnFile' $!";
|
||||||
|
|
||||||
# If team is non-numeric
|
# Pull in the header information
|
||||||
($team =~ m/\D+/) and printf $usage_text and exit 1;
|
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";
|
||||||
|
|
||||||
|
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);
|
printf("Launching with team %i\n",$team);
|
||||||
|
|
||||||
our $turn = 0;
|
|
||||||
|
|
||||||
# Stay looping the AI
|
# Stay looping the AI
|
||||||
while ( 1 )
|
while ( 1 )
|
||||||
{
|
{
|
||||||
|
@ -49,16 +99,12 @@ while ( 1 )
|
||||||
WaitForFile $turnFile;
|
WaitForFile $turnFile;
|
||||||
|
|
||||||
# Read in the game state from turnFile
|
# Read in the game state from turnFile
|
||||||
|
my @units = GetUnitsForTurn($turnFile);
|
||||||
|
|
||||||
# Generate some commands
|
# Generate some commands
|
||||||
my $commands = "";
|
my $commands = GetCommandsForTurn @units;
|
||||||
|
|
||||||
# Get output file
|
OutputCommandsFile $commands;
|
||||||
our $orderFile = "Turn_TURN_Team_TEAM.txt";
|
|
||||||
$orderFile =~ s/TURN/$turn/;
|
|
||||||
$orderFile =~ s/TEAM/$team/;
|
|
||||||
|
|
||||||
system ("echo $commands > $orderFile");
|
|
||||||
|
|
||||||
$turn++;
|
$turn++;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue