From: Sam Moore Date: Wed, 7 Dec 2011 16:00:04 +0000 (+0800) Subject: Modified manager program, updated website X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=17a20de4017ccfadef219d830a28ecccfe6f5106;p=progcomp2012.git Modified manager program, updated website Major changes: Added simple GUI for human players Setup phase doesn't use GUI yet (uses a default if -g enabled). Click in the general region of where you want to select/move pieces. Modified Board::Draw to allow for showing of already revealed pieces, but not all pieces. Used to make human player GUI nicer (hides AI pieces). Modified -t switch to allow for "infinite" stall_time (wait for user to press enter) Changed website. Removed protocol description and linked to manual.txt. Added screenshot to make things slightly more exciting. Updated manual.txt Minor changes to simulate.py (output) TODO: Fix segmentation fault found in manager program It occurs just before exit. Memory error in the cleanup process? ANNOYING! Still have to bring myself to take the time to finish setting up that vm... Need to talk to a non-hostile wheel member about security. I don't want my vm to take out our network or something. Preferably I don't even want the vm to be compromised, regardless of the rest of ucc. So much I don't know about servers/linux... Need to stop staying up past midnight... --- diff --git a/manager/controller.cpp b/manager/controller.cpp index e68c1dc..982f0fc 100644 --- a/manager/controller.cpp +++ b/manager/controller.cpp @@ -158,9 +158,20 @@ MovementResult Controller::MakeMove(string & buffer) } - if (Game::theGame->allowIllegalMoves && !Board::LegalResult(moveResult)) - return MovementResult::OK; //HACK - Illegal results returned as legal! - else - return moveResult; + if (!Board::LegalResult(moveResult)) + { + if (Game::theGame->allowIllegalMoves) + return MovementResult::OK; //HACK - Illegal results returned as legal! (Move not made) + else if (this->HumanController()) //Cut human controllers some slack and let them try again... + { + //Yes, checking type of object is "not the C++ way" + // But sometimes its bloody useful to know!!! + Message("Bad move: \'" + buffer + "\' <- Please try again!"); + buffer = ""; + return this->MakeMove(buffer); + } + } + + return moveResult; } diff --git a/manager/controller.h b/manager/controller.h index 24f0c0d..55c233d 100644 --- a/manager/controller.h +++ b/manager/controller.h @@ -19,7 +19,7 @@ class Controller MovementResult MakeMove(std::string & buffer); - + virtual bool HumanController() const {return false;} //Hacky... overrides in human_controller... avoids having to use run time type info void Message(const std::string & buffer) {Message(buffer.c_str());} virtual void Message(const char * string) = 0; diff --git a/manager/game.cpp b/manager/game.cpp index b4fcc62..ce655d7 100644 --- a/manager/game.cpp +++ b/manager/game.cpp @@ -404,14 +404,34 @@ MovementResult Game::Play() MovementResult result = MovementResult::OK; turnCount = 1; string buffer; + + Piece::Colour toReveal = reveal; + + red->Message("START"); - //logMessage("START\n"); + + + while (!Board::HaltResult(result) && (turnCount < maxTurns || maxTurns < 0)) { + if (red->HumanController()) + toReveal = Piece::RED; + if (printBoard) + { + system("clear"); + if (turnCount == 0) + fprintf(stdout, "START:\n"); + else + fprintf(stdout, "%d BLUE:\n", turnCount); + theBoard.PrintPretty(stdout, toReveal); + fprintf(stdout, "\n\n"); + } + if (graphicsEnabled) + theBoard.Draw(toReveal); turn = Piece::RED; logMessage( "%d RED: ", turnCount); @@ -421,16 +441,25 @@ MovementResult Game::Play() logMessage( "%s\n", buffer.c_str()); if (Board::HaltResult(result)) break; - if (graphicsEnabled) - theBoard.Draw(reveal); + + if (stallTime > 0) + Wait(stallTime); + else + ReadUserCommand(); + + if (blue->HumanController()) + toReveal = Piece::BLUE; if (printBoard) { system("clear"); fprintf(stdout, "%d RED:\n", turnCount); - theBoard.PrintPretty(stdout, reveal); + theBoard.PrintPretty(stdout, toReveal); fprintf(stdout, "\n\n"); } - Wait(stallTime); + if (graphicsEnabled) + theBoard.Draw(toReveal); + + turn = Piece::BLUE; logMessage( "%d BLU: ", turnCount); @@ -444,18 +473,13 @@ MovementResult Game::Play() - if (graphicsEnabled) - theBoard.Draw(reveal); - if (printBoard) - { - system("clear"); - fprintf(stdout, "%d BLUE:\n", turnCount); - theBoard.PrintPretty(stdout, reveal); - fprintf(stdout, "\n\n"); - } - - Wait(stallTime); + + if (stallTime > 0) + Wait(stallTime); + else + ReadUserCommand(); + if (theBoard.MobilePieces(Piece::BOTH) == 0) result = MovementResult::DRAW; @@ -493,6 +517,20 @@ int Game::logMessage(const char * format, ...) return result; } +/** + * Waits for a user command + * Currently ignores the command. + */ +void Game::ReadUserCommand() +{ + fprintf(stdout, "Waiting for user to press enter...\n"); + string command(""); + for (char c = fgetc(stdin); c != '\n' && (int)(c) != EOF; c = fgetc(stdin)) + { + command += c; + } +} + MovementResult FileController::QuerySetup(const char * opponentName, std::string setup[]) { @@ -538,3 +576,5 @@ MovementResult FileController::QueryMove(std::string & buffer) buffer = string(s); return MovementResult::OK; } + + diff --git a/manager/game.h b/manager/game.h index 48926ea..1212b89 100644 --- a/manager/game.h +++ b/manager/game.h @@ -27,7 +27,7 @@ class Game static void HandleBrokenPipe(int signal); - + void ReadUserCommand(); const Piece::Colour Turn() const {return turn;} void ForceTurn(const Piece::Colour & newTurn) {turn = newTurn;} @@ -53,7 +53,8 @@ class Game private: FILE * log; - Piece::Colour reveal; + public: + const Piece::Colour reveal; int turnCount; static bool gameCreated; diff --git a/manager/human_controller.cpp b/manager/human_controller.cpp index 5e3e176..bf43e8d 100644 --- a/manager/human_controller.cpp +++ b/manager/human_controller.cpp @@ -13,23 +13,83 @@ MovementResult Human_Controller::QuerySetup(const char * opponentName, string se if (!shownMessage) { if (graphicsEnabled) - fprintf(stderr, "GUI not yet supported! Please use CLI\n"); - fprintf(stdout,"Enter %d x %d Setup grid\n", Game::theGame->theBoard.Width(), 4); - fprintf(stdout,"Please enter one line at a time, using the following allowed characters:\n"); - for (Piece::Type rank = Piece::FLAG; rank <= Piece::BOMB; rank = Piece::Type((int)(rank) + 1)) + fprintf(stdout, "WARNING: GUI not fully supported. You will be forced to use the default setup.\n"); + else { - fprintf(stdout,"%c x %d\n", Piece::tokens[(int)rank], Piece::maxUnits[(int)rank]); - } - fprintf(stdout, "You must place at least the Flag (%c). Use '%c' for empty squares.\n", Piece::tokens[(int)Piece::FLAG], Piece::tokens[(int)Piece::NOTHING]); - fprintf(stdout, "NOTE: Player RED occupies the top four rows, and BLUE occupies the bottom four rows.\n"); + fprintf(stdout,"Enter %d x %d Setup grid\n", Game::theGame->theBoard.Width(), 4); + fprintf(stdout,"Please enter one line at a time.\n"); + fprintf(stdout, "You must place at least the Flag (%c). Use '%c' for empty squares.\n", Piece::tokens[(int)Piece::FLAG], Piece::tokens[(int)Piece::NOTHING]); + + switch (colour) + { + case Piece::RED: + fprintf(stdout, "You are RED and occupy the top 4 rows of the board.\n"); + fprintf(stdout, "NOTE: Enter \"DEFAULT\" to use the setup:\n"); + fprintf(stdout, "FB8sB479B8\nBB31555583\n6724898974\n967B669999\n"); + break; + case Piece::BLUE: + fprintf(stdout, "You are BLUE and occupy the bottom 4 rows of the board.\n"); + fprintf(stdout, "NOTE: Enter \"DEFAULT\" to use the setup:\n"); + fprintf(stdout, "967B669999\n6724898974\nBB31555583\nFB8sB479B8\n"); + break; + default: + fprintf(stdout, "WARNING: Unknown colour error! Please exit the game.\n"); + break; + } + } shownMessage = true; } - - + + if (graphicsEnabled) + { + switch(colour) + { + case Piece::RED: + setup[0] = "FB8sB479B8"; + setup[1] = "BB31555583"; + setup[2] = "6724898974"; + setup[3] = "967B669999"; + break; + case Piece::BLUE: + setup[0] = "967B669999"; + setup[1] = "6724898974"; + setup[2] = "BB31555583"; + setup[3] = "FB8sB479B8"; + break; + default: + assert(false); + break; + } + return MovementResult::OK; + } for (int y = 0; y < 4; ++y) + { cin >> setup[y]; + if (y == 0 && setup[0] == "DEFAULT") + { + switch(colour) + { + case Piece::RED: + setup[0] = "FB8sB479B8"; + setup[1] = "BB31555583"; + setup[2] = "6724898974"; + setup[3] = "967B669999"; + break; + case Piece::BLUE: + setup[0] = "967B669999"; + setup[1] = "6724898974"; + setup[2] = "BB31555583"; + setup[3] = "FB8sB479B8"; + break; + default: + assert(false); + break; + } + break; + } + } assert(cin.get() == '\n'); return MovementResult::OK; @@ -40,20 +100,78 @@ MovementResult Human_Controller::QueryMove(string & buffer) static bool shownMessage = false; if (!shownMessage) { - if (graphicsEnabled) - fprintf(stderr, "GUI not yet supported! Please use the CLI\n"); - fprintf(stdout, "Please enter your move in the format:\n X Y DIRECTION [MULTIPLIER=1]\n"); - fprintf(stdout, "Where X and Y indicate the coordinates of the piece to move;\n DIRECTION is one of UP, DOWN, LEFT or RIGHT\n and MULTIPLIER is optional (and only valid for scouts (%c))\n", Piece::tokens[(int)(Piece::SCOUT)]); + if (!graphicsEnabled) + { + fprintf(stdout, "Please enter your move in the format:\n X Y DIRECTION [MULTIPLIER=1]\n"); + fprintf(stdout, "Where X and Y indicate the coordinates of the piece to move;\n DIRECTION is one of UP, DOWN, LEFT or RIGHT\n and MULTIPLIER is optional (and only valid for scouts (%c))\n", Piece::tokens[(int)(Piece::SCOUT)]); + + } shownMessage = true; } + if (graphicsEnabled) + { + fprintf(stdout, "Click to move!\n"); + SDL_Event event; int mouseClick = 0; - buffer.clear(); - for (char in = fgetc(stdin); in != '\n'; in = fgetc(stdin)) + int x[] = {-1, -1}; int y[] = {-1, -1}; + while (mouseClick < 2) + { + + while (SDL_PollEvent(&event)) + { + switch (event.type) + { + case SDL_QUIT: + Game::theGame->logMessage("Exit called by human player!\n"); + exit(EXIT_SUCCESS); + break; + case SDL_MOUSEBUTTONDOWN: + switch (event.button.button) + { + case SDL_BUTTON_LEFT: + SDL_GetMouseState(&x[mouseClick], &y[mouseClick]); + x[mouseClick] /= 32; y[mouseClick] /= 32; //Adjust based on graphics grid size + if (mouseClick == 0) + { + stringstream s(""); + s << x[0] << " " << y[0] << " "; + buffer += s.str(); + } + else if (mouseClick == 1) + { + int xDist = x[1] - x[0]; + int yDist = y[1] - y[0]; + if (abs(xDist) > abs(yDist)) + { + if (xDist < 0) + buffer += "LEFT"; + else + buffer += "RIGHT"; + } + else if (yDist < 0) + buffer += "UP"; + else + buffer += "DOWN"; + } + mouseClick++; + break; + } + break; + } + } + } + fprintf(stdout, "Move complete!\n"); + } + else { - buffer += in; + buffer.clear(); + for (char in = fgetc(stdin); in != '\n'; in = fgetc(stdin)) + { + buffer += in; + } } diff --git a/manager/human_controller.h b/manager/human_controller.h index 6d5292e..b2069fc 100644 --- a/manager/human_controller.h +++ b/manager/human_controller.h @@ -12,9 +12,10 @@ class Human_Controller : public Controller Human_Controller(const Piece::Colour & newColour, const bool enableGraphics) : Controller(newColour, "human"), graphicsEnabled(enableGraphics) {} virtual ~Human_Controller() {} + virtual bool HumanController() const {return true;} virtual MovementResult QuerySetup(const char * opponentName, std::string setup[]); virtual MovementResult QueryMove(std::string & buffer); - virtual void Message(const char * message) {fprintf(stderr, "Recieved message \"%s\" from manager.\n", message);} + virtual void Message(const char * message) {fprintf(stderr, "%s\n", message);} private: const bool graphicsEnabled; diff --git a/manager/main.cpp b/manager/main.cpp index 44f8fd3..1fe32bc 100644 --- a/manager/main.cpp +++ b/manager/main.cpp @@ -75,7 +75,10 @@ Piece::Colour SetupGame(int argc, char ** argv) fprintf(stderr, "ARGUMENT_ERROR - Expected timeout value after -t switch!\n"); exit(EXIT_FAILURE); } - timeout = atof(argv[ii+1]); + if (strcmp(argv[ii+1], "inf") == 0) + timeout = -1; + else + timeout = atof(argv[ii+1]); ++ii; break; case 'g': diff --git a/manager/manual.txt b/manager/manual.txt index e7a15d1..3237241 100644 --- a/manager/manual.txt +++ b/manager/manual.txt @@ -19,38 +19,48 @@ DESCRIPTION If set to "human", stratego will request the user to make moves for the Red player using stdin. NOTES 1. There is no plan to support AI programs named "human". Deal with it. - 2. As of writing, human players must use stdin. A graphical interface may be added later. + 2. The graphical interface for human players is... basic. Deal with it. blue_player As red_player, except for controlling the Blue player. OPTIONS -g - By default, graphics are disabled. If the -g switch is present, stratego will draw the game as it is played using OpenGL + By default, graphics are disabled. If the -g switch is present, stratego will draw the game as it is played using SDL/OpenGL + -p By default, even if graphics are disabled, the board state is not printed. If -p is present, the board will be printed to stdout. If the system supports colour, the characters will be in colour. - If -p and -g are both present you will see both behaviours (overkill)! + Yes, If -p and -g are both present you will see both behaviours (overkill)! -i By default, stratego will exit if a move which is deemed "illegal" is made. If the -i switch is present, illegal moves will be ignored. That is, the move will not be made (effectively the player making the illegal move loses a turn). + + NOTE: If -i is not given and a human player accidentally(?) makes an illegal move, they will be asked to make a different move. The game will continue. + This is intended to prevent fits of rage due to the horrible graphical interface causing humans to make illegal moves. -r By default, the identities of all pieces are shown. If the -r switch is present, and graphics are enabled, red pieces will be disguised. If graphics are disabled, the -r switch has no effect. + + Pieces which have previously taken part in combat (and survived) will be revealed. -b As -r, except blue pieces will be disguised. - NOTE: Both -r and -b may be used. + NOTE: Both -r and -b may be used together. -o - By default, stratego is silent. If the -o switch is present, the result of each move is printed to a file. If output_file is "stdout" - then stdout will be used instead of a text file. + By default, stratego does not log moves. If the -o switch is present, the result of each move is printed to a file. + If output_file is "stdout" then stdout will be used instead of a text file. -t By default, stratego executes moves as fast as they are recieved. If the -t switch is present, a delay of stall_time will be introduced between each move. - + + If stall_time is negative or "inf", stratego will wait for the user to press enter before moving to the next move. + + It is tentatively planned to allow the user to enter various commands to alter the game or proceed to specified turns. + However this is slightly complicated. So it might never be done. -m By default, the game is declared a Draw after 5000 turns have ellapsed. Use this option to change the maximum number of turns. - To play for an infinite number of turns, supply "inf" as max_number. + To play for an infinite number of turns, supply "inf" as max_number. This is not recommended for obvious reasons. -f By default, stratego requires red_player and blue_player to enact a game. @@ -107,6 +117,10 @@ PROTOCOL RESPONSE: 4 lines, each of length BOARD_WIDTH, of characters. Each character represents a piece. The characters are shown above. + RED's pieces are placed at the top of the board, and BLUE's pieces are placed at the bottom. + + An AI program does not have to place all 40 pieces, but must at least place the flag ('F'). + 2. TURN QUERY: START | CONFIRMATION BOARD_STATE @@ -127,23 +141,25 @@ PROTOCOL The AI program should print "NO_MOVE" if it is unable to determine a move. This will typically occur when the only pieces belonging to the AI program are Bombs and the Flag. - CONFIRMATION: X Y DIRECTION [MULTIPLIER=1] OUTCOME | NO_MOVE | QUIT RESULT + CONFIRMATION: X Y DIRECTION [MULTIPLIER=1] OUTCOME | NO_MOVE {OK | ILLEGAL} | QUIT [RESULT] + OUTCOME may be either OK, ILLEGAL, KILLS or DIES OK - Move was successful ILLEGAL - Move was not allowed. If stratego was not started with the -i switch, the game will end. KILLS ATTACKER_RANK DEFENDER_RANK - The piece moved into an occupied square and killed the defender. DIES ATTACKER_RANK DEFENDER_RANK - The piece moved into an occupied square and was killed by the defender. - A confirmation of "NO_MOVE" occurs when the AI program made no move for a legitimate reason. + Most turns will be confirmed with: "X Y DIRECTION [MULTIPLIER=1] OUTCOME" + + A confirmation of "NO_MOVE OK" occurs when the AI program made no move for a legitimate reason. "NO_MOVE ILLEGAL" is printed if the AI program made no move for an illegitimate reason. If both AI programs successively make a "NO_MOVE" response, then the game will end. The player with the highest piece value will win, or a draw will be declared if the values are equal. - 3. END GAME If the CONFIRMATION line is of the form: - QUIT RESULT + QUIT [RESULT] Then the game is about to end. If present, RESULT will be a direct copy of the message to stdout described in the EXIT/OUTPUT section below. @@ -190,7 +206,11 @@ EXIT/OUTPUT BUGS - There are no known bugs at this time. However, stratego is still a work in progress. Report a bug to the AUTHOR (see below). + WARNING: + stratego has been observed to segfault occassionally after the end of a game. It is not yet known what is causing these errors. + They appear to occur most often when the result is a draw, however they have been observed to occur under all exit conditions except the Illegal case. The result is still printed to stdout. However this bug _must_ be fixed before stratego can be used by simulation scripts. + + stratego is still a work in progress. Report another bug to the AUTHOR (see below). AUTHORS Sam Moore (for the UCC Programming Competition 2012) diff --git a/manager/stratego.cpp b/manager/stratego.cpp index ed38e35..f2df0ff 100644 --- a/manager/stratego.cpp +++ b/manager/stratego.cpp @@ -202,7 +202,7 @@ void Board::PrintPretty(FILE * stream, const Piece::Colour & reveal) * Draw the board state to graphics * @param reveal - Pieces matching this colour will be revealed. All others will be shown as blank coloured squares. */ -void Board::Draw(const Piece::Colour & reveal) +void Board::Draw(const Piece::Colour & reveal, bool showRevealed) { if (!Graphics::Initialised()) { @@ -223,7 +223,8 @@ void Board::Draw(const Piece::Colour & reveal) //Don't display anything } - else if (piece->colour != Piece::NONE && (piece->colour == reveal || reveal == Piece::BOTH)) + else if ((piece->colour != Piece::NONE && (piece->colour == reveal || reveal == Piece::BOTH)) + || (piece->beenRevealed && showRevealed)) { //Display the piece Piece::textures[(int)(piece->type)].DrawColour(x*32,y*32,0,1, Piece::GetGraphicsColour(piece->colour)); @@ -360,6 +361,9 @@ MovementResult Board::MovePiece(int x, int y, const Direction & direction, int m } else if (defender->colour != target->colour) { + defender->beenRevealed = true; + target->beenRevealed = true; + Piece::Type defenderType = defender->type; Piece::Type attackerType = target->type; diff --git a/manager/stratego.h b/manager/stratego.h index 929f870..fe73aa1 100644 --- a/manager/stratego.h +++ b/manager/stratego.h @@ -108,7 +108,7 @@ class Board void Print(FILE * stream, const Piece::Colour & reveal=Piece::BOTH); //Print board void PrintPretty(FILE * stream, const Piece::Colour & reveal=Piece::BOTH); //Print board using colour - void Draw(const Piece::Colour & reveal=Piece::BOTH); //Draw board + void Draw(const Piece::Colour & reveal=Piece::BOTH, bool showRevealed = true); //Draw board bool AddPiece(int x, int y, const Piece::Type & newType, const Piece::Colour & newColour); //Add piece to board diff --git a/samples/asmodeus/basic_python.pyc b/samples/asmodeus/basic_python.pyc index bca3a0a..cfd6565 100644 Binary files a/samples/asmodeus/basic_python.pyc and b/samples/asmodeus/basic_python.pyc differ diff --git a/samples/basic_python/basic_python.py b/samples/basic_python/basic_python.py index be88d56..cf024e8 100644 --- a/samples/basic_python/basic_python.py +++ b/samples/basic_python/basic_python.py @@ -87,6 +87,8 @@ class BasicAI: """ Implements Setup part of protocol. Always uses the same setup. Override to create custom setups """ #sys.stderr.write("BasicAI Setup here...\n"); setup = sys.stdin.readline().split(' ') + if len(setup) != 4: + sys.stderr.write("BasicAI setup fails, expected 4 tokens, got " + str(len(setup)) + " "+str(setup) + "\n") self.colour = setup[0] self.opponentName = setup[1] self.width = int(setup[2]) diff --git a/samples/basic_python/basic_python.pyc b/samples/basic_python/basic_python.pyc index 4c201ef..06aca7f 100644 Binary files a/samples/basic_python/basic_python.pyc and b/samples/basic_python/basic_python.pyc differ diff --git a/simulator/simulate.py b/simulator/simulate.py index 60320d9..32f2b42 100755 --- a/simulator/simulate.py +++ b/simulator/simulate.py @@ -84,7 +84,7 @@ if len(agents) == 0: if verbose: print "Total: " + str(len(agents)) + " valid agents found (From "+str(len(agentNames))+" possibilities)" print "" - print "Commencing ROUND " + str(roundNumber) + " combat! ("+str(nGames)+" games per pairing)" + print "Commencing ROUND " + str(roundNumber) + " combat! This could take a while... ("+str(nGames)+" games per pairing * " + str(len(agents) * len(agents)-1) + " pairings = " + str((len(agents) * len(agents)-1) * nGames) + " games)" normalGames = 0 diff --git a/web/index.html b/web/index.html index c5205d6..d181a14 100644 --- a/web/index.html +++ b/web/index.html @@ -6,157 +6,68 @@

Quick Details

+

git

The git repository is listed on The UCC git page as "progcomp2012.git"

+

Direct Link Here

+ +

Mailing List

We will use the same mailing list as last year (progcomp).

-

-

There is a #progcomp irc channel on the ucc irc server where you can ask questions or help with setting things up.

+ +

irc channel

+

There is a #progcomp irc channel on the ucc irc server (irc.ucc.asn.au) where you can ask questions or help with setting things up.

+ +

Programming Competition VM

+

I am in the process of learning how to set up a VM for this competition. Please be patient.

Stratego

This site explains what Stratego is.

-

I have never played this game. But it sounds cool. So naturally I decided to make a competition based on it.

-

My original idea was to force people to write AI for Astral, but then I realised that that was a terrible idea.

-

There is in fact, already a World Stratego Championship. However, you have to use Metaforge. Using stdin/stdout will probably make it slightly easier for us. And its better to work out how to do these things ourselves.

+

Short Version: It is a board game in which all pieces have a value that is, initially, unknown to the opponent player. The objective is to destroy all enemy pieces, or capture the enemy "Flag". Pieces with higher values destroy pieces with lower values. There are several special pieces/rules.

+ -

Programming Competition

+

Programming Competition

Create an AI to play Stratego.

-

Yes, I know people are inherently lazy and won't be bothered to do this. But so far in setting this up I have learn quite a lot about inter-process communication, so thats good.

Programs are written independently and interface through stdin/stdout with a manager program, which queries them on setup and moves.

+

The Manager Program

-

The manager program takes two executable paths, one to each of the AI programs to pit against each other.

-

It first requests each program to print the setup of its pieces to stdout. Then the programs take turns (Red, then blue, etc) to move one piece.

-

The first program is Red (top of the board), the second is Blue (bottom of the board).

-

The manager program now has switches to enable/disable graphics and set the move speed of the match.

-

Use "-g" to enable graphics (by default disabled) and "-t TIMEOUT" to set the move speed (default 0 (as fast as possible)).

-

This program now has a manual page

- -

Messaging Protocol and Rules

-

The rules are now also available in the manual page of the manager program

-

Setup

-

Query

-

The manager program prints one line in the following format to each program:

-

COLOUR OPPONENT BOARD_WIDTH BOARD_HEIGHT

-

At the moment BOARD_WIDTH and BOARD_HEIGHT are always 14. The arguments are followed by a newline.

-

OPPONENT will be the identity of the opposing AI program.

-

Response

-

The AI program queried must print four (4) lines containing its initial setup. Each character represents a unit or empty space. The characters are as follows:

+

The manager program provides the protocol for two seperate AI to play a game of stratego. It has the imaginative name of 'stratego', but I will probably refer to it as 'the manager program' or 'stratego' with absolutely no consistency.

+

It also aims to assist with AI design by providing options for graphical or terminal output and saving/reading games from files

- -

Warning: I have changed the characters from mostly letters to mostly digits, indicating the actual worth of a piece

- - - - - - - - - - - - - - - - +

Human players are also supported, although the interface is minimal, as this feature is meant for testing.

+

If you just want to play a game, without having to write your own AI, try Probe

+ +

Screenshot

+Graphical output of 'stratego' manager program. + +

Protocol

+

For the sake of simplicity and keeping things in one place, the protocol is now entirely described in the manual page of the manager program. All updates to the protocol will be reflected in that file.

+ + +

Warning: The accuracy of the above file depends on how recently I pulled it from git. To ensure you get the latest version, find it under "manager/manual.txt" in the git repository

+ +

Long Term Scoring

+

WARNING: Work in progress

+

It is currently planned to store all the AIs on a virtual machine, and periodically run a script to play a round robin

+

The scores for each round and the total scores will be recorded from the start to the end of the competition.

+

The competition will run over a period of weeks (depending on general enthusiasm...), and competitors will be able to alter their programs except during the periods in which the script is running.

+

The following categories will be used when determining the final winners:

+

    +
  1. Total score
  2. +
  3. Number of rounds won
  4. +

+ +

Sample AI Programs

+

WARNING: Work in progress

+

The following sample programs are currently available (and in a working state - refer to the git repository):

+
Name Character Number Notes
Marshal 1 1 Dies if attacked by the Spy
General 2 1
Colonel 3 2
Major 4 3
Captain 5 4
Lietenant 6 4
Sergeant 7 4
Miner 8 5 Defuses Bombs and survives.
Scout 9 8 May move any number of times in a single direction.
Spy s 1 If the Spy attacks the Marshal, the Marshal is destroyed.
Bomb B 6 Immobile. Destroys both self and any unit that attacks the Bomb.
Flag F 1 Immobile. Capture the opponent's flag to win.
Unoccupied .
Obstacle *
+ + + +
Name Language Moves Considers...
basic_python Python Randomised
basic_cpp C++ Randomised
asmodeus Python Scored Path finding, known combat results, piece values
-

The AI program can't place any obstacles, and must at least place the Flag for its setup to be valid.

-

RED will always occupy the top four rows of the board, and BLUE occupies the bottom four rows.

- -

All pieces except the Scout, Bomb and Flag can move 1 square horizontally or vertically (not diagonally).

-

When two pieces of different ranks encounter each other, the piece with the highest rank (lowest numbered rank!) is the victor, unless a special rule applies.

-

When two pieces of equal rank encounter each other, the victor is randomly chosen

-

Pieces of the same colour may not pass through the same squares

- -

Turns

-

Query

-

RED starts the game. The manager queries RED to make the first move by printing:

-

START

-

Followed by a WIDTH*HEIGHT grid. '*' or '#' characters are used to indicate positions of unknown (BLUE/RED) enemy units.

- -

Response

-

The AI program must respond with a single line of the following form:

-

X Y DIRECTION [MULTIPLIER]

-

Where X and Y represent valid co-ordinates, upon which there is a piece of the AI program's colour.

-

DIRECTION must be either "UP", "DOWN", "LEFT", or "RIGHT", and is, obviously, the way the piece is supposed to move

-

MULTIPLIER is optional, and should only be given if the AI program is moving a Scout. Scouts may move multiple times in the same direction if possible.

-

- -

Outcome

-

The manager program will indicate the result of a move by responding with:

-

X Y DIRECTION [MULTIPLIER] OUTCOME

-

Where X, Y, DIRECTION and MULTIPLIER are as above.

-

OUTCOME signals the result of the turn, and will be one of the following:

- - - - - - - - -
OUTCOME Description
OK The piece was successfully moved, nothing eventful happened
FLAG The piece moved onto the opposing Flag; the game will end shortly
KILLS RANK1 RANK2 The piece landed on a square occupied by an enemy, and destroyed it, moving into the square
DIES RANK1 RANK2 The piece landed on a square occupied by an enemy, and was destroyed. The piece is removed from the board.
BOTHDIE RANK1 RANK2 The piece landed on a square occupied by an enemy, and both pieces were destroyed.
ILLEGAL The moving player attempted to make an illegal move, and has hence lost the game. The game will end shortly.
-

If printed, RANK1 and RANK2 indicate the ranks of the moved piece and the defending piece (the piece who occupied the destination square) respectively.

-

Originally RANK1 and RANK2 were never printed, but when I actually tried to write an AI myself I got very annoyed at this restriction... indicating it was probably a bad idea :P

- - -

Additional Turns

-

The Outcome of each turn is printed to both AI programs.

-

The state of the board is then printed to BLUE, who makes a move, then the process repeats.

+

It is planned to implement the equivelants of these samples in C++ and Python at least, possibly other languages later.

-

- -

Overview

-

This is a description of the signals the AI programs recieve, in order: -

    -
  1. Previous turn's outcome (other player's move) OR "START" if it is the first turn
  2. -
  3. A BOARD_WIDTH*BOARD_HEIGHT grid indicating the board state, with the AI program's own pieces revealed
  4. -
  5. After the AI program makes a move, the outcome is printed to it, and the other program, which continues from step 1
  6. -
-

I am considering removing Step 2, since all information needed for an AI to keep the board state is contained in the initial board state and then the movement result messages

- -

End Game

-

Query

-

At the end of the game, the manager program outputs the following:

-

VICTORY

-

To the winning AI program, and

-

DEFEAT

-

To the losing program.

-

Both programs then have 2 seconds to exit succesfully, or the manager will kill them.

-

Invalid Responses and Timeouts

-

If any program fails to respond correctly, or gives an invalid move, or does not respond within 1 second, it will lose by default.

-

In this case, the message

-

ILLEGAL

-

will be sent to the malfunctioning program, and

-

DEFAULT

-

to the other program

-

Both programs then have 2 seconds to exit succesfully, or the manager will kill them.

- -

Modifications/Clarifications to Rules

-

Refer to This site for the original rules again

-

Currently, the pieces taking part in the combat are not revealed; only the outcome of the combat is revealed. In a human game, the pieces would normally be revealed. I am planning to reveal the pieces, since not revealing pieces significantly reduces the value of low ranked pieces (normally used for working out enemy piece values).

-

It is up to the AI program to keep track of pieces. The manager program will only reveal the identity of the AI program's own pieces; the other player's pieces will be marked with * or # characters.

-

In a traditional game, two pieces of equal value will both be destroyed in combat. Currently, only one piece is destroyed and the outcome is randomly chosen.

- -

Example Programs

-

"Dummy" AI

-

Dummy randomly moves pieces. It attempts to not make illegal moves (although sometimes it still does).

-

"Forfax" AI

-

Forfax iterates through all possible moves and allocates a score between 0 and 1 to each move based on how desirable the move is. It then selects the highest scoring move.

-

Forfax is pretty terrible, but can beat the Dummy AI most of the time.

-

It is possible Forfax can be greatly improved by altering the scoring algorithms.

-

Since we don't want the Sample AIs to beat every entrance, I'm not really going to try and improve Forfax unless I get bored.

-

If you are writing an AI in C++, Forfax already contains a lot of useful functions.

- -

Longterm Scoring

-

I haven't started a system for pairing AI's and keeping track of scores and winners etc yet

-

I'll probably have a bash script that chooses who will play, and stores all the scores in files. I've done this before for a BrainF*** based "survival of the fittest" style thing, so I can probably recycle it

-

-

I believe it will make things more interesting if programs are allowed to keep state of who they have played, and the various tactics used.

-

Its kind of hard to implement this... at the moment programs are killed every time a game finishes

-

Perhaps it will be easier if each program is allowed access to one directory, where it can create and read files?

-

This would allow me to keep the manager program which actually plays the games seperate from the program for scoring and matching of opponents

-

There'd probably be security issues with that though.

+

Last webpage update: 7/12/11

diff --git a/web/screenshot.png b/web/screenshot.png new file mode 100644 index 0000000..276d892 Binary files /dev/null and b/web/screenshot.png differ