[Pachi] Implement GTP known_command

Matthew Woodcraft matthew at woodcraft.me.uk
Sun May 8 17:40:09 CEST 2011


Hi!

Here are two patches, to implement the GTP 'known_command' command, and
to add 'final_score' to the list of 'exported' commands.

Between them, these should be enough to let GTP controllers know that
pachi can score games.


-M-



8<--8<--8<--8<--8<--8<--8<--8<

>From 2e3a80a9bdad993233982e3e08190b87b5dd36de Mon Sep 17 00:00:00 2001
From: Matthew Woodcraft <matthew at woodcraft.me.uk>
Date: Sun, 8 May 2011 15:42:52 +0100
Subject: [PATCH 1/2] Implement known_command; make gtp_is_valid() stricter

---
 gtp.c |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/gtp.c b/gtp.c
index 804c943..206e80e 100644
--- a/gtp.c
+++ b/gtp.c
@@ -79,6 +79,7 @@ static char *known_commands =
 	"name\n"
 	"version\n"
 	"list_commands\n"
+	"known_command\n"
 	"quit\n"
 	"boardsize\n"
 	"clear_board\n"
@@ -106,6 +107,7 @@ gtp_is_valid(char *cmd)
 	if (!cmd || !*cmd) return false;
 	char *s = strcasestr(known_commands, cmd);
 	if (!s) return false;
+	if (s != known_commands && s[-1] != '\n') return false;
 
 	int len = strlen(cmd);
 	return s[len] == '\0' || s[len] == '\n';
@@ -160,6 +162,16 @@ gtp_parse(struct board *board, struct engine *engine, struct time_info *ti, char
 	} else if (!strcasecmp(cmd, "list_commands")) {
 		gtp_reply(id, known_commands, NULL);
 		return P_OK;
+
+	} else if (!strcasecmp(cmd, "known_command")) {
+		char *arg;
+		next_tok(arg);
+		if (gtp_is_valid(arg)) {
+			gtp_reply(id, "true", NULL);
+		} else {
+			gtp_reply(id, "false", NULL);
+		}
+		return P_OK;
 	}
 
 	if (engine->notify && gtp_is_valid(cmd)) {
-- 
1.7.2.5


>From 0b32c8acdc7795cd0932031d3540f86766efff02 Mon Sep 17 00:00:00 2001
From: Matthew Woodcraft <matthew at woodcraft.me.uk>
Date: Sun, 8 May 2011 15:44:07 +0100
Subject: [PATCH 2/2] Add final_score to known_commands

---
 gtp.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/gtp.c b/gtp.c
index 206e80e..0e40992 100644
--- a/gtp.c
+++ b/gtp.c
@@ -91,6 +91,7 @@ static char *known_commands =
 	"kgs-genmove_cleanup\n"
 	"set_free_handicap\n"
 	"place_free_handicap\n"
+	"final_score\n"
 	"final_status_list\n"
 	"undo\n"
 	"pachi-result\n"
-- 
1.7.2.5



More information about the Pachi mailing list