Remove player source directory in favor of new higher level players directory with a simple (and not-fully-functioning) perl AI

This commit is contained in:
mdiluzio 2014-12-17 07:51:49 +00:00
parent 6c1647b1be
commit e8610c8131
2 changed files with 65 additions and 0 deletions

65
players/simplePlayer.pl Executable file
View file

@ -0,0 +1,65 @@
#! /usr/bin/perl
use strict;
use warnings;
our $usage_text=<<TEXT;
NAME
simple_player.pl
USAGE
simple_player.pl TEAM [OPTIONS]
DESCRIPTION
A very simple perl AI for ttrts
TEXT
# Wait for a file to exist
sub WaitForFile
{
my $file = $_[0];
printf("Waiting for %s\n", $file);
while( ! -e $file )
{
sleep 1;
}
}
# Exit with usage if not given a number
scalar(@ARGV) or printf $usage_text and exit 1;
# Grab the team
our $team = $ARGV[0];
# If team is non-numeric
($team =~ m/\D+/) and printf $usage_text and exit 1;
printf("Launching with team %i\n",$team);
our $turn = 0;
# Stay looping the AI
while ( 1 )
{
# Wait for turn file
our $turnFile = "Turn_TURN.txt";
$turnFile =~ s/TURN/$turn/;
# Wait for the turn file
WaitForFile $turnFile;
# Read in the game state from turnFile
# Generate some commands
my $commands = "";
# Get output file
our $orderFile = "Turn_TURN_Team_TEAM.txt";
$orderFile =~ s/TURN/$turn/;
$orderFile =~ s/TEAM/$team/;
system ("echo $commands > $orderFile");
$turn++;
}