当前位置: 首页>>代码示例>>Python>>正文


Python Program.sendCommand方法代码示例

本文整理汇总了Python中program.Program.sendCommand方法的典型用法代码示例。如果您正苦于以下问题:Python Program.sendCommand方法的具体用法?Python Program.sendCommand怎么用?Python Program.sendCommand使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在program.Program的用法示例。


在下文中一共展示了Program.sendCommand方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from program import Program [as 别名]
# 或者: from program.Program import sendCommand [as 别名]
class agent:
	def __init__(self, exe):
		self.exe = exe 
		self.program = Program(self.exe, True)
		self.name = self.program.sendCommand("name").strip()
		self.lock  = threading.Lock()

	def sendCommand(self, command):
		self.lock.acquire()
		answer = self.program.sendCommand(command)
		self.lock.release()
		return answer

	def reconnect(self):
		self.program.terminate()
		self.program = Program(self.exe,True)
		self.lock = threading.Lock()
开发者ID:gauthamvasan,项目名称:Neurohex,代码行数:19,代码来源:wolve_tournament.py

示例2: of

# 需要导入模块: from program import Program [as 别名]
# 或者: from program.Program import sendCommand [as 别名]
parser.add_argument("--boardsize", "-b", type=int, help="side length of (square) board")
parser.add_argument("--time", "-t", type=int, help="total time allowed for each move in seconds")
args = parser.parse_args()

if args.boardsize:
	boardsize = args.boardsize
else:
	boardsize = 11

if args.time:
	time = args.time
else:
	time = 10

agent = Program(args.program, False)
agent.sendCommand("boardsize "+str(boardsize))
agent.sendCommand("set_time "+str(time))

human_game = gamestate(boardsize)
game = gamestate(boardsize)
winner = None
moves = []

while(True):
	if(args.first):
		moves.append(get_human_move(game, human_game, "black"))
		if(game.winner() != game.PLAYERS["none"]):
			winner = game.winner()
			break
		print("waiting for opponent...")
		moves.append(make_valid_move(game, agent, "white").strip())
开发者ID:dmorrill10,项目名称:KHex,代码行数:33,代码来源:human_vs.py

示例3: int

# 需要导入模块: from program import Program [as 别名]
# 或者: from program.Program import sendCommand [as 别名]
s = socket.socket(
    socket.AF_INET, socket.SOCK_STREAM)

s.connect((server_addr, int(server_port)))

agent = Program(args.program, True)

while(True):
	command = ''
	bytes_recd = 0
	while True:
	    chunk = s.recv(2048)
	    if chunk == b'':
	        raise RuntimeError("Connection to server lost")
	    command+=chunk.decode('UTF-8')
	    if(chunk[-1]!='\n'):
	    	break
	response = agent.sendCommand(command)
	totalsent=0
	while totalsent < len(response):
		sent = s.send(bytes(response[totalsent:],'UTF-8'))
		if sent == 0:
			raise RuntimeError("client disconnected")
		totalsent += sent
	bytes_recd = 0





开发者ID:dmorrill10,项目名称:KHex,代码行数:27,代码来源:tournament_client.py

示例4: DfpnSolver

# 需要导入模块: from program import Program [as 别名]
# 或者: from program.Program import sendCommand [as 别名]
class DfpnSolver(Thread):
    class Error:
        pass

    def __init__(self, name, command, positions, verbose):
        Thread.__init__(self)
        self._name = name
        self._positions = positions
        self._verbose = verbose
        command = command + " --logfile-name=" + name + ".log"
        self._program = Program(command, verbose)

    def sendCommand(self, command):
        try:
            return self._program.sendCommand(command);
        except Program.CommandDenied:
            reason = self._program.getDenyReason()
            self._errorMessage = _name + ": "  + reason
            raise DfpnSolver.Error
        except Program.Died:
            self._errorMessage = _name + ": program died"
            raise DfpnSolver.Error

    def playVariation(self, variation):
        self.sendCommand("clear_board");
        moves = variation.split(' ');
        color = "B";
        for move in moves:
            cmd = "play " + color + " " + move.strip();
            self.sendCommand(cmd);
            if color == "B":
                color = "W";
            else:
                color = "B";
            
    def solvePosition(self, variation):
        if (self._verbose):
            print "#####################################"
            print self._name + ": " + variation
            print "#####################################"
        else:
            print self._name + ": " + variation
        self.playVariation(variation);
        return self.sendCommand("dfpn-solve-state");

    def addResult(self, variation, winner):
        if (winner == "empty"):
            f = open(self._name + ".unsolved", "a");
            print >> f, variation;
            f.close();
        else:
            f = open(self._name + ".solved", "a");
            print >> f, variation + " " + winner
            f.close();

    def run(self):
        while True:
            variation = self._positions.getPosition();
            if variation == "":
                return;
            else:
                winner = self.solvePosition(variation).strip();
                self.addResult(variation, winner);
                print self._name + ": " + winner
开发者ID:PawelTroka,项目名称:LogicalGamesEnginesGenerator,代码行数:66,代码来源:book-solve.py

示例5: Program

# 需要导入模块: from program import Program [as 别名]
# 或者: from program.Program import sendCommand [as 别名]
    bcmd = oppcmd
    bLogName = oppLogName
    bsettings = opponent_settings
    wcmd = optcmd
    wLogName = optLogName
    wsettings = optimized_settings

time.sleep(random.random())
black = Program("B", command_prefix + bcmd + command_suffix, bLogName, verbose)
time.sleep(random.random())
white = Program("W", command_prefix + wcmd + command_suffix, wLogName, verbose)

# pass settings to programs
try:
    for opt in bsettings:
        black.sendCommand(opt)
    for opt in wsettings:
        white.sendCommand(opt)
except GamePlayer.Error:
    print "Error during initialization!"
    print gamePlayer.getErrorMessage()
except Program.Died:
    print "Error during initialization!"
    print "program died"
   
opening = randomOpening(size, seed / 2)
resultBlack = "?"
resultWhite = "?"
error = 0
errorMessage = ""
game = Game()  # just a temporary
开发者ID:kenjyoung,项目名称:benzene-vanilla,代码行数:33,代码来源:MoHexScript.py

示例6: get_wins

# 需要导入模块: from program import Program [as 别名]
# 或者: from program.Program import sendCommand [as 别名]
def get_wins(program, size, opening):
	program.sendCommand("clear_board")
	program.sendCommand("boardsize "+str(size))
	toplay = 0
	for move in opening:
		program.sendCommand("play "+PLAYERS[toplay]+" "+move)
		toplay = not toplay
	return program.sendCommand("dfpn-solver-find-winning "+PLAYERS[toplay])


p = argparse.ArgumentParser()
p.add_argument('moves', metavar = 'moves', type = int, help = 'number of moves in generated positions.')
p.add_argument('positions', metavar = 'positions', type = int, help = 'number of positions to generate.')
args = p.parse_args()

cells =  [chr(ord('a')+x)+str(y+1) for x in range(5) for y in range(5)]
openings = []

mohex = Program("../mohex/./mohex 2>/dev/null", False)
mohex.sendCommand("param_dfpn threads 4")

for p in range(args.positions):
	random.shuffle(cells)
	opening = cells[0:args.moves]
	for c in opening[0:-1]:
		print(c, end = " ")
	print(opening[-1], end = "")
	print(":", end = "")
	print(get_wins(mohex, 5, opening).strip())
开发者ID:kenjyoung,项目名称:benzene,代码行数:31,代码来源:random5x5.py

示例7: Program

# 需要导入模块: from program import Program [as 别名]
# 或者: from program.Program import sendCommand [as 别名]
import time
from program import Program

PLAYERS = {0: "white", 1: "black"}
PASSCOLOR = '\033[92m'
FAILCOLOR = '\033[91m'
ENDCOLOR = '\033[0m'

mohex = Program("../mohex/./mohex 2>/dev/null", False)
mohex.sendCommand("param_dfpn threads 4")
mohex.sendCommand("boardsize 6")

mohex.sendCommand("play white d2")
start = time.time()
mohex.sendCommand("dfpn-solve-state black")
elapsed = time.time() - start
print("Total Runtime: "+str(elapsed))


开发者ID:kenjyoung,项目名称:benzene,代码行数:19,代码来源:knockout_6x6.py


注:本文中的program.Program.sendCommand方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。