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. } }
owner-computer-go@xxxxxxxxxxxxxxxxx wrote:OK. Over lunch, I cleaned up the packaging a little and wrote a trivial GTPCan 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?
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/