示例#1
0
def emoPollingWorker(sharedObject):
    global running
    with Emotiv(display_output=True, verbose=False) as headset:
        while True:
            packet = headset.dequeue()
            if packet is not None:
                sharedObject["sensors"] = copy.deepCopy(packet.sensors)

            time.sleep(0.001)
示例#2
0
    def getLegalMoves(self):
        moves = []
        moves_ = []

        # logic:
        # for every empty square DESTINATION, see if move possible
        # for every opponent occupied square DESTINATION, see if attack possible

        for sqrDest in Common.squaresSan:
            moveTempl = ChessMove.ChessMove()
            moveTempl.player = self.activePlayer
            moveTempl.moveNum = int(self.fullMoveNum) / 2

            if self[sqrDest] == ' ':
                #print "trying to go to square %s" % sqrDest
                for pieceType in 'rnbpqk':
                    for sqrSource in self.getMoveSourceSquares(
                            sqrDest, pieceType):
                        move = copy.deepcopy(moveTempl)
                        move.san = '%s%s' % (pieceType, sqrDest)
                        move.canonical = '%s%s' % (sqrSource, sqrDest)
                        #print "(move) adding: %s" % str(move.canonical)
                        moves_.append(move)

            elif Common.coloredPieceToPlayer(
                    self[sqrDest]) == Common.togglePlayer(
                        self['activePlayer']):
                #print "trying to attack square %s" % sqrDest
                for pieceType in 'rnbpqk':
                    for sqrSource in self.getAttackingSquares(
                            sqrDest, pieceType):
                        move = copy.deepcopy(moveTempl)
                        move.san = '%s%s' % (pieceType, sqrDest)
                        move.canonical = '%s%s' % (sqrSource, sqrDest)
                        #print "%s is a capture!" % (move.canonical)
                        move.flags['CAPTURE'] = 1
                        #print "(attack) adding: %s" % str(move)
                        moves_.append(move)

        # filter out moves that result in self-check
        for move in moves_:
            m = re.match(r'^([a-h][1-8])([a-h][1-8])$', move.canonical)

            [sqrSource, sqrDest] = [m.group(1), m.group(2)]

            tempState = copy.deepCopy(boardMap)
            tempState[m.group(2)] = tempState[m.group(1)]
            tempState[m.group(1)] = ' '

            # if hypothetical board does not produce a king check
            if not tempState.isInCheck():
                moves.append(move)

        return moves
示例#3
0
 def getLegalMoves(self):
     moves = []
     moves_ = []
 
     # logic:
     # for every empty square DESTINATION, see if move possible
     # for every opponent occupied square DESTINATION, see if attack possible
 
     for sqrDest in Common.squaresSan:
         moveTempl = ChessMove.ChessMove()
         moveTempl.player = self.activePlayer
         moveTempl.moveNum = int(self.fullMoveNum)/2
 
         if self[sqrDest] == ' ':
             #print "trying to go to square %s" % sqrDest
             for pieceType in 'rnbpqk':
                 for sqrSource in self.getMoveSourceSquares(sqrDest, pieceType):
                     move = copy.deepcopy(moveTempl)
                     move.san = '%s%s' % (pieceType, sqrDest)
                     move.canonical = '%s%s' % (sqrSource, sqrDest)
                     #print "(move) adding: %s" % str(move.canonical)
                     moves_.append(move)
 
         elif Common.coloredPieceToPlayer(self[sqrDest]) == Common.togglePlayer(self['activePlayer']):
             #print "trying to attack square %s" % sqrDest
             for pieceType in 'rnbpqk':
                 for sqrSource in self.getAttackingSquares(sqrDest, pieceType):
                     move = copy.deepcopy(moveTempl)
                     move.san = '%s%s' % (pieceType, sqrDest)
                     move.canonical = '%s%s' % (sqrSource, sqrDest)
                     #print "%s is a capture!" % (move.canonical)
                     move.flags['CAPTURE'] = 1
                     #print "(attack) adding: %s" % str(move)
                     moves_.append(move)
 
     # filter out moves that result in self-check
     for move in moves_:
         m = re.match(r'^([a-h][1-8])([a-h][1-8])$', move.canonical)
 
         [sqrSource, sqrDest] = [m.group(1), m.group(2)]
 
         tempState = copy.deepCopy(boardMap)
         tempState[m.group(2)] = tempState[m.group(1)]
         tempState[m.group(1)] = ' '
 
         # if hypothetical board does not produce a king check
         if not tempState.isInCheck():
             moves.append(move)
 
     return moves
示例#4
0
    def __init__(self, m, dicts, share=False):

        super(MultiCloneModule, self).__init__()

        self.moduleList = nn.ModuleList()
        self.moduleList.append(m)

        for i in range(1, len(dicts)):
            clone = copy.deepCopy(m)

            if share:
                clone.weight = m.weight

            self.moduleList.append(clone)

        self.currentID = 0
示例#5
0
def visit(adjMatrix, x, xColor, rCount, bCount, currColorCnt, threshold, ucityList, pathSoFar, pathLength):
    "Returns ONE tuple of (weight, [totalPath])"
    #rCount is the number of Reds total so far
    #bCount is the number of Blues total so far
    #pathLength is the sum of the weights of edges so far
    if sum >= threshold:
        return [float("inf"), None]
    possiblePaths = []
    ucityList[x] = -1
    # legalNeighbors returns a list of VERTICES able to be visited
    for v in legalNeighbors(x, xColor, currColorCnt, rCount, bCount, ucityList, adjMatrix, colorArray, pathSoFar):
        pathSoFarCopy = copy.deepCopy(pathSoFar)
        lmao = visit(adjMatrix, v, threshold, ucityList, pathLength + adjMatrix[x][v])
        theWeight = lmao[0]
        thePath = pathSoFarCopy.extend(lmao[1])
        possiblePaths.append([theWeight, thePath])

    res = min(possiblePaths, cmp=lambda x, y: cmp(x[0], y[0]))
    return res
示例#6
0
def MoveDown(VisitedFirst):
    global inpu
    currentPos = [0, 0]
    Visited = copy.deepcopy(VisitedFirst)
    Visited[0][0] = True
    while 1:
        if (currentPos[0] == inpu[0] - 1
                and currentPos[1] == inpu[1] - 1):  # 끝에 도착할 경우
            if False in Visited:
                currentPos[0] = 0
                currentPos[1] = 0
                Visited = copy.deepCopy(VisitedFirst)
                Visited[0][0] = True
            else:
                return

        if (currentPos[0] == 0):
            if (Visited[currentPos[0] + 1][currentPos[1]] == True):
                print("R")
                Visited[currentPos[0]][currentPos[1]] = True
                currentPos[1] = currentPos[1] + 1
            elif (Visited[currentPos[0] + 1][currentPos[1]] == False):
                print("D")
                Visited[currentPos[0]][currentPos[1]] = True
                currentPos[0] = currentPos[0] + 1
        elif (currentPos[0] == inpu[0] - 1):
            if (Visited[currentPos[0] - 1][currentPos[1]] == True):
                print("R")
                Visited[currentPos[0]][currentPos[1]] = True
                currentPos[1] = currentPos[1] + 1
            elif (Visited[currentPos[0] - 1][currentPos[1]] == False):
                print("U")
                Visited[currentPos[0]][currentPos[1]] = True
                currentPos[0] = currentPos[0] - 1
        else:
            if (Visited[currentPos[0] - 1][currentPos[1]] == True):
                Visited[currentPos[0]][currentPos[1]] = True
                currentPos[0] = currentPos[0] + 1
                print("D")
            elif (Visited[currentPos[0] + 1][currentPos[1]] == True):
                Visited[currentPos[0]][currentPos[1]] = True
                currentPos[0] = currentPos[0] - 1
                print("U")
    def arc_consistency_check(self, var):
        """
        Perform the AC-3 algorithm. The goal is to reduce the size of the
        domain values for the unassigned variables based on arc consistency.

        @param var: The variable whose value has just been set.

        While not required, you can also choose to add return values in this
        function if there's a need.
        """
        # BEGIN_YOUR_CODE (around 17 lines of code expected)
        q = queue.Queue()
        q.put(var)
        while !q.empty():
            var = q.get()
            newdomains = copy.deepCopy(self.domains) 
            for neighbor in xrange(len(self.domains)):
                newdomain = enforce_arc_consistency(neighbor, targetvar)
                newdomains[neighbor] = newdomain
        raise Exception("Not implemented yet")
示例#8
0
def visit(adjMatrix, x, xColor, rCount, bCount, currColorCnt, threshold,
          ucityList, pathSoFar, pathLength):
    "Returns ONE tuple of (weight, [totalPath])"
    #rCount is the number of Reds total so far
    #bCount is the number of Blues total so far
    #pathLength is the sum of the weights of edges so far
    if sum >= threshold:
        return [float("inf"), None]
    possiblePaths = []
    ucityList[x] = -1
    # legalNeighbors returns a list of VERTICES able to be visited
    for v in legalNeighbors(x, xColor, currColorCnt, rCount, bCount, ucityList,
                            adjMatrix, colorArray, pathSoFar):
        pathSoFarCopy = copy.deepCopy(pathSoFar)
        lmao = visit(adjMatrix, v, threshold, ucityList,
                     pathLength + adjMatrix[x][v])
        theWeight = lmao[0]
        thePath = pathSoFarCopy.extend(lmao[1])
        possiblePaths.append([theWeight, thePath])

    res = min(possiblePaths, cmp=lambda x, y: cmp(x[0], y[0]))
    return res
示例#9
0
 def copyStyles(self):
     return copy.deepCopy(self.styles)
 def enforce_arc_consistencies(self, targetvar):
     newdomains = copy.deepCopy(self.domains) 
     for neighbor in xrange(len(self.domains)):
         newdomain = enforce_arc_consistency(neighbor, targetvar)
         newdomains[neighbor] = newdomain
     return newdomains
示例#11
0
 def __deepCopy__(self):
     s = State()
     s.tiles = copy.deepCopy(self.tiles)
     s.players = copy.deepCopy(self.players)
     s.dragons = copy.deepCopy(self.dragons)
     return s