Esempio n. 1
0
 def __init__(self, deck_size, deck_w_jokers, num_players, start_hand_size,
              direction):
     super(SpoonsEnv, self).__init__(deck_size, deck_w_jokers, num_players,
                                     start_hand_size, direction)
     self.trash = Pile()
     self.pass_pile = Pile()
     self.end_player = num_players - 1
Esempio n. 2
0
def labyrinthe(n, dst=None):
    atteint = initLaby(n, False)

    p = Pile()

    laby = Pile()
    c = (0, 0)
    #
    p.empile(c)

    atteint = visiter(c, atteint)

    while not (p.estVide()):

        c = p.depile()
        v = voisins(c, atteint)

        if v:
            s = choisir(v)
            laby.empile((c, s))
            p.empile(c)
            p.empile(s)

            atteint = visiter(s, atteint)

            if not (dst is None) and s == dst:
                path = p._content[:]

    if not (dst is None):
        return laby, path

    return laby
Esempio n. 3
0
    def __init__(self, limit=1000):
        """
        Here is the algorithm for class construction:
        1. Initializes round limit.
        2. Creates the Deck and Pile.
        3. Creates both Players and places them in a list.
        4. Creates the lists holding round and negotiation counts.
        """

        # 1. Initialize round limit

        self.__limit = limit

        # 2. Creates the Deck and Pile

        self.__deck = Deck()
        self.__pile = Pile()

        # 3. Creates both Players and places them in a list

        self.__players = [None, Player(), Player()]

        # 4. Creates the lists holding round and negotiation counts

        self.__round_wins = [0, 0, 0]
Esempio n. 4
0
 def __init__(self, deck_size, deck_w_jokers, num_players, start_hand_size,
              direction):
     super(BartokEnv, self).__init__(deck_size, deck_w_jokers, num_players,
                                     start_hand_size, direction)
     self.center = Pile()
     self.draw2 = False
     self.draw2_effect = 0
Esempio n. 5
0
 def setup_game(self):
     self.pile = Pile()
     self.board = Board()
     self.create_players()
     self.deal()
     self.set_starting_tile()
     self.play()
Esempio n. 6
0
 def __init__(self):
     """
     Constructor:
     Creates the empty hand
     """
     self.__pile = Pile()
     self.__hand = Hand()
Esempio n. 7
0
 def __init__(self, game):
     super(Bartok, self).__init__(game)
     self.env['center'] = Pile()
     # Determines if the current player mustDraw2
     self.env['mustDraw2'] = False
     # Keeps track of the number of players who cumulatively Draw 2
     self.env['draw2Effect'] = 0
Esempio n. 8
0
    def __init__(self,
                 players: List[Player],
                 turn=0,
                 trade_pile=None,
                 draw_pile=None,
                 verbose=True,
                 seed=None):
        self.turn = turn
        self.players: List[Player] = players
        if draw_pile is None:
            draw_pile = DEFAULT_TRADE_PILE.copy()
            random.shuffle(draw_pile)
        self.trade_pile: Pile[Card] = Pile('trade_pile', trade_pile or [])
        self.draw_pile: Pile[Card] = Pile('draw_pile', draw_pile)
        #self.scrap_pile : Pile[Card] = Pile('scrap', [])

        if seed:
            random.seed(seed)
        self.verbose = verbose
Esempio n. 9
0
    def reset(self):
        self.draw_pile : Pile[Card] = Pile('draw_pile')
        self.discard_pile : Pile[Card] = Pile('discard_pile', DEFAULT_PLAYER_DRAW)
        self.health = 50
        self.bases : Pile[BaseCard] = Pile('bases', [])
        self.outposts : Pile[OutpostCard] = Pile('outposts', [])
        self.need_draw = True

        # turn data
        self.hand : Pile[Card] = Pile('hand', [])
        self.in_play : Pile[Card] = Pile('in_play', [])
        self.trade = 0
        self.discard = 0
        self.on_top = 0
        self.damage = 0
        self.remaining_actions : List[Tuple[Card, Action]] = []
Esempio n. 10
0
    def choose_from_piles(self, action: str, *piles: Pile, min_n=0, max_n=1, ship_only=False, remove_from_pile=True) -> Tuple[Pile, List[Card]]:
        if ship_only:
            filtered_piles = [Pile(p.name, filter(lambda c: not isinstance(c, (BaseCard, OutpostCard)), p)) for p in piles]
        else:
            filtered_piles = piles

        filtered_piles = [p for p in filtered_piles if p and len(p) > max(1, min_n)]

        if not filtered_piles:
            if min_n > 0:
                raise UndoMove()
            return None, None

        pile, cards = self.do_choose_from_piles(action, filtered_piles, min_n, max_n)
        actual_pile = None
        if pile and remove_from_pile:
            actual_pile = [p for p in piles if p.name == pile.name]
            assert len(actual_pile) == 1
            actual_pile = actual_pile[0]
            for c in cards:
                actual_pile.remove(c)

        return actual_pile, cards
Esempio n. 11
0
    def __init__(self, limit=1000):
        """
        Initialize round limit
        Initialize the Deck and Pile
        Create both Players and place in list
        Create the lists holding the round and negotiation counts
        """
        # 1. Initialize round limit

        self.__limit = limit

        # 2. Initialize the Deck and Pile

        self.__deck = Deck()
        self.__pile = Pile()

        # 3. Create both Players and place in list

        self.__players = [None, Player(), Player()]

        # 4. Create the lists holding the round and negotiation counts

        self.__round_wins = [0, 0, 0]
Esempio n. 12
0
    def __init__(self, name, health=50, draw_pile=None, discard_pile=None, bases=None, hand=None, outposts=None, need_draw=True):
        if draw_pile is None and discard_pile is None:
            discard_pile = DEFAULT_PLAYER_DRAW

        self.draw_pile : Pile[Card] = Pile('draw_pile', draw_pile or [])
        self.discard_pile : Pile[Card] = Pile('discard_pile', discard_pile or [])
        self.health = health
        self.name = name
        self.bases : Pile[BaseCard] = Pile('bases', bases or [])
        self.outposts : Pile[OutpostCard] = Pile('outposts', outposts or [])
        self.need_draw = need_draw

        # turn data
        self.hand : Pile[Card] = Pile('hand', hand or [])
        self.in_play : Pile[Card] = Pile('in_play', [])
        self.trade = 0
        self.discard = 0
        self.on_top = 0
        self.damage = 0
        self.remaining_actions : List[Tuple[Card, Action]] = []
Esempio n. 13
0
 def test_length(self):
     self.assertEqual(len(Pile()), len(Value) * len(Suit))
     self.assertEqual(len(Pile([])), 0)
     self.assertEqual(len(Pile([Card(Value.TWO, Suit.SPADES)])), 1)
Esempio n. 14
0
    def load_piles(self, display_size):
        display_width, display_height = display_size
        pile_spacing = 50

        start_x = 50
        start_y = self.card_size[1] + 100

        foundation_x_step = self.card_size[0] + pile_spacing
        foundation_start_x = display_width - (foundation_x_step * 4)

        tableau1 = Pile([self.cards[0]], start_x, start_y, self.card_size)
        tableau2 = Pile(self.cards[1:3],
                        start_x + self.card_size[0] + pile_spacing, start_y,
                        self.card_size)
        tableau3 = Pile(self.cards[3:6],
                        start_x + self.card_size[0] * 2 + pile_spacing * 2,
                        start_y, self.card_size)
        tableau4 = Pile(self.cards[6:10],
                        start_x + self.card_size[0] * 3 + pile_spacing * 3,
                        start_y, self.card_size)
        tableau5 = Pile(self.cards[10:15],
                        start_x + self.card_size[0] * 4 + pile_spacing * 4,
                        start_y, self.card_size)
        tableau6 = Pile(self.cards[15:21],
                        start_x + self.card_size[0] * 5 + pile_spacing * 5,
                        start_y, self.card_size)
        tableau7 = Pile(self.cards[21:28],
                        start_x + self.card_size[0] * 6 + pile_spacing * 6,
                        start_y, self.card_size)

        stock = Pile(self.cards[28:],
                     start_x,
                     pile_spacing,
                     self.card_size,
                     pile_type="stock")
        waste = Pile([],
                     start_x + self.card_size[0] + pile_spacing,
                     pile_spacing,
                     self.card_size,
                     pile_type="waste")

        foundation1 = Pile([],
                           foundation_start_x,
                           pile_spacing,
                           self.card_size,
                           pile_type="foundation")
        foundation2 = Pile([],
                           foundation_start_x + foundation_x_step,
                           pile_spacing,
                           self.card_size,
                           pile_type="foundation")
        foundation3 = Pile([],
                           foundation_start_x + foundation_x_step * 2,
                           pile_spacing,
                           self.card_size,
                           pile_type="foundation")
        foundation4 = Pile([],
                           foundation_start_x + foundation_x_step * 3,
                           pile_spacing,
                           self.card_size,
                           pile_type="foundation")

        self.piles = [
            tableau1, tableau2, tableau3, tableau4, tableau5, tableau6,
            tableau7, stock, waste, foundation1, foundation2, foundation3,
            foundation4
        ]
Esempio n. 15
0
 def __init__(self, game):
     super(Spoons, self).__init__(game)
     self.initHandCount = 4
     self.env['trash'] = Pile()
Esempio n. 16
0
 def __init__(self, deck_size, deck_w_jokers, num_players, start_hand_size, direction):
     super(SevensEnv, self).__init__(deck_size, deck_w_jokers, num_players, start_hand_size, direction)
     self.spades_layout = Pile()
     self.diamonds_layout = Pile()
     self.clubs_layout = Pile()
     self.hearts_layout = Pile()
Esempio n. 17
0
 def __init__(self, deck_size, deck_w_jokers, deck_wo_queens, num_players, start_hand_size, direction):
     super(OldmaidEnv, self).__init__(deck_size, deck_w_jokers, deck_wo_queens, num_players, start_hand_size, direction)
     self.trash = Pile()
     self.pass_pile = Pile()
Esempio n. 18
0
 def __init__(self, name, id_, max_size=MAX_SIZE):
     self.name = name
     self.id = id_
     self.hand = Pile()
     self.knowledge = []
     self.points = 0
Esempio n. 19
0
 def _parse_page(self, page):
     print 'parsing page ' + str(page.pageid)
     pile = Pile()
     pile.parse_layout(page)
     piles = pile.split_piles()
     return piles
Esempio n. 20
0
    def __init__(self):
        # create and shuffle deck
        self.gameDeck = Deck()
        self.gameDeck.createDeck()
        self.gameDeck.shuffleDeck()

        # initialize piles
        self.handPile = Pile("h", self.gameDeck.cards[:])
        self.wastePile = Pile("w", []) 
        self.foundationsPiles = [
            Pile("f", []),
            Pile("f", []),
            Pile("f", []),
            Pile("f", []) 
        ]
        self.tableauPiles = [
            Pile("t", []),
            Pile("t", []),
            Pile("t", []),
            Pile("t", []),
            Pile("t", []),
            Pile("t", []),
            Pile("t", [])
        ]
Esempio n. 21
0
 def construct_piles_subseqs(self):
     """
     This method handles most of this program's tasks. It creates 
     the Piles of Cards on the table from the Cards dealt from the 
     Deck. It also places the Card in its correct position in the 
     list of SubSequences, linking it to the top Card from the 
     previous Pile.
     
     The Algorithm:
     
     A. Outer Loop for each Card in the Deck
        1. Retrieve the Card from the Deck: card_from_deck
        2. Set a flag to indicate if we place the 
           card_from_deck in an existing Pile
        3. Inner Loop through each Pile starting from the 
           leftmost Pile - Python list index 0 - to find the
           correct one on which to place the card_from_deck
           a. Obtain a reference to the top Card on the current 
              Pile(Stack): See Pile methods
           b. If there exists a Pile whose top Card is higher 
              than the card_from_deck, then
              1.   Add the card_from_deck onto the Pile: See Pile methods
              ii.  Set the flag to say we have found a Pile on 
                   which to place the card_from_deck
              iii. Obtain a reference to the top Card on the 
                   previous Pile - the one to the left of where 
                   you just placed the card_from_deck: (one less 
                   index value in Python list): 
                   This needs to be a if / else block:
                   if the pile has an index of 0, then prev_card = None
                   else prev_card = top Card on the previous Pile
              iv. Add the card_from_deck to the list of 
                  SubSequences using the add_card_to_subseq method
              v.   Break out of loop
        4. Check the flag:
           If we haven't found a place for the card_from_deck 
           in an existing Pile, then
           a. Create a new Pile (in Python list of Piles)
           b. Obtain a reference to the top Card on the 
              previous Pile - the one to the left of where 
              you just placed the card_from_deck: (one less 
              index value in Python list): 
              This needs to be a if / else block:
              if the pile has an index of 0, then prev_card = None
              else prev_card = top Card on the previous Pile
           c. Add the card_from_deck to the list of SubSequences 
              using the add_card_to_subseq method
           d. Push the card_from_deck onto the Pile
           e. Add the new pile to the pile list
     """
     for i in range(self.CARDS_IN_DECK):
         card_from_deck = self.__deck.dequeue()
         flag = 0
         while flag < 5:
             for t in range(len(self.__piles)):
                 top = self.__piles[t].get_top_card()
                 if top.compare(card_from_deck) == 1:
                     self.__piles[t].add_card(card_from_deck)
                     if len(self.__piles[t - 1]) == 0:
                         prev_card = None
                     else:
                         prev_card = self.__piles[t - 1].get_top_card()
                         self.add_card_to_subseq(card_from_deck, prev_card)
                     flag += 5
                     break
             if flag == 0:
                 self.__piles.append(Pile())
                 if len(self.__piles) <= 1:
                     prev_card = None
                 else:
                     prev_card = self.__piles[len(self.__piles) -
                                              2].get_top_card()
                 self.add_card_to_subseq(card_from_deck, prev_card)
                 self.__piles[len(self.__piles) - 1].push(card_from_deck)
             flag += 5
Esempio n. 22
0
    def _init_piles(self) -> [Pile]:
        '''
        Initializes a new list of piles randomly. Used 
        when starting a new game
        '''
        cards = self._generate_random_deck()
        piles = []

        piles.append(Pile('tableau', [cards[0]], number=0))
        piles.append(Pile('tableau', cards[1:3], number=1))
        piles.append(Pile('tableau', cards[3:6], number=2))
        piles.append(Pile('tableau', cards[6:10], number=3))
        piles.append(Pile('tableau', cards[10:15], number=4))
        piles.append(Pile('tableau', cards[15:21], number=5))
        piles.append(Pile('tableau', cards[21:28], number=6))

        piles.append(Pile('stock', cards[28:]))
        piles.append(Pile('waste'))

        piles.append(Pile('foundation', number=0))
        piles.append(Pile('foundation', number=1))
        piles.append(Pile('foundation', number=2))
        piles.append(Pile('foundation', number=3))

        return piles
Esempio n. 23
0

from pile import Pile

pile = Pile()
pile.empiler(5)
pile.empiler(6)
pile.empiler(6)
pile.empiler(6)
pile.empiler(6)
pile.empiler(6)
pile.empiler(6)

if pile.est_vide():
    print("C'est bien vide")
else:
    print("la liste n'est pas vide")

print(pile)
Esempio n. 24
0
    def construct_piles_subseqs(self):
        """
        This method handles most of this program's tasks. It creates 
        the Piles of Cards on the table from the Cards dealt from the 
        Deck. It also places the Card in its correct position in the 
        list of SubSequences, linking it to the top Card from the 
        previous Pile.
        
        The Algorithm:
        
        A. Outer Loop for each each Card in the Deck
           1. Retrieve the Card from the Deck: card_from_deck
           2. Set a flag to indicate if we place the 
              card_from_deck in an existing Pile
           3. Inner Loop through each Pile starting from the 
              leftmost Pile - Python list index 0 - to find the
              correct one on which to place the card_from_deck
              a. Obtain a reference to the top Card on the current 
                 Pile(Stack) using peek
              b. If there exists a Pile whose top Card is higher 
                 than the card_from_deck, then
                 i.   Set the flag to say we have found a Pile on 
                      which to place the card_from_deck
                 ii.  Obtain a reference to the top Card on the 
                      previous Pile - the one to the left of where 
                      you just placed the card_from_deck: (one less 
                      index value in Python list) using peek
                 iii. Add the card_from_deck to the list of 
                      SubSequences using the add_card_to_subseq 
                      method
                 iv.  Push the card_from_deck onto the Pile
           4. Check the flag:
              If we haven't found a place for the card_from_deck 
              in an existing Pile, then
              a. Create a new Pile (in Python list of Piles (Stacks)
              b. Obtain a reference to the top Card on the previous 
                 Pile - the one to the left of where you just placed 
                 the card_from_deck: (one less index value in Python 
                 list) using peek - unless this first Card from the 
                 Deck, when the number of Piles are zero, using len 
                 function.
              c. Add the card_from_deck to the list of SubSequences 
                 using the add_card_to_subseq method
              d. Push the card_from_deck onto the Pile
        """
        for card in range(self.CARDS_IN_DECK):
            card_from_deck = self.__deck.deal()
            flag = False
            prev_card = None
            if len(self.__piles) > 0:

                for i in range(len(self.__piles)):
                    top_card = self.__piles[i].get_top_card()
                    if top_card.compare(card_from_deck) > 0:
                        flag = True
                        if i > 0:
                            prev_card = self.__piles[i - 1].get_top_card()
                        self.add_card_to_subseq(card_from_deck, prev_card)
                        self.__piles[i].add_card(card_from_deck)
                        break
            if flag is not True:
                pile = Pile()
                if len(self.__piles) > 0:
                    prev_card = self.__piles[len(self.__piles) -
                                             1].get_top_card()
                self.add_card_to_subseq(card_from_deck, prev_card)
                pile.add_card(card_from_deck)
                self.__piles.append(pile)
Esempio n. 25
0
 def __init__(self, decks=1, seed=None):
     self.pile1, self.pile2 = Pile(decks).shuffle(seed).split()
Esempio n. 26
0
 def _parse_page(self, page):
     pile = Pile()
     pile.parse_layout(page)
     piles = pile.split_piles()
     return piles
Esempio n. 27
0
 def test_pop(self):
     with self.assertRaises(IndexError):
         Pile([]).pop()