/usr/share/pyshared/pychess/Players/Engine.py is in pychess 0.10.1~beta1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | from urllib import urlopen, urlencode
from gobject import SIGNAL_RUN_FIRST, TYPE_NONE
from pychess.System.ThreadPool import pool
from pychess.System.Log import log
from pychess.Utils.Offer import Offer
from pychess.Utils.const import ARTIFICIAL, CHAT_ACTION
from Player import Player
class Engine (Player):
__type__ = ARTIFICIAL
''' The first argument is the pv list of moves. The second is a score
relative to the engine. If no score is known, the value can be None,
but not 0, which is a draw. '''
__gsignals__ = {
'analyze': (SIGNAL_RUN_FIRST, TYPE_NONE, (object,object))
}
def __init__(self):
Player.__init__(self)
self.currentAnalysis = []
def on_analysis(self_, analysis, score):
if score != None:
self.currentScore = score
self.currentAnalysis = analysis
self.connect('analyze', on_analysis)
#===========================================================================
# Offer handling
#===========================================================================
def offer (self, offer):
raise NotImplementedError
def offerDeclined (self, offer):
pass #Ignore
def offerWithdrawn (self, offer):
pass #Ignore
def offerError (self, offer, error):
pass #Ignore
#===========================================================================
# General Engine Options
#===========================================================================
def setOptionAnalyzing (self, mode):
self.mode = mode
def setOptionInitialBoard (self, model):
""" If the game starts at a board other than FEN_START, it should be
sent here. We sends a gamemodel, so the engine can load the entire
list of moves, if any """
pass # Optional
def setOptionVariant (self, variant):
""" Inform the engine of any special variant. If the engine doesn't
understand the variant, this will raise an error. """
raise NotImplementedError
def setOptionTime (self, secs, gain):
""" Seconds is the initial clock of the game.
Gain is the amount of seconds a player gets after each move.
If the engine doesn't support playing with time, this will fail."""
raise NotImplementedError
def setOptionStrength (self, strength):
""" Strength is a number [1,8] inclusive. Higher is better. """
self.strength = strength
raise NotImplementedError
#===========================================================================
# Engine specific methods
#===========================================================================
def canAnalyze (self):
raise NotImplementedError
def getAnalysis (self):
""" Returns a list of moves, or None if there haven't yet been made an
analysis """
return self.currentAnalysis
#===========================================================================
# General chat handling
#===========================================================================
def putMessage (self, message):
def answer (message):
try:
data = urlopen("http://www.pandorabots.com/pandora/talk?botid=8d034368fe360895",
urlencode({"message":message, "botcust2":"x"})).read()
except IOError, e:
log.warn("Couldn't answer message from online bot: '%s'\n" % e,
self.defname)
return
ss = "<b>DMPGirl:</b>"
es = "<br>"
answer = data[data.find(ss)+len(ss) : data.find(es,data.find(ss))]
self.emit("offer", Offer(CHAT_ACTION, answer))
pool.start(answer, message)
|