Ejemplo n.º 1
0
    def policy_moves_cmd(self, args):
        if self.go_engine.random_simulation:
            #get legal moves
            first_moves = GoBoardUtil.generate_legal_moves(
                self.board, self.board.current_player)
            moves = []
            #convert points to formated
            for move in first_moves:
                #convert to coords
                temp = point_to_coord(move, self.board.size)
                #format version
                temp = format_point(temp)
                moves.append(temp)
            moves.sort()

            #reverse it
            new_moves = []
            column_letters = "ABCDEFGHJKLMNOPQRSTUVWXYZ"
            #put format to point
            for move in moves:
                temp = str(column_letters.find(move[0]) + 1)
                temp = coord_to_point(int(move[1]), int(temp), self.board.size)
                new_moves.append((temp))

            movelist = new_moves

            p = []
            for x in range(0, len(movelist)):
                p.append(round(float(1) / float(len(movelist)), 3))
        else:
            movelist, p = PatternUtil.pattern(self.board)

        result = ''
        for move in movelist:
            temp = point_to_coord(move, self.board.size)
            temp = format_point(temp)
            result += temp.lower() + " "
        for i in p:
            result += str(i) + " "

        try:
            if args[0] == "1":
                return movelist, p

        except:
            self.respond(result)
Ejemplo n.º 2
0
    def policy_moves_cmd(self, args):

        signal.signal(signal.SIGALRM, self.handler)  #added for timer
        signal.alarm(int(self.timel) - 10)  #added for timer
        print("timer start")
        try:
            movelist = GoBoardUtil.generate_legal_moves(
                self.board, self.board.current_player)
            if self.go_engine.random_simulation:
                """#get legal moves
                first_moves = GoBoardUtil.generate_legal_moves(self.board, self.board.current_player)
                moves =[]
                #convert points to formated
                for move in first_moves:
                    #convert to coords
                    temp = point_to_coord(move, self.board.size)
                    #format version
                    temp = format_point(temp)
                    moves.append(temp)
                moves.sort()

                #reverse it
                new_moves =[]
                column_letters = "ABCDEFGHJKLMNOPQRSTUVWXYZ"
                #put format to point
                for move in moves:
                    temp = str(column_letters.find(move[0])+1)
                    temp = coord_to_point(int(move[1]),int(temp), self.board.size)
                    new_moves.append((temp))

                movelist = new_moves"""

                p = []
                for x in range(0, len(movelist)):
                    p.append(round(float(1) / float(len(movelist)), 3))
            else:
                p = []
                for move in movelist:
                    p.append(PatternUtil.pattern(self.board, move))
                for y in range(0, len(p)):
                    p.append(round(float(p.pop()) / float(len(movelist)), 3))
            try:
                if args[0] == "1":
                    signal.alarm(0)
                    return movelist, p

            except:
                result = ''
                for move in movelist:
                    temp = point_to_coord(move, self.board.size)
                    temp = format_point(temp)
                    result += temp.lower() + " "
                for i in p:
                    result += str(i) + " "
                signal.alarm(0)
                self.respond(result)

        except TimeoutException:  #added for timer
            #give best we have
            if len(p) < len(movelist):
                for x in range(0, (len(movelist) - len(p))):
                    p.append(1.0)
            for y in range(0, len(p)):
                p.append(round(float(p.pop()) / float(len(movelist)), 3))
            signal.alarm(0)
            return movelist, p