コード例 #1
0
    resultWhite = white.getResult()
    filename = path + ("/%07d.sgf" % seed)
    gamePlayer.save(filename, seed, resultBlack, resultWhite)

    result = "?"
    if resultBlack == resultWhite:
        result = resultBlack

    if result == '?':
        print "Error: could not determine game result"
    elif 'B+' in result:
        if (seed % 2 == 0):  # seed even ==> black == opt
            print "W"
        else:
            print "L"
    elif 'W+' in result:     
        if (seed % 2 == 0):  # seed even ==> black == opt
            print "L"
        else:
            print "W"

except GamePlayer.Error:
    error = 1
    errorMessage = gamePlayer.getErrorMessage()
    print errorMessage
except Program.Died:
    error = 1
    errorMessage = "program died"
    print errorMessage

コード例 #2
0
    def playGame(self, gameIndex, currentRound, 
                 blackName, blackCmd, whiteName, whiteCmd,
                 opening, verbose):
        if verbose:
            print
            print "==========================================================="
            print "Game ", gameIndex
            print "==========================================================="
            
        bcmd = "nice " + blackCmd + " --seed %SRAND" \
               + " --logfile-name " + self._outdir + "/"  \
               + blackName + "-" + str(gameIndex) + ".log"
        wcmd = "nice " + whiteCmd + " --seed %SRAND" \
               + " --logfile-name " + self._outdir + "/"  \
               + whiteName + "-" + str(gameIndex) + ".log"
        bLogName = self._outdir + "/" + blackName + "-" + str(gameIndex) \
                          + "-stderr.log"
        wLogName = self._outdir + "/" + whiteName + "-" + str(gameIndex) \
                          + "-stderr.log"
        black = Program("B", bcmd, bLogName, verbose)
        white = Program("W", wcmd, wLogName, verbose)
        
        resultBlack = "?"
        resultWhite = "?"
        error = 0
        errorMessage = ""
        game = Game()  # just a temporary
        gamePlayer = GamePlayer(black, white, self._size)
        try:
            game = gamePlayer.play(opening, verbose)
            swapped = game.playedSwap()
            resultBlack = self.handleResult(swapped, black.getResult())
            resultWhite = self.handleResult(swapped, white.getResult())
        except GamePlayer.Error:
            error = 1
            errorMessage = gamePlayer.getErrorMessage()
        except Program.Died:
            error = 1
            errorMessage = "program died"

        name = "%s/%04i" % (self._outdir, gameIndex)

        # save the result
        # recall it has been flipped if a swap move was played
        result = "?"
        if resultBlack == resultWhite:
            result = resultBlack
        game.setResult(result)

        # save it to the results file
        self._resultsFile.addResult(currentRound, opening,
                                    blackName, whiteName,
                                    resultBlack, resultWhite,
                                    # -1 so we don't count "resign" as a move
                                    game.getLength()-1,
                                    game.getElapsed("black"),
                                    game.getElapsed("white"),
                                    error, errorMessage)

        # save game
        gamePlayer.save(name + ".sgf", name, resultBlack, resultWhite)
        if error:
            print "Error: Game", gameIndex
        for program in [black, white]:
            try:
                program.sendCommand("quit");
            except Program.Died:
                pass
            
        return game
コード例 #3
0
ファイル: tournament.py プロジェクト: w14/benzene
    def playGame(self, gameIndex, currentRound, 
                 blackName, blackCmd, whiteName, whiteCmd,
                 opening, verbose):
        if verbose:
            print
            print "==========================================================="
            print "Game ", gameIndex
            print "==========================================================="
            
        bcmd = "nice " + blackCmd + " --seed %SRAND" \
               + " --logfile-name " + self._outdir + "/"  \
               + blackName + "-" + str(gameIndex) + ".log"
        wcmd = "nice " + whiteCmd + " --seed %SRAND" \
               + " --logfile-name " + self._outdir + "/"  \
               + whiteName + "-" + str(gameIndex) + ".log"
        
        black = Program("B", bcmd, verbose)
        white = Program("W", wcmd, verbose)
        
        resultBlack = "?"
        resultWhite = "?"
        error = 0
        errorMessage = ""
        game = Game()  # just a temporary
        gamePlayer = GamePlayer(black, white, self._size)
        try:
            game = gamePlayer.play(opening, verbose)
            swapped = game.playedSwap()
            resultBlack = self.handleResult(swapped, black.getResult())
            resultWhite = self.handleResult(swapped, white.getResult())
        except GamePlayer.Error:
            error = 1
            errorMessage = gamePlayer.getErrorMessage()
        except Program.Died:
            error = 1
            errorMessage = "program died"

        name = "%s/%04i" % (self._outdir, gameIndex)

        # save the result
        # recall it has been flipped if a swap move was played
        result = "?"
        if resultBlack == resultWhite:
            result = resultBlack
        game.setResult(result)

        # save it to the results file
        self._resultsFile.addResult(currentRound, opening,
                                    blackName, whiteName,
                                    resultBlack, resultWhite,
                                    # -1 so we don't count "resign" as a move
                                    game.getLength()-1,
                                    game.getElapsed("black"),
                                    game.getElapsed("white"),
                                    error, errorMessage)

        # save game
        gamePlayer.save(name + ".sgf", name, resultBlack, resultWhite)
        
        if error:
            print "Error: Game", gameIndex
            for p in (black, white):
                if p.isDead():
                    p.saveLog(name + ".log")
                    p.saveCommandLog(name + ".gtp")
                    break
        for program in [black, white]:
            try:
                program.sendCommand("quit");
            except Program.Died:
                pass
            
        return game