|
@@ -11,8 +11,8 @@ class Board:
|
|
|
|
|
|
def __init__(self, nrows = 4, deck_size = 104, max_row_len = 5):
|
|
|
self.ncards = deck_size
|
|
|
- #self.deck = random.shuffle(list(range(1, deck_size + 1)))
|
|
|
self.deck = list(range(1, deck_size + 1))
|
|
|
+ random.shuffle(self.deck)
|
|
|
print(self.deck)
|
|
|
self.rows = [[c] for c in self.draw(nrows)]
|
|
|
print(self.rows)
|
|
@@ -29,16 +29,19 @@ class Board:
|
|
|
def calc_penalty(cls, row):
|
|
|
return sum(map(Board.card_value, row))
|
|
|
|
|
|
- def draw(cls, n = 1):
|
|
|
- #assert len(cls.deck) < n, 'draw: not that many cards in the deck'
|
|
|
- top_n = cls.deck[:n]
|
|
|
- cls.deck = cls.deck[n:]
|
|
|
+ def draw(self, n = 1):
|
|
|
+ print(len(self.deck), n)
|
|
|
+ assert len(self.deck) >= n, 'draw: not that many cards in the deck'
|
|
|
+ top_n = self.deck[:n]
|
|
|
+ self.deck = self.deck[n:]
|
|
|
return top_n
|
|
|
|
|
|
def reset_row(self, row_ind, card):
|
|
|
- #assert 0 <= row_ind > len(self.rows), 'reset_row: index is out of the range'
|
|
|
- #assert 0 < card <= self.ncards, 'reset_row: invalid card'
|
|
|
+ assert 0 <= row_ind < len(self.rows), 'reset_row: index is out of the range'
|
|
|
+ assert 0 < card <= self.ncards, 'reset_row: invalid card'
|
|
|
+ penalty = self.calc_penalty(self.rows[row_ind])
|
|
|
self.rows[row_ind] = [card]
|
|
|
+ return penalty
|
|
|
|
|
|
def place_card(self, card):
|
|
|
mindiff = self.ncards
|