예제 #1
0
 def get_shuffled_deck(self):
     deck = []
     for suit in ['C', 'D', 'H', 'S']:
         for i in range(1, 14):
             deck.append(new_eleusis.number_to_value(i) + suit)
     random.shuffle(deck)
     return deck
def get_random_card():
    """
    Select random card from a standard 52 card deck
    :return:
    """
    suits = ['C', 'D', 'H', 'S']
    suit = suits[random.randrange(4)]
    val = random.randrange(1, 14)
    return ne.number_to_value(val) + suit
def get_shuffled_deck():
    """
    Create and return a shuffled deck of cards
    :return:
    """
    deck = []
    for suit in ['C', 'D', 'H', 'S']:
        for i in range(1, 14):
            deck.append(ne.number_to_value(i) + suit)

    random.shuffle(deck)
    return deck
예제 #4
0
    def __init__(self, prevCards,
                 godrule):  # prevCards = cards on table so far
        self.prevCards = prevCards
        prevString = str(prevCards).strip('[]')
        for i in range(1, 14, 1):
            for s in ['C', 'D', 'H', 'S']:
                v = new_eleusis.number_to_value(i)
                card = v + s
                self.cardsToPlay.append(card)

        self.setRule(godrule)
        if self.current_domain == 3:
            self.possibleRules = self.forward_checking(
                build_domain(True, True, True))
        else:
            self.possibleRules = self.forward_checking(build_domain(True))
        self.pickRule()
예제 #5
0
    def random_card_old(self, value=None, suit=None):
        i = randint(1, 13)
        s = choice('CDHS')
        if value is not None:
            i = choice(value)
        else:
            value = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
        if suit is not None:
            s = choice(suit)
        else:
            suit = ['C', 'H', 'D', 'S']

        v = new_eleusis.number_to_value(i)
        card = v + s
        s = self.prevCards
        while card in str(s).strip('[]') and len(
                self.prevCards) < len(value) * len(suit):
            card = self.random_card(value, suit)

        return card
예제 #6
0
def generateTrainingData(boardState):
    attributeTable = []
    keysinBS = []
    valuesinBS = []
    for item in boardState:
        keysinBS.extend(list(item.keys()))
        valuesinBS.extend(list(item.values()))
    i = 2
    dict = {}
    for i in range(2, len(keysinBS)):
        # 'card':keysinBS[i],
        dict = {
            'suitCur':
            func.suit(keysinBS[i]),
            'suitLsDCur':
            func.less(func.suit(keysinBS[i]), func.suit('D')),
            'suitLsHCur':
            func.less(func.suit(keysinBS[i]), func.suit('H')),
            'suitLsSCur':
            func.less(func.suit(keysinBS[i]), func.suit('S')),
            'suitGrCCur':
            func.greater(func.suit(keysinBS[i]), func.suit('C')),
            'suitGrDCur':
            func.greater(func.suit(keysinBS[i]), func.suit('D')),
            'suitGrHCur':
            func.greater(func.suit(keysinBS[i]), func.suit('H')),
            'colorCur':
            func.color(keysinBS[i]),
            'royalCur':
            func.is_royal(keysinBS[i]),
            'valueEvenCur':
            func.even(keysinBS[i]),
            'valueEq1Cur':
            func.equal(func.value(keysinBS[i]), '1'),
            'valueEq2Cur':
            func.equal(func.value(keysinBS[i]), '2'),
            'valueEq3Cur':
            func.equal(func.value(keysinBS[i]), '3'),
            'valueEq4Cur':
            func.equal(func.value(keysinBS[i]), '4'),
            'valueEq5Cur':
            func.equal(func.value(keysinBS[i]), '5'),
            'valueEq6Cur':
            func.equal(func.value(keysinBS[i]), '6'),
            'valueEq7Cur':
            func.equal(func.value(keysinBS[i]), '7'),
            'valueEq8Cur':
            func.equal(func.value(keysinBS[i]), '8'),
            'valueEq9Cur':
            func.equal(func.value(keysinBS[i]), '9'),
            'valueEq10Cur':
            func.equal(func.value(keysinBS[i]), '10'),
            'valueEq11Cur':
            func.equal(func.value(keysinBS[i]), '11'),
            'valueEq12Cur':
            func.equal(func.value(keysinBS[i]), '12'),
            'valueEq13Cur':
            func.equal(func.value(keysinBS[i]), '13'),
            'valueGr1Cur':
            func.greater(str(func.number_to_value(func.value(keysinBS[i]))),
                         'A'),
            'valueGr2Cur':
            func.greater(str(func.number_to_value(func.value(keysinBS[i]))),
                         '2'),
            'valueGr3Cur':
            func.greater(str(func.number_to_value(func.value(keysinBS[i]))),
                         '3'),
            'valueGr4Cur':
            func.greater(str(func.number_to_value(func.value(keysinBS[i]))),
                         '4'),
            'valueGr5Cur':
            func.greater(str(func.number_to_value(func.value(keysinBS[i]))),
                         '5'),
            'valueGr6Cur':
            func.greater(str(func.number_to_value(func.value(keysinBS[i]))),
                         '6'),
            'valueGr7Cur':
            func.greater(str(func.number_to_value(func.value(keysinBS[i]))),
                         '7'),
            'valueGr8Cur':
            func.greater(str(func.number_to_value(func.value(keysinBS[i]))),
                         '8'),
            'valueGr9Cur':
            func.greater(str(func.number_to_value(func.value(keysinBS[i]))),
                         '9'),
            'valueGr10Cur':
            func.greater(str(func.number_to_value(func.value(keysinBS[i]))),
                         '10'),
            'valueGr11Cur':
            func.greater(str(func.number_to_value(func.value(keysinBS[i]))),
                         'J'),
            'valueGr12Cur':
            func.greater(str(func.number_to_value(func.value(keysinBS[i]))),
                         'Q'),
            'valueLs2Cur':
            func.less(str(func.number_to_value(func.value(keysinBS[i]))), '2'),
            'valueLs3Cur':
            func.less(str(func.number_to_value(func.value(keysinBS[i]))), '3'),
            'valueLs4Cur':
            func.less(str(func.number_to_value(func.value(keysinBS[i]))), '4'),
            'valueLs5Cur':
            func.less(str(func.number_to_value(func.value(keysinBS[i]))), '5'),
            'valueLs6Cur':
            func.less(str(func.number_to_value(func.value(keysinBS[i]))), '6'),
            'valueLs7Cur':
            func.less(str(func.number_to_value(func.value(keysinBS[i]))), '7'),
            'valueLs8Cur':
            func.less(str(func.number_to_value(func.value(keysinBS[i]))), '8'),
            'valueLs9Cur':
            func.less(str(func.number_to_value(func.value(keysinBS[i]))), '9'),
            'valueLs10Cur':
            func.less(str(func.number_to_value(func.value(keysinBS[i]))),
                      '10'),
            'valueLs11Cur':
            func.less(str(func.number_to_value(func.value(keysinBS[i]))), 'J'),
            'valueLs12Cur':
            func.less(str(func.number_to_value(func.value(keysinBS[i]))), 'Q'),
            'valueLs13Cur':
            func.less(str(func.number_to_value(func.value(keysinBS[i]))), 'K'),
            'suitPrev':
            func.suit(keysinBS[i - 1]),
            'suitLsDPrev':
            func.less(func.suit(keysinBS[i - 1]), func.suit('D')),
            'suitLsHPrev':
            func.less(func.suit(keysinBS[i - 1]), func.suit('H')),
            'suitLsSPrev':
            func.less(func.suit(keysinBS[i - 1]), func.suit('S')),
            'suitGrCPrev':
            func.greater(func.suit(keysinBS[i - 1]), func.suit('C')),
            'suitGrDPrev':
            func.greater(func.suit(keysinBS[i - 1]), func.suit('D')),
            'suitGrHPrev':
            func.greater(func.suit(keysinBS[i - 1]), func.suit('H')),
            'colorPrev':
            func.color(keysinBS[i - 1]),
            'royalPrev':
            func.is_royal(keysinBS[i - 1]),
            'valueEvenPrev':
            func.even(keysinBS[i - 1]),
            'valueEq1Prev':
            func.equal(func.value(keysinBS[i - 1]), '1'),
            'valueEq2Prev':
            func.equal(func.value(keysinBS[i - 1]), '2'),
            'valueEq3Prev':
            func.equal(func.value(keysinBS[i - 1]), '3'),
            'valueEq4Prev':
            func.equal(func.value(keysinBS[i - 1]), '4'),
            'valueEq5Prev':
            func.equal(func.value(keysinBS[i - 1]), '5'),
            'valueEq6Prev':
            func.equal(func.value(keysinBS[i - 1]), '6'),
            'valueEq7Prev':
            func.equal(func.value(keysinBS[i - 1]), '7'),
            'valueEq8Prev':
            func.equal(func.value(keysinBS[i - 1]), '8'),
            'valueEq9Prev':
            func.equal(func.value(keysinBS[i - 1]), '9'),
            'valueEq10Prev':
            func.equal(func.value(keysinBS[i - 1]), '10'),
            'valueEq11Prev':
            func.equal(func.value(keysinBS[i - 1]), '11'),
            'valueEq12Prev':
            func.equal(func.value(keysinBS[i - 1]), '12'),
            'valueEq13Prev':
            func.equal(func.value(keysinBS[i - 1]), '13'),
            'valueGr1Prev':
            func.greater(
                str(func.number_to_value(func.value(keysinBS[i - 1]))), 'A'),
            'valueGr2Prev':
            func.greater(
                str(func.number_to_value(func.value(keysinBS[i - 1]))), '2'),
            'valueGr3Prev':
            func.greater(
                str(func.number_to_value(func.value(keysinBS[i - 1]))), '3'),
            'valueGr4Prev':
            func.greater(
                str(func.number_to_value(func.value(keysinBS[i - 1]))), '4'),
            'valueGr5Prev':
            func.greater(
                str(func.number_to_value(func.value(keysinBS[i - 1]))), '5'),
            'valueGr6Prev':
            func.greater(
                str(func.number_to_value(func.value(keysinBS[i - 1]))), '6'),
            'valueGr7Prev':
            func.greater(
                str(func.number_to_value(func.value(keysinBS[i - 1]))), '7'),
            'valueGr8Prev':
            func.greater(
                str(func.number_to_value(func.value(keysinBS[i - 1]))), '8'),
            'valueGr9Prev':
            func.greater(
                str(func.number_to_value(func.value(keysinBS[i - 1]))), '9'),
            'valueGr10Prev':
            func.greater(
                str(func.number_to_value(func.value(keysinBS[i - 1]))), '10'),
            'valueGr11Prev':
            func.greater(
                str(func.number_to_value(func.value(keysinBS[i - 1]))), 'J'),
            'valueGr12Prev':
            func.greater(
                str(func.number_to_value(func.value(keysinBS[i - 1]))), 'Q'),
            'valueLs2Prev':
            func.less(str(func.number_to_value(func.value(keysinBS[i - 1]))),
                      '2'),
            'valueLs3Prev':
            func.less(str(func.number_to_value(func.value(keysinBS[i - 1]))),
                      '3'),
            'valueLs4Prev':
            func.less(str(func.number_to_value(func.value(keysinBS[i - 1]))),
                      '4'),
            'valueLs5Prev':
            func.less(str(func.number_to_value(func.value(keysinBS[i - 1]))),
                      '5'),
            'valueLs6Prev':
            func.less(str(func.number_to_value(func.value(keysinBS[i - 1]))),
                      '6'),
            'valueLs7Prev':
            func.less(str(func.number_to_value(func.value(keysinBS[i - 1]))),
                      '7'),
            'valueLs8Prev':
            func.less(str(func.number_to_value(func.value(keysinBS[i - 1]))),
                      '8'),
            'valueLs9Prev':
            func.less(str(func.number_to_value(func.value(keysinBS[i - 1]))),
                      '9'),
            'valueLs10Prev':
            func.less(str(func.number_to_value(func.value(keysinBS[i - 1]))),
                      '10'),
            'valueLs11Prev':
            func.less(str(func.number_to_value(func.value(keysinBS[i - 1]))),
                      'J'),
            'valueLs12Prev':
            func.less(str(func.number_to_value(func.value(keysinBS[i - 1]))),
                      'Q'),
            'valueLs13Prev':
            func.less(str(func.number_to_value(func.value(keysinBS[i - 1]))),
                      'K'),
            'suitPrev2':
            func.suit(keysinBS[i - 2]),
            'suitLsDPrev2':
            func.less(func.suit(keysinBS[i - 2]), func.suit('D')),
            'suitLsHPrev2':
            func.less(func.suit(keysinBS[i - 2]), func.suit('H')),
            'suitLsSPrev2':
            func.less(func.suit(keysinBS[i - 2]), func.suit('S')),
            'suitGrCPrev2':
            func.greater(func.suit(keysinBS[i - 2]), func.suit('C')),
            'suitGrDPrev2':
            func.greater(func.suit(keysinBS[i - 2]), func.suit('D')),
            'suitGrHPrev2':
            func.greater(func.suit(keysinBS[i - 2]), func.suit('H')),
            'colorPrev2':
            func.color(keysinBS[i - 2]),
            'royalPrev2':
            func.is_royal(keysinBS[i - 2]),
            'valueEvenPrev2':
            func.even(keysinBS[i - 2]),
            'valueEq1Prev2':
            func.equal(func.value(keysinBS[i - 2]), '1'),
            'valueEq2Prev2':
            func.equal(func.value(keysinBS[i - 2]), '2'),
            'valueEq3Prev2':
            func.equal(func.value(keysinBS[i - 2]), '3'),
            'valueEq4Prev2':
            func.equal(func.value(keysinBS[i - 2]), '4'),
            'valueEq5Prev2':
            func.equal(func.value(keysinBS[i - 2]), '5'),
            'valueEq6Prev2':
            func.equal(func.value(keysinBS[i - 2]), '6'),
            'valueEq7Prev2':
            func.equal(func.value(keysinBS[i - 2]), '7'),
            'valueEq8Prev2':
            func.equal(func.value(keysinBS[i - 2]), '8'),
            'valueEq9Prev2':
            func.equal(func.value(keysinBS[i - 2]), '9'),
            'valueEq10Prev2':
            func.equal(func.value(keysinBS[i - 2]), '10'),
            'valueEq11Prev2':
            func.equal(func.value(keysinBS[i - 2]), '11'),
            'valueEq12Prev2':
            func.equal(func.value(keysinBS[i - 2]), '12'),
            'valueEq13Prev2':
            func.equal(func.value(keysinBS[i - 2]), '13'),
            'valueGr1Prev2':
            func.greater(
                str(func.number_to_value(func.value(keysinBS[i - 2]))), 'A'),
            'valueGr2Prev2':
            func.greater(
                str(func.number_to_value(func.value(keysinBS[i - 2]))), '2'),
            'valueGr3Prev2':
            func.greater(
                str(func.number_to_value(func.value(keysinBS[i - 2]))), '3'),
            'valueGr4Prev2':
            func.greater(
                str(func.number_to_value(func.value(keysinBS[i - 2]))), '4'),
            'valueGr5Prev2':
            func.greater(
                str(func.number_to_value(func.value(keysinBS[i - 2]))), '5'),
            'valueGr6Prev2':
            func.greater(
                str(func.number_to_value(func.value(keysinBS[i - 2]))), '6'),
            'valueGr7Prev2':
            func.greater(
                str(func.number_to_value(func.value(keysinBS[i - 2]))), '7'),
            'valueGr8Prev2':
            func.greater(
                str(func.number_to_value(func.value(keysinBS[i - 2]))), '8'),
            'valueGr9Prev2':
            func.greater(
                str(func.number_to_value(func.value(keysinBS[i - 2]))), '9'),
            'valueGr10Prev2':
            func.greater(
                str(func.number_to_value(func.value(keysinBS[i - 2]))), '10'),
            'valueGr11Prev2':
            func.greater(
                str(func.number_to_value(func.value(keysinBS[i - 2]))), 'J'),
            'valueGr12Prev2':
            func.greater(
                str(func.number_to_value(func.value(keysinBS[i - 2]))), 'Q'),
            'valueLs2Prev2':
            func.less(str(func.number_to_value(func.value(keysinBS[i - 2]))),
                      '2'),
            'valueLs3Prev2':
            func.less(str(func.number_to_value(func.value(keysinBS[i - 2]))),
                      '3'),
            'valueLs4Prev2':
            func.less(str(func.number_to_value(func.value(keysinBS[i - 2]))),
                      '4'),
            'valueLs5Prev2':
            func.less(str(func.number_to_value(func.value(keysinBS[i - 2]))),
                      '5'),
            'valueLs6Prev2':
            func.less(str(func.number_to_value(func.value(keysinBS[i - 2]))),
                      '6'),
            'valueLs7Prev2':
            func.less(str(func.number_to_value(func.value(keysinBS[i - 2]))),
                      '7'),
            'valueLs8Prev2':
            func.less(str(func.number_to_value(func.value(keysinBS[i - 2]))),
                      '8'),
            'valueLs9Prev2':
            func.less(str(func.number_to_value(func.value(keysinBS[i - 2]))),
                      '9'),
            'valueLs10Prev2':
            func.less(str(func.number_to_value(func.value(keysinBS[i - 2]))),
                      '10'),
            'valueLs11Prev2':
            func.less(str(func.number_to_value(func.value(keysinBS[i - 2]))),
                      'J'),
            'valueLs12Prev2':
            func.less(str(func.number_to_value(func.value(keysinBS[i - 2]))),
                      'Q'),
            'valueLs13Prev2':
            func.less(str(func.number_to_value(func.value(keysinBS[i - 2]))),
                      'K'),
            'suitCurLsPrev':
            func.less(func.suit(keysinBS[i]), func.suit(keysinBS[i - 1])),
            'suitCurGrPrev':
            func.greater(func.suit(keysinBS[i]), func.suit(keysinBS[i - 1])),
            'suitCurEqPrev':
            func.equal(func.suit(keysinBS[i]), func.suit(keysinBS[i - 1])),
            'valueCurLsPrev':
            func.less(str(func.number_to_value(func.value(keysinBS[i]))),
                      str(func.number_to_value(func.value(keysinBS[i - 1])))),
            'valueCurGrPrev':
            func.greater(
                str(func.number_to_value(func.value(keysinBS[i]))),
                str(func.number_to_value(func.value(keysinBS[i - 1])))),
            'valueCurEqPrev':
            func.equal(str(func.number_to_value(func.value(keysinBS[i]))),
                       str(func.number_to_value(func.value(keysinBS[i - 1])))),
            'colorCurLsPrev':
            func.less(func.color(keysinBS[i]), func.color(keysinBS[i - 1])),
            'colorCurGrPrev':
            func.greater(func.color(keysinBS[i]), func.color(keysinBS[i - 1])),
            'colorCurEqPrev':
            func.equal(func.color(keysinBS[i]), func.color(keysinBS[i - 1])),
            'suitPrevLsPrev2':
            func.less(func.suit(keysinBS[i - 1]), func.suit(keysinBS[i - 2])),
            'suitPrevGrPrev2':
            func.greater(func.suit(keysinBS[i - 1]),
                         func.suit(keysinBS[i - 2])),
            'suitPrevEqPrev2':
            func.equal(func.suit(keysinBS[i - 1]), func.suit(keysinBS[i - 2])),
            'valuePrevLsPrev2':
            func.less(str(func.number_to_value(func.value(keysinBS[i - 1]))),
                      str(func.number_to_value(func.value(keysinBS[i - 2])))),
            'valuePrevGrPrev2':
            func.greater(
                str(func.number_to_value(func.value(keysinBS[i - 1]))),
                str(func.number_to_value(func.value(keysinBS[i - 2])))),
            'valuePrevEqPrev2':
            func.equal(str(func.number_to_value(func.value(keysinBS[i - 1]))),
                       str(func.number_to_value(func.value(keysinBS[i - 2])))),
            'colorPrevLsPrev2':
            func.less(func.color(keysinBS[i - 1]),
                      func.color(keysinBS[i - 2])),
            'colorPrevGrPrev2':
            func.greater(func.color(keysinBS[i - 1]),
                         func.color(keysinBS[i - 2])),
            'colorPrevEqPrev2':
            func.equal(func.color(keysinBS[i - 1]),
                       func.color(keysinBS[i - 2])),
            'suitPrev2LsCur':
            func.less(func.suit(keysinBS[i - 2]), func.suit(keysinBS[i])),
            'suitPrev2GrCur':
            func.greater(func.suit(keysinBS[i - 2]), func.suit(keysinBS[i])),
            'suitPrev2EqCur':
            func.equal(func.suit(keysinBS[i - 2]), func.suit(keysinBS[i])),
            'valuePrev2LsCur':
            func.less(str(func.number_to_value(func.value(keysinBS[i - 2]))),
                      str(func.number_to_value(func.value(keysinBS[i])))),
            'valuePrev2GrCur':
            func.greater(
                str(func.number_to_value(func.value(keysinBS[i - 2]))),
                str(func.number_to_value(func.value(keysinBS[i])))),
            'valuePrev2EqCur':
            func.equal(str(func.number_to_value(func.value(keysinBS[i - 2]))),
                       str(func.number_to_value(func.value(keysinBS[i])))),
            'colorPrev2LsCur':
            func.less(func.color(keysinBS[i - 2]), func.color(keysinBS[i])),
            'colorPrev2GrCur':
            func.greater(func.color(keysinBS[i - 2]), func.color(keysinBS[i])),
            'colorPrev2EqCur':
            func.equal(func.color(keysinBS[i - 2]), func.color(keysinBS[i])),
            'classification':
            valuesinBS[i]
        }
        attributeTable.append(dict)
    return attributeTable