Esempio n. 1
0
File: card.py Progetto: halexus/Uno
 def __str__(self):
     colStr = color.toString(self.col)
     value = self.val
     if self.val == Card.WILD:
         value = '(Wild)'
     elif self.val == Card.WILDDRAW4:
         value = '(Wild draw 4)'
     elif self.val == Card.DRAW2:
         value = '+2'
     elif self.val == Card.REVERSE:
         value = 'reverse'
     elif self.val == Card.SKIP:
         value = "skip"
     return '%s %s%s%s' % (colStr, value, colorama.Style.DIM, colorama.Fore.BLACK)
Esempio n. 2
0
File: card.py Progetto: halexus/Uno
 def __str__(self):
     colStr = color.toString(self.col)
     value = self.val
     if self.val == Card.WILD:
         value = '(Wild)'
     elif self.val == Card.WILDDRAW4:
         value = '(Wild draw 4)'
     elif self.val == Card.DRAW2:
         value = '+2'
     elif self.val == Card.REVERSE:
         value = 'reverse'
     elif self.val == Card.SKIP:
         value = "skip"
     return '%s %s%s%s' % (colStr, value, colorama.Style.DIM,
                           colorama.Fore.BLACK)
Esempio n. 3
0
 def putCard(self, card, player):
     self.pile.append(card)
     """If a black card was put on discard pile ask for new color
     and add a card with that color and respective value on pile"""
     if card.getColor() == color.BLACK:
         if not player.isKi(): #ki == False
             for i in range(4):
                 print('%d: %s%s%s' % (i + 1, color.toString(i), colorama.Fore.BLACK, colorama.Style.DIM))
             newColor = None
             while newColor == None:
                 try:
                     newColor = int(input('Choose Color: ')) - 1
                     if newColor not in range(4):
                         print('Number must be in range 1-4')
                         newColor = None 
                 except ValueError:
                     print('Number must be in range 1-4')
         else: #ki == True
             #newColor = randint(0,3)
             newColor = player.getHand().mostFrequentColor()
         card = Card(newColor, card.getValue())
         self.pile.append(card)
Esempio n. 4
0
 def putCard(self, card, player):
     self.pile.append(card)
     """If a black card was put on discard pile ask for new color
     and add a card with that color and respective value on pile"""
     if card.getColor() == color.BLACK:
         if not player.isKi():  #ki == False
             for i in range(4):
                 print('%d: %s%s%s' %
                       (i + 1, color.toString(i), colorama.Fore.BLACK,
                        colorama.Style.DIM))
             newColor = None
             while newColor == None:
                 try:
                     newColor = int(input('Choose Color: ')) - 1
                     if newColor not in range(4):
                         print('Number must be in range 1-4')
                         newColor = None
                 except ValueError:
                     print('Number must be in range 1-4')
         else:  #ki == True
             #newColor = randint(0,3)
             newColor = player.getHand().mostFrequentColor()
         card = Card(newColor, card.getValue())
         self.pile.append(card)
Esempio n. 5
0
        else:
            return self.cards[i]
        
    def addCard(self, card):
        self.cards.append(card)
        
    def mostFrequentColor(self):
        freq={color.BLUE: 0, color.GREEN: 0, color.RED: 0, color.YELLOW: 0}
        for card in self.cards:
            if card.getColor() != color.BLACK:
                freq[card.getColor()] += 1
        freqView = freq.items()
        freqView = sorted(freqView, key = lambda x: x[1])
        return freqView[-1][0]

    def __str__(self):
        #cardsStr = [str(card) for card in self.cards]
        cardsStr = ['%2d: %s' % ( index + 1, card) for index, card in enumerate(self.cards)]
        #return ', '.join(cardsStr) 
        return '\n'.join(cardsStr)
    
if __name__ == '__main__': #TEST
    from discardpile import Discardpile
    from deck import Deck
    discardPile = Discardpile() #Build the initial (empty) discard pile
    deck = Deck(discardPile) #Build a deck with 108 cards
    h = Hand(deck)
    print(h)
    print(color.toString(h.mostFrequentColor()))
        
Esempio n. 6
0
# ******************************************************************
# ******************************************************************
    print('Start mainloop.')
    while True:
        frame = fr.getFrame(video, resolution=RESOLUTION, imshow=False)
        if frame is None:
            break

        key = cv2.waitKey(1)
        if key == 27:  # ESC
            break

        cut = fr.printCursor(frame, radius=4, color=(0, 255, 255))

        cut_hsv = cv2.cvtColor(cut, cv2.COLOR_BGR2HSV)
        h, s, v = color.pickColor(cut_hsv)
        cref = color.pixColorRef([h, s, v])
        print("%4d %4d %4d %10s" % (h, s, v, color.toString(cref)))

        cv2.imshow('CUT', cv2.resize(cut, (RESOLUTION[1], RESOLUTION[1])))
        cv2.imshow('FRAME', frame)
        cv2.imshow('MASK', color.colorMask(frame,
                                           color.YELLOW,
                                           useFilter=False))

cv2.destroyAllWindows()
print('Exit program')
# ******************************************************************
# ******************************************************************
# ******************************************************************