Example #1
0
File: gogame.py Project: ojii/Spayc
    def serve(self):
        #avoid the "new room quick message" bug
        sleep(.5)

        p("serving game!")

        self.gnugo = Gnugo()

        sz = False
        while not sz:
            sz = self.get_int(
                "What boardsize would you like? (Must be between 3 and 19, default is 19):",
                3, 19, 19)
        self.gnugo.command("boardsize", sz)

        handicap = False
        while not handicap:
            handicap = self.get_int(
                "What handicap would you like? (Must be between 0 and 12, default is 0):",
                0, 12, 0)
        if handicap > 0:
            self.gnugo.command("fixed_handicap", handicap)

        self.showboard()

        if handicap == 0:
            self.get_human_move("black")
        else:
            self.white = Serve.HUMAN
            self.black = Serve.COMPUTER

        #now black will have played, either via handicap or the previous command,
        #so white will go next.
        while self.gamestate != Serve.FINISHED:
            if self.white == Serve.HUMAN:
                self.get_human_move("white")
            else:
                self.get_computer_move("white")

            if self.gamestate == Serve.FINISHED: break

            if self.black == Serve.HUMAN:
                self.get_human_move("black")
            else:
                self.get_computer_move("black")

        score = self.gnugo.command("final_score").split()[1]
        self.send("Final Score: %s" % score)