Welcome, Guest. Please Login or Register.
Apr 19th, 2024, 3:30pm

Home Home Help Help Search Search Members Members Login Login Register Register
Arimaa Forum « Arimaa Engine Interface (AEI) »


   Arimaa Forum
   Arimaa
   Bot Development
(Moderator: supersamu)
   Arimaa Engine Interface (AEI)
« Previous topic | Next topic »
Pages: 1 2 3 4 5  ...  7 Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print
   Author  Topic: Arimaa Engine Interface (AEI)  (Read 21574 times)
99of9
Forum Guru
*****




Gnobby's creator (player #314)

  toby_hudson  


Gender: male
Posts: 1413
Re: Arimaa Engine Interface (AEI)
« Reply #30 on: Mar 25th, 2010, 6:33pm »
Quote Quote Modify Modify

Hi Janzert,
If you have a set of instructions that says how to convert from the old bot script to the AEI, I would probably do it.  I would prefer not to make any significant program changes at this point, so would not make use of any of your new functionality (e.g. pondering).  Is there a way to just run a new executable each move?
IP Logged
Janzert
Forum Guru
*****



Arimaa player #247

   


Gender: male
Posts: 1016
Re: Arimaa Engine Interface (AEI)
« Reply #31 on: Mar 26th, 2010, 7:30am »
Quote Quote Modify Modify

While I think it is pretty close to the same degree of difficulty to start a bot using either interface, it's probably harder to convert between them. Because the assumptions an engine will inevitably make are going to be quite different. But I believe Clueless is the only bot that has been converted between the two so I'm sure Jdb could comment on this better than I can. So unless you want to take advantage of something AEI makes easy (pondering, not restarting every move) I don't think it is worth the effort of converting.
 
Also I'm planning on writing an adapter that will run getmove based engines under an AEI controller. Although the primary use I see for this is to run getmove bots under an AEI gui.
 
Janzert
IP Logged
jdb
Forum Guru
*****



Arimaa player #214

   


Gender: male
Posts: 682
Re: Arimaa Engine Interface (AEI)
« Reply #32 on: Mar 26th, 2010, 12:23pm »
Quote Quote Modify Modify

Here is the code from clueless to interface to gtp.
 
The indentation messed up. I have no idea how to fix it.
 
Code:

package arimaa3;
 
import ai_util.*;
 
import java.util.*;
import java.io.*;
import cataract.GtpCommand;
 
public class ArimaaEngineInterface {
  public ArimaaEngineInterface() {
  }
 
  private GameState initial_position = new GameState();
  private ArrayList<String> move_list = new ArrayList<String>();
  private EngineThread engine_thread = new EngineThread();
  private ArimaaEngine engine = new ArimaaEngine("clueless.cfg");
 private ArimaaServerInfo info = new ArimaaServerInfo(initial_position);
   
 
  // All messages must by sent thru here so they get logged
  private void send_message(String text) {
    text += "\n";  
    LogFile.message("AEIs--> " + text);
    System.out.print(text);
    System.out.flush();
  }
 
 
  private void control() {
 
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
 
    while (true) {
 try {
   // Get the message
   String message = reader.readLine();
 
   // Write message to log file
   LogFile.message("AEIr--> " + message);
 
   // If connection broken, just shutdown
   if (message == null) {
     engine.shutdown_search();
     return;
   }
 
   GtpCommand command = new GtpCommand(message);
 
   // Figure out which command it is
   if (command.command.equals("aei")) {
     send_message("id name clueless");
     send_message("id author Jeff Bacher");
     send_message("id version 2009");
    send_message("aeiok");
   }
 
   else if (command.command.equals("isready")) {
     send_message("readyok");
   }
 
   else if (command.command.equals("quit")) {
     engine.shutdown_search();
     return;
   }
   
   else if (command.command.equals("stop")) {
     engine.abort_search();
   }
 
   else if (command.command.equals("newgame")) {
     engine.abort_search();
     initial_position = new GameState();
     move_list.clear();
   }
   
   else if (command.command.equals("makemove")) {
    String move_text = command.getRestOfCommand();
    move_list.add(move_text);
   }
 
   else if (command.command.equals("setposition")) {
    String position_text = command.getRestOfCommand();
     initial_position = new GameState(position_text);
    move_list.clear();
   }
   
   else if (command.command.equals("setoption")) {
    String name = command.arguments.get(1);
    String value = command.arguments.get(3);
    set_option(name,value);
   }
 
   else if (command.command.equals("go")) {
     if ( command.getRestOfCommand().equals("ponder") ) {
       
     }
     else {
      engine_thread.run();
     }
   }
   
   
 
   // Try sending command on to the engine
   else {
  // Unknown command received, just log it and ignore the command
   }
   
 
 } // Loop forever
 
 // This should never happen!
 // We're sunk if we get here, just exit
 catch (Exception e) {
   StringWriter sw = new StringWriter();
   e.printStackTrace(new PrintWriter(sw));
   String stackTrace = sw.toString();
   LogFile.message("Exception " + e);
   LogFile.message(stackTrace);
 }
    }
 
  }
   
  private void set_option(String name, String value_text) {
   name = name.toLowerCase();
   
   if ( name.equals("rated") ) {
    info.is_rated  = value_text.equals("1") ? true : false;
   }
   
   if ( name.equals("opponent")) {
    info.enemy_name = value_text;
   }
   
   if ( name.equals("tcmove") ) {
     int value = Integer.parseInt(value_text);
    info.tc_move = value;
   }
 
   if ( name.equals("tcpercent") ) {
     int value = Integer.parseInt(value_text);
    info.tc_percent = value;
   }
 
   if ( name.equals("tcmax") ) {
     int value = Integer.parseInt(value_text);
    if (value == 0 ) {
     value = Integer.MAX_VALUE;
    }
    info.tc_max_reserve = value;
   }
 
   if ( name.equals("tcturntime") ) {
     int value = Integer.parseInt(value_text);
    if (value == 0 ) {
     value = Integer.MAX_VALUE;
    }
    info.tc_max_turn_time = value;
   }
   
   if ( name.equals("wreserve")) {
     int value = Integer.parseInt(value_text);
    info.tc_white_reserve = value;
   }
 
   if ( name.equals("breserve")) {
     int value = Integer.parseInt(value_text);
    info.tc_black_reserve = value;
   }
   
  }
   
   
  private void populate_arimaa_server_info() {
   
   // Get the current gamestate
   GameState current_position = new GameState();
   for( String move_text : move_list ) {
    ArimaaMove move = new ArimaaMove(move_text);
    current_position.play(move,current_position);
   }
   info.position = current_position.toEPDString();
   info.side_to_move = current_position.getSideToMove();
   
   // Create the move list
   String move_list_text = "";
   int half_move_count = 0;
   for( String move_text : move_list ) {
    move_list_text += getMoveIdentifier(half_move_count);
    move_list_text += " "+move_text;
    move_list_text += "%13";
    half_move_count++;
   }
   
   move_list_text += getMoveIdentifier(half_move_count);
   info.move_list = move_list_text;
   
  }
   
  private String getMoveIdentifier(int half_move_count) {
   String result = "";
   
   int move_number = half_move_count/2 + 1;
   int side_to_move = move_number & 0x01;
   
   result += move_number;
   result += (side_to_move == 0) ? "w" : "b";
       
   return result;
  }
   
  // Separate thread to run the engine
  private class EngineThread implements Runnable {
   public void run() {
 long start_time = System.currentTimeMillis();
     
    populate_arimaa_server_info();
     
    MoveInfo move = engine.genMove(info);
 // remove any pass words, as arimaa-online doesn't want them
 String final_move = move.move_text.replaceAll(" pass", "");
 send_message("bestmove " + final_move);
 
 long elapsed_time = System.currentTimeMillis() - start_time;
 LogFile.message("Elapsed time: "+elapsed_time+" ms");
   }
  }
 
  public static void main(String args[]) {
    LogFile.setMessageDisplay(false);
    LogFile.message( (new Date()).toString());
 
    ArimaaEngineInterface main = new ArimaaEngineInterface();
    main.control();
  }
 
}
 
IP Logged
rabbits
Forum Guru
*****




Arimaa player #1337

   
WWW

Gender: male
Posts: 108
Re: Arimaa Engine Interface (AEI)
« Reply #33 on: Mar 27th, 2010, 4:47pm »
Quote Quote Modify Modify

on Mar 25th, 2010, 6:33pm, 99of9 wrote:
Is there a way to just run a new executable each move?

I just added a simple getmove adapter script to my GUI project.  I have used it with bot_Score1 and bot_Fairy, so maybe it will work with bot_Gnobot.
IP Logged

Polyfractal
Forum Senior Member
****



Arimaa player #3241

   


Gender: male
Posts: 27
Re: Arimaa Engine Interface (AEI)
« Reply #34 on: Jun 18th, 2010, 10:48am »
Quote Quote Modify Modify

Quick question regarding AEI since I haven't worked with it in ages (haven't programmed in ages now that I think about it):
 
How does AEI handle illegal moves when playing locally bot-against-bot? Does it terminate the game or report an error and allow the bot engine to submit another attempt?
« Last Edit: Jun 18th, 2010, 11:09am by Polyfractal » IP Logged
Janzert
Forum Guru
*****



Arimaa player #247

   


Gender: male
Posts: 1016
Re: Arimaa Engine Interface (AEI)
« Reply #35 on: Jun 21st, 2010, 1:24pm »
Quote Quote Modify Modify

AEI the protocol doesn't specify what the controller should do when receiving an illegal move. This was explicit and I can give the reasoning for what I think should be done in a few specific cases, but I don't think this is what you're trying to find out.
 
Since you specify playing locally I assume you're wondering how the "roundrobin.py" script handles illegal moves. Currently it doesn't do any explicit checking, but it does track the current state of the board so it can tell when the game has ended. This should result in a large number of illegal moves being caught and cause an exception to be thrown. But there are also a number of cases that will just silently be accepted. This is certainly something that can and should be improved. Both to catch all illegal moves and to properly assign the result.
 
Janzert
IP Logged
FireBorn
Forum Guru
*****



Arimaa player #1832

   


Gender: male
Posts: 123
Re: Arimaa Engine Interface (AEI)
« Reply #36 on: Jun 21st, 2010, 4:07pm »
Quote Quote Modify Modify

I am curious why there is no checking for illegal moves.
 
I looked into using AEI to evolve my bots, but if I did they would be getting away with all kinds of illegal moves!
IP Logged
Janzert
Forum Guru
*****



Arimaa player #247

   


Gender: male
Posts: 1016
Re: Arimaa Engine Interface (AEI)
« Reply #37 on: Jun 21st, 2010, 9:49pm »
Quote Quote Modify Modify

on Jun 21st, 2010, 4:07pm, FireBorn wrote:
I am curious why there is no checking for illegal moves.

 
Why there is no checking where? Specified in the protocol, implemented in the gameroom interface, implemented in roundrobin.py, or one of the other controller scripts included in the standard implementation?
 
The protocol doesn't specify checking for a couple of different reasons. Two big ones are: the appropriate response by a controller varies from one controller to another depending on how that controller is being used, and although the name may not imply it the AEI protocol is quite generic and at the vary least should handle many Arimaa variants without any change.
 
The main reason the gameroom interface does no checking is because one of the highest priorities for it is "no game should ever be lost by an engine because of the interface". Adding any sort of checking would always open the possibility of rejecting a move that the server would have accepted (maybe the server is actually playing a variant Wink ).
 
The only reason roundrobin.py doesn't check is simply that it's never been added. The underlying board representation already has methods to check a moves legality, the appropriate calls to actually check just need to be added to roundrobin.py. I've just never needed it although I'm sure I'll probably get to it. But I won't guarantee the legality check methods are fully correct. I've only used them in a very rudimentary GUI I started a while back. Rabbits has also sent some fixes for them though, so I imagine he must be using them as well. Although I don't know how extensively or for what purpose.
 
Quote:
I looked into using AEI to evolve my bots, but if I did they would be getting away with all kinds of illegal moves!

 
Certainly the AEI protocol would be perfectly suitable for controlling evolving bots. Also quite certainly none of the controllers included in the standard implementation are suitable for doing so, even if they did check for move legality.
 
Janzert
IP Logged
FireBorn
Forum Guru
*****



Arimaa player #1832

   


Gender: male
Posts: 123
Re: Arimaa Engine Interface (AEI)
« Reply #38 on: Jun 22nd, 2010, 8:36am »
Quote Quote Modify Modify

Thanks, I get it now
 
on Jun 21st, 2010, 9:49pm, Janzert wrote:
Certainly the AEI protocol would be perfectly suitable for controlling evolving bots. Also quite certainly none of the controllers included in the standard implementation are suitable for doing so, even if they did check for move legality.

I ended up using Chimaera, which has a lot of illegal move checking, but even then I had to add some checking to ensure proper move notation.
IP Logged
Janzert
Forum Guru
*****



Arimaa player #247

   


Gender: male
Posts: 1016
Re: Arimaa Engine Interface (AEI)
« Reply #39 on: Jun 23rd, 2010, 8:00pm »
Quote Quote Modify Modify

Great; so it sounds like what you needed was more of a general engine.
 
Janzert
IP Logged
rbarreira
Forum Guru
*****



Arimaa player #1621

   


Gender: male
Posts: 605
Re: Arimaa Engine Interface (AEI)
« Reply #40 on: Jun 28th, 2010, 1:37am »
Quote Quote Modify Modify

I've noticed that my bot cannot play games that have already started (for example, if the bot crashes the gameroom controller attempts to restart it; this probably also happens if trying to move on a postal game, though I haven't tried).
 
I'm thinking that this is due to the wrong assumption that it will always receive a "go" command either asking for a gold or a silver setup. In fact this is how my bot today can tell whether it's supposed to play as gold or silver.
 
I suppose that to fix this, the only correct way to know whether we're playing Gold or Silver is to wait for the first "go" or "go ponder" command. Is there an easier way, especially something that tells us our side before moves start getting sent with the makemove command?
« Last Edit: Jun 28th, 2010, 1:38am by rbarreira » IP Logged
Janzert
Forum Guru
*****



Arimaa player #247

   


Gender: male
Posts: 1016
Re: Arimaa Engine Interface (AEI)
« Reply #41 on: Jun 28th, 2010, 7:30am »
Quote Quote Modify Modify

The only way to determine what side the engine should think about is to check the current state of the game. Even after the first "go" command it shouldn't assume that it will always be asked to think about the same side after that or that the move it returns will be the actual move played.
 
And yes from the engine's perspective with the current interface joining an ongoing postal game will look the same as joining or rejoining an ongoing live game. After starting the engine and initializing it with the game settings the interface with "catch the engine up" by sending it a series of makemove commands for all the moves of the game already played.
 
Janzert
IP Logged
rbarreira
Forum Guru
*****



Arimaa player #1621

   


Gender: male
Posts: 605
Re: Arimaa Engine Interface (AEI)
« Reply #42 on: Jun 28th, 2010, 7:35am »
Quote Quote Modify Modify

Thanks for the reply.  Except for the input/output of Arimaa notation, my code is not based on gold/silver sides but instead on my/opponent sides, so I guess I'll have to work around this in some way.
« Last Edit: Jun 28th, 2010, 7:37am by rbarreira » IP Logged
Janzert
Forum Guru
*****



Arimaa player #247

   


Gender: male
Posts: 1016
Re: Arimaa Engine Interface (AEI)
« Reply #43 on: Jun 28th, 2010, 10:55am »
Quote Quote Modify Modify

My thought on how to handle it in that case would be to reverse the board after every makemove command and keep a separate field to track what color's turn it actually is.
 
Janzert
IP Logged
doublep
Forum Guru
*****



Badger author

   


Gender: male
Posts: 82
Re: Arimaa Engine Interface (AEI)
« Reply #44 on: Jul 4th, 2010, 9:20am »
Quote Quote Modify Modify

I started working on AEI support in Badger.  However, I can't get to start roundrobin script:
 
Code:

cmdline = /home/paul/badger/tools/gtp-aei.py --command '/home/paul/badger/badger -T all'

Causes the following failure in (my own) 'gtp-aei.py' script:
 
Code:

getopt.GetoptError: option -T not recognized

The intention is to pass -T as part of --command value, not as a separate argument.  I guess the problem is that subprocess.Popen() in 'aei.py' is invoked without shell = True argument.  Can we have that as an option?  I'd hate to split configuration in a hundred different files and would prefer to pass most of it through command line.
 
Also, if 'roundrobin.py' fails for any reason, including Ctrl-C abortion, it should kill all spawned engine processes.  I had about 8 'simple_engine.py' running and wondered wtf my system was so slow...
IP Logged
Pages: 1 2 3 4 5  ...  7 Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print

« Previous topic | Next topic »

Arimaa Forum » Powered by YaBB 1 Gold - SP 1.3.1!
YaBB © 2000-2003. All Rights Reserved.