Skip to content

Commit

Permalink
Add l1, ..., l4 for compatibility with Deal.
Browse files Browse the repository at this point in the history
  • Loading branch information
anntzer committed Aug 13, 2023
1 parent 3a52874 commit f09526a
Showing 1 changed file with 26 additions and 11 deletions.
37 changes: 26 additions & 11 deletions redeal/redeal.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from bisect import bisect
from collections import Counter
from itertools import permutations, product
from operator import itemgetter
from operator import itemgetter, attrgetter
import functools
import random
import statistics
Expand Down Expand Up @@ -424,16 +424,31 @@ def __contains__(self, other):
clubs = util.reify(
itemgetter(Suit.C), "The hand's clubs.", "clubs")

shape = util.reify(lambda self: tuple(len(holding) for holding in self),
"The hand's shape.")
hcp = util.reify(lambda self: sum(holding.hcp for holding in self),
"The hand's HCP count.")
qp = util.reify(lambda self: sum(holding.qp for holding in self),
"The hand's QP count.")
losers = util.reify(lambda self: sum(holding.losers for holding in self),
"The hand's loser count.")
pt = util.reify(lambda self: sum(holding.pt for holding in self),
"The hand's playing tricks.")
shape = util.reify(
lambda self: tuple(map(len, self)),
"The hand's shape.")
hcp = util.reify(
lambda self, _hcp=attrgetter("hcp"): sum(map(_hcp, self)),
"The hand's HCP count.")
qp = util.reify(
lambda self, _qp=attrgetter("qp"): sum(map(_qp, self)),
"The hand's QP count.")
losers = util.reify(
lambda self, _losers=attrgetter("losers"): sum(map(_losers, self)),
"The hand's loser count.")
pt = util.reify(
lambda self, _pt=attrgetter("pt"): sum(map(_pt, self)),
"The hand's playing tricks.")

# Compatibility with Deal.
l1 = util.reify(lambda self: sorted(map(len, self))[3],
"The length of the hand's longest suit.")
l2 = util.reify(lambda self: sorted(map(len, self))[2],
"The length of the hand's second longest suit.")
l3 = util.reify(lambda self: sorted(map(len, self))[1],
"The length of the hand's third longest suit.")
l4 = util.reify(lambda self: sorted(map(len, self))[0],
"The length of the hand's shortest suit.")

@util.reify
def freakness(self):
Expand Down

0 comments on commit f09526a

Please sign in to comment.