def test4(self): spiel = Spiel_class.Spiel( card_class.create_kartenliste([ 'OSSW', 'SWSW', 'SOSSG', 'WWSWK', 'WWSS', 'WWSS', 'OOSOOT', 'OSSW', 'SOWS', 'OSSW' ], False)) player1 = Player(1) player2 = Player(2) k1 = Card('O', 'S', 'S', 'W') spiel.make_action(player1, k1, 1, 0, 3) k2 = Card('W', 'W', 'S', 'W', 'K') spiel.make_action(player2, k2, 1, -1, 1, 'k') k3 = Card('S', 'O', 'W', 'S') spiel.make_action(player1, k3, 0, 1, 3) k4 = Card('O', 'S', 'S', 'W') spiel.make_action(player2, k4, 0, -1, 3) k5 = Card('W', 'W', 'S', 'S') spiel.make_action(player1, k5, 1, 1, 3) self.assertEqual(len(spiel.alle_wiesen), 2)
def test1(self): p1 = Player(1) p2 = Player(2) spiel = Spiel_class.Spiel([], p1, p2) k1 = Card('O', 'O', 'S', 'O', 'O', True) spiel.make_action(p1, k1, 1, 0, 0, k1.orte[0]) k2 = Card('O', 'S', 'S', 'W') spiel.make_action(p2, k2, 0, 1, 1, k2.strassen[0]) k3 = Card('O', 'S', 'S', 'W') spiel.make_action(p1, k3, 2, 0, 3, k3.strassen[0]) k4 = Card('W', 'W', 'S', 'S') spiel.make_action(p2, k4, 2, -1, 0, k4.strassen[0]) k5 = Card('S', 'W', 'S', 'W') spiel.make_action(p1, k5, -1, 0, 0, k5.strassen[0]) k6 = Card('W', 'W', 'S', 'S') spiel.make_action(p2, k6, 0, 2, 1, k6.strassen[0]) k7 = Card('W', 'W', 'S', 'W', 'K') spiel.make_action(p1, k7, 2, 1, 0, 'k') k8 = Card('S', 'O', 'S', 'S', 'G') s = None for st in k8.strassen: if st.kanten == [3]: s = st spiel.make_action(p2, k8, 1, -1, 1, s) k9 = Card('O', 'S', 'S', 'W') spiel.make_action(p1, k9, 1, -2, 0, k9.orte[0]) #display_spielbrett_dict(spiel.cards_set) k10 = Card('S', 'O', 'W', 'S') #pos = spiel.calculate_possible_actions(k10, p2) #node = Node(True, None, p2.nummer, None) #a, b = uct_select(spiel, k10, p2, pos, d=1, root_node=node, t_end=None, rechenzeit=30, c=1.4142, threads=1) #print(a, b) w = None for wi in k10.wiesen: if wi.ecken == [4]: w = wi spiel.make_action(p2, k10, 2, -2, 0, w) spiel.final_evaluate() self.assertEqual(p2.punkte, 12)
def test10(self): spiel = Spiel_class.Spiel(Kartenliste) player1 = Player(1) player2 = Player(2) k1 = Card('O', 'S', 'S', 'W') pos1 = spiel.calculate_possible_actions(k1, player1) self.assertEqual(30, len(pos1)) spiel.make_action(player1, k1, 0, 1, 1, k1.orte[0]) k2 = Card('O', 'W', 'W', 'O', 'O', True) pos2 = spiel.calculate_possible_actions(k2, player2) self.assertEqual(22, len(pos2)) spiel.make_action(player2, k2, 1, 0, 0, k2.orte[0]) k3 = Card('O', 'O', 'W', 'O', 'O') pos3 = spiel.calculate_possible_actions(k3, player1) self.assertEqual(16, len(pos3)) spiel.make_action(player1, k3, 1, 1, 2) #display_spielbrett_dict(spiel.cards_set) k4 = Card('W', 'O', 'W', 'O') pos4 = spiel.calculate_possible_actions(k4, player2) self.assertEqual(23, len(pos4))
def test5(self): spiel = Spiel_class.Spiel(Kartenliste) player1 = Player(1) player2 = Player(2) k2 = Card('O', 'W', 'W', 'O', 'O') spiel.make_action(player1, k2, 1, 0, 0, k2.orte[0]) k3 = Card('W', 'O', 'W', 'O') pos = spiel.calculate_possible_actions(k3, player2) self.assertEqual(len(pos), 15)
def test4(self): spiel = Spiel_class.Spiel(Kartenliste) player1 = Player(1) player2 = Player(2) k2 = Card('O', 'W', 'W', 'O', 'O') spiel.make_action(player1, k2, 1, 0, 0) k3 = Card('W', 'O', 'W', 'O') pos = spiel.calculate_possible_actions(k3, player2) #display_spielbrett_dict(spiel.cards_set) self.assertEqual(len(pos), 16)
def test_2(self): spiel = Spiel(Kartenliste) player1 = Player(1) player2 = Player(2) card1 = Card('W', 'W', 'S', 'S') spiel.make_action(player1, card1, 0, -1, 1) card2 = Card('O', 'S', 'S', 'O', 'O') spiel.make_action(player2, card2, 0, 1, 1) card3 = Card('O', 'S', 'S', 'W') spiel.make_action(player1, card3, -1, 1, 3) card4 = Card('S', 'W', 'S', 'W') spiel.make_action(player2, card4, -1, -1, 1) card5 = Card('S', 'O', 'W', 'S') spiel.make_action(player1, card5, -2, -1, 1) card6 = Card('O', 'W', 'W', 'W') spiel.make_action(player2, card6, -2, 1, 1) card7 = Card('W', 'W', 'S', 'W', 'K') spiel.make_action(player1, card7, -2, 0, 0, 'k') self.assertEqual(len(spiel.alle_kloester), 1) self.assertEqual(player1.meeples, 6) card8 = Card('W', 'W', 'W', 'W', 'K') spiel.make_action(player2, card8, -1, 0, 0, 'k') self.assertEqual(len(spiel.alle_kloester), 1) self.assertEqual(player2.meeples, 7)
def test3(self): p1 = Player(1) p2 = Player(2) spiel = Spiel_class.Spiel([], p1, p2) k1 = Card('O', 'S', 'S', 'W') spiel.make_action(p1, k1, 0, -1, 2) k2 = Card('W', 'W', 'S', 'S') spiel.make_action(p2, k2, 1, -1, 3) k3 = Card('O', 'S', 'S', 'W') spiel.make_action(p1, k3, 2, -1, 1) k4 = Card('O', 'S', 'S', 'W') spiel.make_action(p2, k4, 0, -2, 0) k5 = Card('W', 'W', 'S', 'W', 'K') spiel.make_action(p1, k5, 0, -3, 2) k6 = Card('S', 'O', 'W', 'S') spiel.make_action(p2, k6, 2, -2, 0) k7 = Card('W', 'O', 'W', 'O') spiel.make_action(p1, k7, 1, -3, 1) #display_spielbrett_dict(spiel.cards_set) k8 = Card('S', 'O', 'S', 'S', 'G') spiel.make_action(p2, k8, 1, -2, 1) print('ende')
def add_card_to_deck(self,id_card,subject,top_side,back_side): """ this program creates a new card (attributes are the inputs) and add it to the current deck """ new_card = Card(id_card, subject, top_side, back_side) self.cards.append(new_card) return
def __init__(self, u_id): self._unique_id = u_id self._cards = [] for suit in Card.suits: for rank in Card.ranks: card = Card(suit, rank) self._cards.append(card)
def test4(self): spiel = Spiel_class.Spiel(Kartenliste) player1 = Player_Class.Player(1) player2 = Player_Class.Player(2) k1 = Card('W', 'W', 'W', 'W', 'K') spiel.make_action(player2, k1, -1, 0, 0, 'k') k2 = Card('O', 'W', 'W', 'W') spiel.make_action(player1, k2, -2, 0, 0) k3 = Card('W', 'O', 'W', 'O') spiel.make_action(player2, k3, -2, 1, 3, k3.wiesen[0]) self.assertEqual(player1.punkte, 0) self.assertEqual(player2.punkte, 0)
def test4(self): spiel = Spiel_class.Spiel(Kartenliste) player1 = Player_Class.Player(1) player2 = Player_Class.Player(2) k1 = Card('O', 'O', 'W', 'O', 'O') spiel.make_action(player1, k1, 1, 0, 2) k2 = Card('O', 'S', 'S', 'O', 'O') spiel.make_action(player2, k2, 1, -1, 1) k3 = Card('O', 'W', 'W', 'O', 'O') spiel.make_action(player1, k3, 2, -1, 0) k4 = Card('O', 'O', 'O', 'O', 'O') spiel.make_action(player2, k4, 2, 0, 0)
def test6(self): spiel = Spiel_class.Spiel(Kartenliste) player1 = Player_Class.Player(1) player2 = Player_Class.Player(2) k1 = Card('S', 'O', 'S', 'S', 'G') spiel.make_action(player2, k1, 0, -1, 0) k2 = Card('S', 'O', 'S', 'W') spiel.make_action(player1, k2, 0, 1, 2) k3 = Card('O', 'W', 'W', 'O', 'O') spiel.make_action(player2, k3, 2, 0, 1) k4 = Card('O', 'O', 'S', 'O', 'O', True) spiel.calculate_possible_actions(k4, player1)
def test3(self): spiel = Spiel(Kartenliste) player1 = Player(1) player2 = Player(2) k1 = Card('W', 'W', 'W', 'W', 'K') spiel.make_action(player1, k1, -1, 0, 0, 'k') k2 = Card('W', 'W', 'S', 'W', 'K') spiel.make_action(player2, k2, -1, 1, 1, 'k') #plot_cards.display_spielbrett_dict(spiel.cards_set) spiel.final_evaluate() self.assertEqual(player1.punkte, 3) self.assertEqual(player2.punkte, 3)
def test5(self): spiel = Spiel_class.Spiel(Kartenliste) player1 = Player_Class.Player(1) player2 = Player_Class.Player(2) k1 = Card('W', 'O', 'W', 'O') spiel.make_action(player1, k1, -1, 0, 1) self.assertEqual(len(spiel.alle_orte), 3)
def test5(self): p1 = Player(1) p2 = Player(2) spiel = Spiel_class.Spiel([], p1, p2) k1 = Card('S', 'W', 'S', 'W') spiel.make_action(p1, k1, 0, -1, 0, k1.strassen[0]) k2 = Card('O', 'S', 'S', 'W') w = None for wi in k2.wiesen: if sorted(wi.ecken) == [4, 5, 7]: w = wi spiel.make_action(p2, k2, 0, 1, 0, w) print('ende')
def new_deck(self): """ Create a new deck and shuffle.""" self.cards = [] for suit in Card.suits: for rank in Card.ranks: card = Card(suit, rank) self._cards.append(card) self.shuffle() return self.cards
def test_1(self): spiel = Spiel(Kartenliste) card1 = Card('W', 'W', 'W', 'W', 'K') player1 = Player(1) spiel.make_action(player1, card1, -1, 0, 1, 'k') self.assertEqual(player1.meeples, 6) self.assertEqual(len(spiel.alle_kloester), 1)
def test1(self): player1 = Player(1) player2 = Player(2) spiel = Spiel_class.Spiel([]) k1 = Card('S', 'W', 'S', 'W') pos = spiel.calculate_possible_actions(k1, player1) self.assertEqual(12, len(pos))
def test2(self): spiel = Spiel_class.Spiel(Kartenliste) player1 = Player(1) player2 = Player(2) k1 = Card('W', 'S', 'S', 'W') spiel.make_action(player1, k1, 0, 1, 1, k1.strassen[0]) k2 = Card("S", 'W', 'S', 'W') spiel.make_action(player2, k2, -1, 0, 0, k2.strassen[0]) k3 = Card('W', 'S', 'S', 'W') spiel.make_action(player1, k3, -1, 1, 0, None) # display_spielbrett_dict(spiel.cards_set) spiel.final_evaluate() self.assertEqual(player1.punkte, 4) self.assertEqual(player2.punkte, 4)
def test7(self): p1 = Player(1) p2 = Player(2) spiel = Spiel_class.Spiel([], p1, p2) k1 = Card('O', 'S', 'S', 'O', 'O') spiel.make_action(p2, k1, 1, 0, 0, k1.strassen[0]) k2 = Card('W', 'W', 'S', 'S') spiel.make_action(p1, k2, 1, -1, 2) k3 = Card('W', 'W', 'S', 'S') spiel.make_action(p2, k3, 2, -1, 1) k4 = Card('W', 'S', 'S', 'S', 'G') spiel.make_action(p1, k4, 2, 0, 0) self.assertEqual(p2.meeples, 7) self.assertEqual(p2.punkte, 5)
def __init__(self): self.cards = [] # holds 52 cards self.suits = ["Clubs", "Hearts", "Diamond", "Spades"] self.ranks = { "Two": 2, "Three": 3, "Four": 4, "Five": 5, "Six": 6, "Seven": 7, "Eight": 8, "Nine": 9, "Ten": 10, "Ace": 11, "Jack": 12, "Queen": 13, "King": 14 } # fill Deck object with 52 cards for suit in self.suits: for rank, value in self.ranks.items(): self.cards.append(Card(suit, rank, value))
def test2(self): p1 = Player(1) p2 = Player(2) spiel = Spiel_class.Spiel([], p1, p2) k1 = Card('W', 'W', 'S', 'W', 'K') spiel.make_action(p1, k1, 0, -1, 2) k2 = Card('O', 'O', 'S', 'O', 'O', True) spiel.make_action(p2, k2, 1, 0, 2) k3 = Card('S', 'O', 'W', 'S') spiel.make_action(p1, k3, -1, 0, 3) k4 = Card('W', 'W', 'S', 'W', 'K') spiel.make_action(p2, k4, 1, 1, 0) k5 = Card('O', 'S', 'S', 'W') spiel.make_action(p1, k5, -1, 1, 2) #display_spielbrett_dict(spiel.cards_set) k6 = Card('S', 'W', 'S', 'W') pos = spiel.calculate_possible_actions(k6, p2) spiel.make_action(p2, k6, 0, 1, 0)
def print_card(self, identifier): existence = False my_card = Card("id_card", "Waste", "topside", "backside") if my_deck.cards == []: showinfo("Info", "Empty deck: you should add cards first!") else: for c in my_deck.cards: if c.identifier == identifier: existence = False my_card.identifier = c.identifier my_card.subject = c.subject my_card.topside = c.topside my_card.backside = c.backside break else: existence = True if existence == False: showinfo( "Here is your card", "id: " + identifier + "\ntopside: " + my_card.topside + "\nbackside: " + my_card.backside) else: showinfo("Info!", "This card does not exist or you haven't choose a card")
def test6(self): spiel = Spiel_class.Spiel( card_class.create_kartenliste([ 'OSSW', 'SWSW', 'SOSSG', 'WWSWK', 'WWSS', 'WWSS', 'OOSOOT', 'OSSW', 'SOWS', 'OSSW' ], False)) player1 = Player(1) player2 = Player(2) k0 = Card('S', 'W', 'W', 'S') spiel.make_action(player1, k0, 0, 1, 2) k1 = Card('W', 'W', 'S', 'S') spiel.make_action(player2, k1, 0, 2, 1) k2 = Card('W', 'W', 'S', 'W', 'K') spiel.make_action(player1, k2, 1, 2, 0) k3 = Card('O', 'S', 'S', 'W') spiel.make_action(player2, k3, 1, 1, 2) self.assertEqual(1, 1)
def test5(self): spiel = Spiel_class.Spiel( card_class.create_kartenliste([ 'OSSW', 'SWSW', 'SOSSG', 'WWSWK', 'WWSS', 'WWSS', 'OOSOOT', 'OSSW', 'SOWS', 'OSSW' ], False)) player1 = Player(1) player2 = Player(2) k1 = Card('O', 'S', 'S', 'W') spiel.make_action(player1, k1, 1, 0, 3) k2 = Card('W', 'W', 'S', 'W', 'K') spiel.make_action(player2, k2, 1, -1, 1, 'k') k3 = Card('W', 'W', 'S', 'W', 'K') spiel.make_action(player1, k3, 0, 1, 1, 'k') k4 = Card('W', 'W', 'S', 'S') spiel.make_action(player2, k4, 0, -1, 2) a = sorted([ list(v) for v in [w.alle_teile.items() for w in spiel.alle_wiesen] ]) b = [[((1, 0), [5])], [((1, 0), [7, 4, 6]), ((1, -1), [5, 6, 7, 4]), ((0, -1), [6, 7, 4, 5]), ((0, 0), [5, 6, 4, 7]), ((0, 1), [5, 6, 7, 4])]] self.assertEqual(a, b) w = [w for w in spiel.alle_wiesen if len(w.alle_teile) != 1][0] for c in spiel.cards_set: if c != (1, 0): for ecke in spiel.cards_set[c].ecken: self.assertEqual(spiel.cards_set[c].ecken[ecke], w)
def test3(self): spiel = Spiel_class.Spiel(Kartenliste) player1 = Player(1) player2 = Player(2) k1 = Card('O', 'O', 'S', 'O', 'O', True) spiel.make_action(player2, k1, 1, 0, 0, k1.orte[0]) k2 = Card('O', 'W', 'W', 'O', 'O') spiel.make_action(player1, k2, 1, 1, 2, k2.wiesen[0]) k3 = Card('W', 'W', 'W', 'W', 'K') pos = spiel.calculate_possible_actions(k3, player2) #display_spielbrett_dict(spiel.cards_set) goal = [(-1, 0, 0, k3.wiesen[0]), (-1, 0, 0, None), (-1, 0, 0, 'k'), (1, 2, 0, None), (1, 2, 0, 'k')] self.assertEqual(len(pos), len(goal)) for tup in pos: self.assertTrue(tup in goal)
def test9(self): spiel = Spiel_class.Spiel(Kartenliste) player1 = Player(1) player2 = Player(2) k1 = Card('W', 'W', 'S', 'S') pos1 = spiel.calculate_possible_actions(k1, player1) self.assertEqual(len(pos1), 24) spiel.make_action(player1, k1, 0, 1, 3) k2 = Card('S', 'O', 'S', 'W') pos2 = spiel.calculate_possible_actions(k2, player2) self.assertEqual(len(pos2), 40) wiese = [w for w in k2.wiesen if w.ecken == [5, 6]][0] spiel.make_action(player1, k2, 1, 1, 1, wiese) k3 = Card('O', 'O', 'S', 'O', 'O', True) pos3 = spiel.calculate_possible_actions(k3, player1) self.assertEqual(len(pos3), 18)
def test7(self): spiel = Spiel_class.Spiel(Kartenliste) player1 = Player(1) player2 = Player(2) k1 = Card('S', 'W', 'S', 'W') pos1 = spiel.calculate_possible_actions(k1, player1) self.assertEqual(len(pos1), 12) spiel.make_action(player1, k1, 0, 1, 0, k1.strassen[0]) k2 = Card('O', 'W', 'W', 'O', 'O') pos2 = spiel.calculate_possible_actions(k2, player2) self.assertEqual(len(pos2), 24) spiel.make_action(player2, k2, 1, 0, 0, k2.orte[0]) #display_spielbrett_dict(spiel.cards_set) k3 = Card('W', 'W', 'S', 'S') pos3 = spiel.calculate_possible_actions(k3, player1) self.assertEqual(len(pos3), 44) spiel.make_action(player1, k3, 0, 2, 3) k4 = Card('O', 'S', 'S', 'W') pos4 = spiel.calculate_possible_actions(k4, player2) self.assertEqual(len(pos4), 46) spiel.make_action(player2, k4, 1, 2, 2) k4 = Card('W', 'O', 'W', 'O') pos5 = spiel.calculate_possible_actions(k4, player1) #display_spielbrett_dict(spiel.cards_set) self.assertEqual(len(pos5), 31)
def test8(self): """fast der gleiche wie test7, nur mit meeple mehr in vorletzem Zug""" spiel = Spiel_class.Spiel(Kartenliste) player1 = Player(1) player2 = Player(2) k1 = Card('S', 'W', 'S', 'W') pos1 = spiel.calculate_possible_actions(k1, player1) self.assertEqual(len(pos1), 12) spiel.make_action(player1, k1, 0, 1, 0, k1.strassen[0]) k2 = Card('O', 'W', 'W', 'O', 'O') pos2 = spiel.calculate_possible_actions(k2, player2) self.assertEqual(len(pos2), 24) spiel.make_action(player2, k2, 1, 0, 0, k2.orte[0]) #display_spielbrett_dict(spiel.cards_set) k3 = Card('W', 'W', 'S', 'S') pos3 = spiel.calculate_possible_actions(k3, player1) self.assertEqual(len(pos3), 44) spiel.make_action(player1, k3, 0, 2, 3) k4 = Card('O', 'S', 'S', 'W') pos4 = spiel.calculate_possible_actions(k4, player2) self.assertEqual(len(pos4), 46) spiel.make_action(player2, k4, 1, 2, 2, k4.orte[0]) k5 = Card('W', 'O', 'W', 'O') pos5 = spiel.calculate_possible_actions(k5, player1) self.assertEqual(len(pos5), 30)
def test11(self): spiel = Spiel_class.Spiel(Kartenliste) player1 = Player(1) player2 = Player(2) k1 = Card('S', 'O', 'S', 'S', 'G') spiel.make_action(player1, k1, 1, 0, 2, k1.orte[0]) k2 = Card('O', 'S', 'S', 'W') spiel.make_action(player2, k2, 0, -1, 2, k2.orte[0]) pos = spiel.calculate_possible_actions(k2, player2) k3 = Card('W', 'W', 'S', 'S') wiese = None for w in k3.wiesen: if sorted(w.ecken) == sorted([4, 5, 7]): wiese = w spiel.make_action(player1, k3, 1, -1, 2, wiese) k4 = Card('S', 'W', 'S', 'W') spiel.make_action(player2, k4, 0, 1, 0, k4.strassen[0]) k5 = Card('O', 'O', 'S', 'O', 'O', True) wiese = [w for w in k5.wiesen if w.ecken == [6]][0] spiel.make_action(player1, k5, 2, -1, 1, wiese) k6 = Card('O', 'S', 'S', 'W') wiese = [w for w in k6.wiesen if sorted(w.ecken) == sorted([4, 5, 7])][0] spiel.make_action(player2, k6, 0, -2, 0, wiese) k7 = Card('O', 'S', 'S', 'W') spiel.make_action(player1, k7, 2, 0, 2, k7.orte[0]) k8 = Card('S', 'O', 'W', 'S') pos = spiel.calculate_possible_actions(k8, player2) print('hi')