def color_greater(card1, card2): """ return if color of card1 is greater than color of card2 :param card1: :param card2: :return: """ return ne.greater(ne.color(card1), ne.color(card2))
def color_less(card1, card2): """ return if color of card1 is less than color of card2 :param card1: :param card2: :return: """ return ne.less(ne.color(card1), ne.color(card2))
def cardProperties(card): # to do : add more properties return { 'suit': new_eleusis.suit(card), 'value': new_eleusis.value(card), 'color': new_eleusis.color(card) }
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
def populate_attribute(attributes, curr, prev, prev2, result, decision): cards = [curr, prev, prev2] cards_names = ["current", 'previous', 'previous2'] function_names = ["even", "is_royal"] functions = [new_eleusis.even, new_eleusis.is_royal, new_eleusis.odd] for card, card_name in zip(cards, cards_names): for func_names, func in zip(function_names, functions): attributes[func_names + "(" + str(card_name) + ")"].append( func(card)) function_names_two = ['equal', 'less', 'greater'] functions_two = [new_eleusis.equal, new_eleusis.less, new_eleusis.greater] suit = ['C', 'D', 'H', 'S'] color = ['B', 'R'] for i in range(len(cards)): for func_two, func_name_two in zip(functions_two, function_names_two): #for suit for s in suit: if func_name_two == 'equal': attributes[func_name_two + "(suit(" + cards_names[i] + ")," + s + ")"].append( func_two(new_eleusis.suit(cards[i]), s)) elif func_name_two == 'less': if s != 'C': attributes[func_name_two + "(suit(" + cards_names[i] + ")," + s + ")"].append( func_two(new_eleusis.suit(cards[i]), s)) elif func_name_two == 'greater': if s != 'S': attributes[func_name_two + "(suit(" + cards_names[i] + ")," + s + ")"].append( func_two(new_eleusis.suit(cards[i]), s)) for c in color: if func_name_two == 'equal': attributes[func_name_two + "(color(" + cards_names[i] + ")," + c + ")"].append( func_two(new_eleusis.color(cards[i]), c)) ''' Attributes with both arguments as functions ''' for i in range(len(cards) - 1): for j in range(i + 1, len(cards)): for func_two, func_name_two in zip(functions_two, function_names_two): attributes[func_name_two + "(color(" + cards_names[i] + "),color(" + cards_names[j] + "))"].append( func_two(new_eleusis.color(cards[i]), new_eleusis.color(cards[j]))) attributes[func_name_two + "(suit(" + cards_names[i] + "),suit(" + cards_names[j] + "))"].append( func_two(new_eleusis.suit(cards[i]), new_eleusis.suit(cards[j]))) attributes[func_name_two + "(value(" + cards_names[i] + "),value(" + cards_names[j] + "))"].append( func_two(str(new_eleusis.value(cards[i])), str(new_eleusis.value(cards[j])))) result.append(decision) return attributes, result
def populate_attribute(attributes, curr, prev, prev2, valid): #single card attributes #color, even, suit, royal cards = [curr, prev, prev2] cards_names = ["current", 'prev', 'prev2'] function_names = ["color", "even", "suit", "is_royal", "odd"] functions = [ new_eleusis.color, new_eleusis.even, new_eleusis.suit, new_eleusis.is_royal, new_eleusis.odd ] for card, card_name in zip(cards, cards_names): for func_names, func in zip(function_names, functions): attributes[func_names + "('" + str(card_name) + "')"].append( func(card)) #value list values = range(1, 14) #suit list suits = ['C', 'D', 'H', 'S'] function_names_two = ['equal', 'less', 'greater'] functions_two = [new_eleusis.equal, new_eleusis.less, new_eleusis.greater] #double card attributes for card, card_name in zip(cards, cards_names): for func_name_two, func_two in zip(function_names_two, functions_two): for value in values: if func_name_two == 'equal': attributes[func_name_two + "(value('" + card_name + "')," + str(value) + ")"].append( func_two(new_eleusis.value(card), value)) if func_name_two == 'less': if value != 1: attributes[func_name_two + "(value('" + card_name + "')," + str(value) + ")"].append( func_two(str(new_eleusis.value(card)), value)) if func_name_two == "greater": if value != 13: attributes[func_name_two + "(value('" + card_name + "')," + str(value) + ")"].append( func_two(str(new_eleusis.value(card)), str(value))) for suit in suits: if func_name_two == 'equal': attributes[func_name_two + "(suit('" + card_name + "'),'" + suit + "')"].append( func_two(new_eleusis.suit(card), suit)) if func_name_two == 'less': if suit != 'C': attributes[func_name_two + "(suit('" + card_name + "'),'" + suit + "')"].append( func_two(str(new_eleusis.suit(card)), suit)) if func_name_two == 'greater': if suit != 'S': attributes[func_name_two + "(suit('" + card_name + "')," + suit + "')"].append( func_two(str(new_eleusis.suit(card)), str(suit))) for i in range(len(cards) - 1): for j in range(i + 1, len(cards)): for func_name_two, func_two in zip(function_names_two, functions_two): attributes[func_name_two + "(" + cards_names[i] + "," + cards_names[j] + ")"].append( func_two(cards[i], cards[j])) attributes[func_name_two + "(value('" + cards_names[i] + "'),value('" + cards_names[j] + "'))"].append( func_two(str(new_eleusis.value(cards[i])), str(new_eleusis.value(cards[j])))) attributes[func_name_two + "(color('" + cards_names[i] + "'),color('" + cards_names[j] + "'))"].append( func_two(str(new_eleusis.color(cards[i])), str(new_eleusis.color(cards[j])))) attributes[func_name_two + "(suit('" + cards_names[i] + "'),suit('" + cards_names[j] + "'))"].append( func_two(str(new_eleusis.suit(cards[i])), str(new_eleusis.suit(cards[j])))) #conjuctions of hypothesis if valid == False: for attr in attributes: if attributes[attr] == False: attributes[attr] = True elif attributes[attr] == True: attributes[attr] = False # for attr in attributes: # if attributes[attr][0] == True: # print(attr,attributes[attr]) print("this is count", len(attributes)) return attributes