def play()

in pachi_py/pachi/tools/twogtp.py [0:0]


    def play(self, games, sgfbase):
        last_color = ""
        last_streak = 0
        game = GTP_game(self.white, self.black,
                        self.size, self.komi, self.handicap,
                        self.handicap_type, "")
        results = []
        for i in range(games):
            sgffilename = "%s%03d.sgf" % (sgfbase, i + 1)
            game.play(sgffilename)
            result = game.result()
            if result[0] == result[1]:
                print "Game %d: %s" % (i + 1, result[0])
            else:
                print "Game %d: %s %s" % (i + 1, result[0], result[1])

            if result[0][0] == last_color:
                last_streak += 1
            elif result[0][0] != "0":
                last_color = result[0][0]
                last_streak = 1

            if last_streak == self.streak_length:
                if last_color == "W":
                    self.handicap += 1
                    if self.handicap == 1:
                        self.handicap = 2
                    print "White wins too often. Increasing handicap to %d" \
                          % (self.handicap)
                else:   
                    if self.handicap > 0:
                        self.handicap -= 1
                        if self.handicap == 1:
                            self.handicap = 0
                        print "Black wins too often. Decreasing handicap to %d" \
                              % (self.handicap)
                    else:
                        self.handicap = 2
                        game.swap_players()
                        print "Black looks stronger than white. Swapping colors and setting handicap to 2"
                game.set_handicap(self.handicap)
                last_color = ""
                last_streak = 0
            results.append(result)
        cputime = game.cputime()
        game.quit()
        return results, cputime