[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

computer-go: Re: GTP Java client framework



I might be able to out-trivialize you:


I've got a tiny random player partially working. (It never passes and I have several more commands to implement, but at least you can start a game.)

Get gGo here:

http://igs.joyjoy.net/java/gGo/

(The "Java Web Start" version is easiest to install.)

Put the attached files in the directory from which you plan to launch gGo, and compile the Java files.

chmod a+x orego

Now start gGo, and under preferences give the path to orego as the path to GNU Go.

Click on "Play GNU Go", and viola!

I think that, once it's finished, GTPPlayer will be an excellent interface for programs to implement. We may want to build an abstract or even concrete class to provide standard functionality, but this is the route of minimum commitment and maximum flexibility.

Attachment: orego
Description: Binary data

import java.io.*;
import java.util.*;


public class Orego {

  private BufferedReader in;
  
  private GTPPlayer player;
  
  public Orego() throws IOException {
    player = new RandomPlayer();
    in = new BufferedReader(new InputStreamReader(System.in));
  }

  protected void play() throws IOException {
    while (true) {
      String s = in.readLine();
      //      log("Read: " + s);
      if (s.startsWith("boardsize")) {
        // Set board size
        StringTokenizer st = new StringTokenizer(s);
        st.nextToken();
        int n = Integer.parseInt(st.nextToken());
        System.out.println(player.setBoardSize(n)
                           ? "= " : "? unacceptable size");
      } else if (s.startsWith("genmove")) {
        // Generate a move
        System.out.println("= " + player.generateMove());
      } else if (s.startsWith("komi")) {
        // Set komi
        StringTokenizer st = new StringTokenizer(s);
        st.nextToken();
        double k = Double.parseDouble(st.nextToken());
        player.setKomi(k);
        System.out.println("= ");
      } else {
        StringTokenizer st = new StringTokenizer(s);
        String command = st.nextToken().toLowerCase();
        if ((command.equals("black")) ||
            (command.equals("b")) ||
            (command.equals("white")) ||
            (command.equals("w"))) {
          // Move made
          System.out.println(player.acceptMove(st.nextToken().toUpperCase())
               ? "= " : "? illegal move");
        } else {
          // Unknown command;  acknowledge and ignore
          System.out.println("= unknown command, ignoring");
        }
      }
    }
  }
  
  public static void main(String[] args) throws IOException {
    Orego game = new Orego();
    game.play();
  }
  
}
public interface GTPPlayer {

  /**
   * Accept a move made by the opponent.  The move is specified in the
   * human-readable format specified by GTP, e.g., "h10" or "pass".
   * The player may assume that all letters are upper-case.  Return true if
   * the move is legal, false otherwise.
   */
  public boolean acceptMove(String s);

  /**
   * Return a move.
   * @see GTPPlayer#acceptMove(String)
   */
  public String generateMove();
  
  /**
   * Update the player's board size if possible.  Return true if the size is
   * acceptable, false otherwise.
   */
  public boolean setBoardSize(int n);

  /**
   * Set the komi value.  Komi is a score bonus given to white to offset
   * black's advantage in going first.  Common values are 0.5 (white wins
   * ties) and 5.5.
   */
  public void setKomi(double k);
  
}
import java.util.*;

public class RandomPlayer implements GTPPlayer {

  private int boardSize;

  private Random random;

  public RandomPlayer() { random = new Random(); }

  /** Blindly assume that the move is legal. */
  public boolean acceptMove(String s) {
    return true;
  }

  /**
   * Pick a random point on the board and move there.  This move may be
   * illegal.
   */
  public String generateMove() {
    int column = random.nextInt(boardSize);
    int row = random.nextInt(boardSize) + 1;
    if (column < 'I' - 'A') {
      return "" + (char)('A' + column) + row;
    } else {
      return "" + (char)('B' + column) + row;
    }
  }
  
  public boolean setBoardSize(int n) {
    boardSize = n;
    return true;
  }

  public void setKomi(double k) {
    // Since RandomPlayer (currently) doesn't score, komi is ignored.
  }
  
}


I'm very interested in working with people who are building GTP front ends to stabilize the protocol!



On Wednesday, March 5, 2003, at 01:44 PM, Piotr Kaminski wrote:

owner-computer-go@xxxxxxxxxxxxxxxxx wrote:
Can we talk you into showing us how to write a trivial AI (i.e., a
random player which does not even keep track of the board state) that
works with this?
OK. Over lunch, I cleaned up the packaging a little and wrote a trivial GTP
random player. Grab the new source code, and look at
com.ideanest.vegos.RandomGTPEngine. It doesn't get more trivial than that.
:-)

-- P.

--
Piotr Kaminski (piotr@xxxxxxxxxxxxxxxxx)
It's the heart afraid of breaking that never learns to dance.

Peter Drake
Assistant Professor of Computer Science
Lewis & Clark College
http://www.lclark.edu/~drake/