[gnome-games] Detect resign and draw requests from CECP AIs
- From: Robert Ancell <rancell src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnome-games] Detect resign and draw requests from CECP AIs
- Date: Tue, 1 Sep 2009 00:47:00 +0000 (UTC)
commit 452d8a861d6e41cb917175a5704c6fd787cc1e2c
Author: Robert Ancell <robert ancell gmail com>
Date: Tue Sep 1 10:35:20 2009 +1000
Detect resign and draw requests from CECP AIs
glchess/src/lib/cecp.py | 23 ++++++++++++++++-------
1 files changed, 16 insertions(+), 7 deletions(-)
---
diff --git a/glchess/src/lib/cecp.py b/glchess/src/lib/cecp.py
index d7e3717..f65136f 100644
--- a/glchess/src/lib/cecp.py
+++ b/glchess/src/lib/cecp.py
@@ -9,9 +9,10 @@ class CECPProtocol:
NEWLINE = '\n'
MOVE_PREFIXS = ['My move is: ', 'my move is ', 'move ']
INVALID_MOVE_PREFIX = 'Illegal move: '
- RESIGN_PREFIX = 'tellics resign'
- DRAW_PREFIX = '1/2-1/2'
-
+ RESIGN_PREFIX = 'resign'
+ RESIGN_ICS_PREFIX = 'tellics resign'
+ DRAW_PREFIX = 'offer draw'
+
def __init__(self):
"""
"""
@@ -54,6 +55,10 @@ class CECPProtocol:
"""Called when the AI resigns"""
print 'CECP AI resigns'
+ def onDraw(self):
+ """Called when the AI requests a draw"""
+ print 'CECP AI calls a draw'
+
def logText(self, text, style):
print 'LOG: %s' % text
@@ -139,15 +144,19 @@ class CECPProtocol:
self.logText(line + '\n', 'move')
self.onMove(move.strip())
return
-
+
if line.startswith(self.INVALID_MOVE_PREFIX):
self.onIllegalMove(line[len(self.INVALID_MOVE_PREFIX):])
- elif line.startswith(self.RESIGN_PREFIX):
+ elif line.startswith(self.RESIGN_PREFIX) or line.startswith(self.RESIGN_ICS_PREFIX):
+ self.logText(line + '\n', 'move')
self.onResign()
-
+ return
+
elif line.startswith(self.DRAW_PREFIX):
- print 'AI calls a draw'
+ self.logText(line + '\n', 'move')
+ self.onDraw()
+ return
else:
self.onUnknownLine(line)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]