Skip to content

Commit

Permalink
Minor cleanups.
Browse files Browse the repository at this point in the history
  • Loading branch information
anntzer committed Dec 30, 2017
1 parent 70d2fda commit 4b8f2f1
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 18 deletions.
6 changes: 3 additions & 3 deletions README.rst
Expand Up @@ -34,11 +34,11 @@ package is directly from GitHub,

.. code:: sh
$ pip install --user git+https://github.com/anntzer/redeal
$ python -mpip install --user git+https://github.com/anntzer/redeal
On Windows **only**, you can also download the ``.zip`` archive (from master,
not from the releases), and run, from the folder containing the archive, ``pip
install redeal-master.zip`` (or whatever name it has).
not from the releases), and run, from the folder containing the archive,
``python -mpip install redeal-master.zip`` (or whatever name it has).

Directly running ``setup.py`` is **not** supported in either case.

Expand Down
2 changes: 1 addition & 1 deletion examples/bbo_you_have_no_clue.py
Expand Up @@ -5,7 +5,7 @@
from redeal import *


predeal = {"S": H("T8 8762 KT4 KQ52")}
predeal = {"S": "T8 8762 KT4 KQ52"}


def initial():
Expand Down
5 changes: 2 additions & 3 deletions examples/bridgewinners_matchpoint_odds.py
Expand Up @@ -21,9 +21,8 @@
from redeal import *


# The predealt cards (a dict with keys N, E, S, W). `H` is a hand constructor
# (if less than 13 cards are predealt, use "-" for the empty suits).
predeal = {"S": H("652 K752 53 9862")}
# The predealt cards (a dict with keys N, E, S, W; use "-" for voids).
predeal = {"S": "652 K752 53 9862"}


# `initial` is called at the beginning of the sim. Here it initializes a
Expand Down
2 changes: 1 addition & 1 deletion examples/deal2.py
Expand Up @@ -7,7 +7,7 @@

from redeal import *

predeal = {"S": H("Q86432 T2 932 83")}
predeal = {"S": "Q86432 T2 932 83"}

def accept(deal):
return deal.east.hcp > 18 and (deal.east.hcp > 22 or deal.east.losers < 2)
2 changes: 1 addition & 1 deletion examples/deal3.py
Expand Up @@ -13,7 +13,7 @@

from redeal import *

predeal = {"S": H("764 J4 J753 AQJ2")}
predeal = {"S": "764 J4 J753 AQJ2"}

def accept(deal):
return (16 <= deal.west.hcp <= 19 and deal.west.shape in Shape("5(332)")
Expand Down
2 changes: 1 addition & 1 deletion examples/deal_gambling.py
Expand Up @@ -24,7 +24,7 @@ def gambling(holding):
len(holding) >= 7 and A in holding and K in holding and Q in holding
or len(holding) <= 4 and A not in holding and K not in holding)

predeal = {"S": H("AK K52 98765 962"),
predeal = {"S": "AK K52 98765 962",
"N": SmartStack(GamblingShape, gambling, [4])}

_shapes = Counter()
Expand Down
5 changes: 1 addition & 4 deletions examples/opening_lead.py
@@ -1,14 +1,11 @@
from redeal import *


predeal = {"W": H("QT T32 JT8732 32")}

predeal = {"W": "QT T32 JT8732 32"}

def accept(deal):
north, south = deal.north, deal.south
return (south.shape in Shape("33(43)") + Shape("(32)(53)") and
4 in (len(north.spades), len(north.hearts)) and
15 <= south.hcp <= 17 and 9 <= north.hcp <= 11)


simulation = OpeningLeadSim(accept, "3NS", imps)
9 changes: 5 additions & 4 deletions redeal/redeal.py
Expand Up @@ -233,13 +233,13 @@ def prepare(cls, predeal=None):
There can be at most one ``SmartStack`` entry.
"""
predeal = {} if predeal is None else predeal.copy() or {}
predeal = {} if predeal is None else predeal.copy()
dealer = {}
seat_smartstack = None
for seat in Seat:
try:
pre = predeal.pop(str(seat)[0])
except:
except KeyError:
pre = predeal.pop(seat, Hand(()))
if isinstance(pre, str):
dealer[seat] = H(pre).cards
Expand Down Expand Up @@ -268,8 +268,9 @@ def prepare(cls, predeal=None):
def __new__(cls, dealer, accept_func=None, tries=1000):
"""Randomly deal a hand from a prepared dealer.
``accept_func`` can be a function similar to ``Simulation.accept``
Reshuffles until ``accept_func`` returns true, but at most set number of ``tries``.
*accept_func* can be a function similar to `Simulation.accept`:
reshuffle until *accept_func* returns True, but no more than *tries*
times.
"""
for i in range(tries):
hands = [None] * len(Seat)
Expand Down

0 comments on commit 4b8f2f1

Please sign in to comment.