bridgeobjects 0.1.26__tar.gz → 0.1.28__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. {bridgeobjects-0.1.26 → bridgeobjects-0.1.28}/PKG-INFO +15 -6
  2. bridgeobjects-0.1.28/bridgeobjects/_version.py +1 -0
  3. {bridgeobjects-0.1.26 → bridgeobjects-0.1.28}/bridgeobjects/src/_create_pbn_string.py +2 -3
  4. {bridgeobjects-0.1.26 → bridgeobjects-0.1.28}/bridgeobjects/src/_file_constants.py +1 -1
  5. {bridgeobjects-0.1.26 → bridgeobjects-0.1.28}/bridgeobjects/src/_parse_pbn_string.py +13 -7
  6. {bridgeobjects-0.1.26 → bridgeobjects-0.1.28}/bridgeobjects/src/auction.py +7 -4
  7. {bridgeobjects-0.1.26 → bridgeobjects-0.1.28}/bridgeobjects/src/card.py +5 -3
  8. {bridgeobjects-0.1.26 → bridgeobjects-0.1.28}/bridgeobjects/src/hand.py +314 -247
  9. {bridgeobjects-0.1.26 → bridgeobjects-0.1.28}/bridgeobjects/src/suit_base.py +18 -12
  10. {bridgeobjects-0.1.26 → bridgeobjects-0.1.28}/bridgeobjects/tests/test_auctions.py +2 -2
  11. bridgeobjects-0.1.28/bridgeobjects/tests/test_data/lin_input_file_1.lin +33 -0
  12. bridgeobjects-0.1.28/bridgeobjects/tests/test_data/pbn_auction_1.pbn +47 -0
  13. bridgeobjects-0.1.28/bridgeobjects/tests/test_data/pbn_auction_2.pbn +47 -0
  14. bridgeobjects-0.1.28/bridgeobjects/tests/test_data/pbn_input_3.pbn +120 -0
  15. bridgeobjects-0.1.28/bridgeobjects/tests/test_data/pbn_input_file_1.pbn +1287 -0
  16. bridgeobjects-0.1.28/bridgeobjects/tests/test_data/pbn_output_file_1.pbn +29 -0
  17. bridgeobjects-0.1.28/bridgeobjects/tests/test_data/rbn_input_file_1.rbn +24 -0
  18. bridgeobjects-0.1.28/bridgeobjects/tests/test_data/rbn_output_file_1.rbn +124 -0
  19. {bridgeobjects-0.1.26 → bridgeobjects-0.1.28}/bridgeobjects/tests/test_hands.py +146 -79
  20. {bridgeobjects-0.1.26 → bridgeobjects-0.1.28}/bridgeobjects/tests/test_lin.py +3 -3
  21. {bridgeobjects-0.1.26 → bridgeobjects-0.1.28}/bridgeobjects/tests/test_pbn.py +18 -4
  22. {bridgeobjects-0.1.26 → bridgeobjects-0.1.28}/bridgeobjects/tests/test_rbn.py +4 -4
  23. {bridgeobjects-0.1.26 → bridgeobjects-0.1.28}/bridgeobjects.egg-info/PKG-INFO +15 -6
  24. {bridgeobjects-0.1.26 → bridgeobjects-0.1.28}/bridgeobjects.egg-info/SOURCES.txt +9 -2
  25. {bridgeobjects-0.1.26 → bridgeobjects-0.1.28}/setup.py +13 -3
  26. bridgeobjects-0.1.26/bridgeobjects/_version.py +0 -1
  27. bridgeobjects-0.1.26/bridgeobjects/scratch.py +0 -51
  28. {bridgeobjects-0.1.26 → bridgeobjects-0.1.28}/LICENSE.txt +0 -0
  29. {bridgeobjects-0.1.26 → bridgeobjects-0.1.28}/README.md +0 -0
  30. {bridgeobjects-0.1.26 → bridgeobjects-0.1.28}/bridgeobjects/__init__.py +0 -0
  31. {bridgeobjects-0.1.26 → bridgeobjects-0.1.28}/bridgeobjects/src/__init__.py +0 -0
  32. {bridgeobjects-0.1.26 → bridgeobjects-0.1.28}/bridgeobjects/src/_parse_lin_string.py +0 -0
  33. {bridgeobjects-0.1.26 → bridgeobjects-0.1.28}/bridgeobjects/src/_parse_rbn_string.py +0 -0
  34. {bridgeobjects-0.1.26 → bridgeobjects-0.1.28}/bridgeobjects/src/board.py +0 -0
  35. {bridgeobjects-0.1.26 → bridgeobjects-0.1.28}/bridgeobjects/src/call.py +0 -0
  36. {bridgeobjects-0.1.26 → bridgeobjects-0.1.28}/bridgeobjects/src/constants.py +0 -0
  37. {bridgeobjects-0.1.26 → bridgeobjects-0.1.28}/bridgeobjects/src/contract.py +0 -0
  38. {bridgeobjects-0.1.26 → bridgeobjects-0.1.28}/bridgeobjects/src/denomination.py +0 -0
  39. {bridgeobjects-0.1.26 → bridgeobjects-0.1.28}/bridgeobjects/src/event.py +0 -0
  40. {bridgeobjects-0.1.26 → bridgeobjects-0.1.28}/bridgeobjects/src/file_operations.py +0 -0
  41. {bridgeobjects-0.1.26 → bridgeobjects-0.1.28}/bridgeobjects/src/suit.py +0 -0
  42. {bridgeobjects-0.1.26 → bridgeobjects-0.1.28}/bridgeobjects/src/trick.py +0 -0
  43. {bridgeobjects-0.1.26 → bridgeobjects-0.1.28}/bridgeobjects/tests/__init__.py +0 -0
  44. {bridgeobjects-0.1.26 → bridgeobjects-0.1.28}/bridgeobjects/tests/test_boards.py +0 -0
  45. {bridgeobjects-0.1.26 → bridgeobjects-0.1.28}/bridgeobjects/tests/test_calls.py +0 -0
  46. {bridgeobjects-0.1.26 → bridgeobjects-0.1.28}/bridgeobjects/tests/test_cards.py +0 -0
  47. {bridgeobjects-0.1.26 → bridgeobjects-0.1.28}/bridgeobjects/tests/test_contracts.py +0 -0
  48. {bridgeobjects-0.1.26 → bridgeobjects-0.1.28}/bridgeobjects/tests/test_denominations.py +0 -0
  49. {bridgeobjects-0.1.26 → bridgeobjects-0.1.28}/bridgeobjects/tests/test_events.py +0 -0
  50. {bridgeobjects-0.1.26 → bridgeobjects-0.1.28}/bridgeobjects/tests/test_scores.py +0 -0
  51. {bridgeobjects-0.1.26 → bridgeobjects-0.1.28}/bridgeobjects/tests/test_suits.py +0 -0
  52. {bridgeobjects-0.1.26 → bridgeobjects-0.1.28}/bridgeobjects/tests/test_trick.py +0 -0
  53. {bridgeobjects-0.1.26 → bridgeobjects-0.1.28}/bridgeobjects.egg-info/dependency_links.txt +0 -0
  54. {bridgeobjects-0.1.26 → bridgeobjects-0.1.28}/bridgeobjects.egg-info/top_level.txt +0 -0
  55. {bridgeobjects-0.1.26 → bridgeobjects-0.1.28}/setup.cfg +0 -0
@@ -1,14 +1,13 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: bridgeobjects
3
- Version: 0.1.26
4
- Summary: A collection of modules that allows the user to access objects used in bridge games, for example, a board or a contract.
3
+ Version: 0.1.28
4
+ Summary: A collection of modules that allows the user to access objects used in bridge games,
5
5
  Home-page: https://psionman@bitbucket.org/psionman/bridgeobjects.git
6
+ Download-URL: https://pypi.org/project/bridgeobjects/
6
7
  Author: jeff watkins
7
8
  Author-email: support@bidforgame.com
8
9
  License: MIT
9
- Download-URL: https://pypi.org/project/bridgeobjects/
10
10
  Keywords: bridge, duplicate bridge, contract bridge, hand, board, suit, auction, contract, card
11
- Platform: UNKNOWN
12
11
  Description-Content-Type: text/markdown
13
12
  License-File: LICENSE.txt
14
13
 
@@ -43,9 +42,21 @@ pip install bridgeobjects
43
42
 
44
43
  # History
45
44
 
45
+ Version 0.1.28 01 Feb 2024
46
+
47
+ 1. Refactor hand
48
+ 2. File load pbn to handle BBO files
49
+
50
+ Version 0.1.27 7 Jan 2024
51
+
52
+ 1. Fix calls in Auction
53
+
54
+ ------
55
+
46
56
  Version 0.1.26 13 Oct 2023
47
57
 
48
58
  1. Add icecream
59
+
49
60
  ------
50
61
 
51
62
  Version 0.1.25 18 Sep 2023
@@ -342,5 +353,3 @@ Version 0.0.0 - August 2020
342
353
  Created and uploaded
343
354
 
344
355
  ---
345
-
346
-
@@ -0,0 +1 @@
1
+ __version__ = '0.1.28'
@@ -1,5 +1,4 @@
1
1
  """Processes to create a pbn event."""
2
- import os
3
2
 
4
3
  from .event import Event
5
4
  from .board import Board
@@ -16,7 +15,7 @@ def create_pbn_event_list(events: list[Event], path: str = '') -> list[str]:
16
15
  output = []
17
16
  output = _append_pbn_header()
18
17
  if path:
19
- if not os.path.isfile(path):
18
+ if not path.is_file():
20
19
  output = _append_pbn_header()
21
20
  else:
22
21
  with open(path, 'r') as pbn_file:
@@ -267,7 +266,7 @@ def _create_rbn_names(board: Board) -> str:
267
266
 
268
267
  def _write_file(output: list[str], path: str, append: bool) -> bool:
269
268
  """Write the list 'output' to a text file defined by path."""
270
- if not os.path.isfile(path):
269
+ if not path.is_file():
271
270
  with open(path, 'w') as f_clear_pbn_file:
272
271
  f_clear_pbn_file.write('')
273
272
  try:
@@ -23,4 +23,4 @@ RBN_VERSION_TEXT = '% RBN version 3.2'
23
23
  RBN_CREATOR_TEXT = '% Created by bridgeobjects'
24
24
 
25
25
  DEFAULT_EVENT_NAME = 'BfG default event name'
26
- DEFAULT_EVENT_DATE = datetime.date(1980, 1, 1)
26
+ DEFAULT_EVENT_DATE = datetime.date(1980, 1, 1)
@@ -17,7 +17,7 @@ from ._file_constants import (PBN_CALL_CONVERSION, DEFAULT_EVENT_NAME,
17
17
 
18
18
  def parse_pbn(file_lines: list[str]) -> list[Event]:
19
19
  """Populate bridgeobjects objects from a pbn file."""
20
- current_name = None
20
+ current_event = None
21
21
  current_board_identifier = ""
22
22
  auction_state = False
23
23
  play_state = False
@@ -28,14 +28,16 @@ def parse_pbn(file_lines: list[str]) -> list[Event]:
28
28
  event = Event()
29
29
  board = Board()
30
30
  value = ''
31
+ dummy_event = 'Dummy event'
31
32
 
32
33
  for line in file_lines:
33
34
  if line:
34
35
  tag = ""
35
36
  if line.startswith("%"): # Comments
36
- pass
37
- elif line.startswith("[") or line.startswith("{"):
37
+ continue
38
+ if line.startswith("[") or line.startswith("{"):
38
39
  (tag, value) = _parse_pbn_line(line)
40
+
39
41
  if auction_state and tag != 'Note':
40
42
  auction_state = False
41
43
  elif play_state and tag != 'Note':
@@ -51,11 +53,15 @@ def parse_pbn(file_lines: list[str]) -> list[Event]:
51
53
  if tag == "Event":
52
54
  if not value:
53
55
  value = str(uuid.uuid1()) # Dummy event
54
- if current_name != value:
55
- current_name = value
56
+ value = DEFAULT_EVENT_NAME
57
+ # ic(f'{DEFAULT_EVENT_NAME=}')
58
+ if current_event != value:
59
+ current_event = value
56
60
  current_board_identifier = ""
57
61
  board_index = 0
58
- if value and value != DEFAULT_EVENT_NAME:
62
+ # if value and value != DEFAULT_EVENT_NAME:
63
+ if value:
64
+ ic(value)
59
65
  event = Event(str(value))
60
66
  events.append(event)
61
67
 
@@ -191,7 +197,7 @@ def parse_pbn(file_lines: list[str]) -> list[Event]:
191
197
 
192
198
  def _parse_pbn_line(line: str) -> tuple[str, str]:
193
199
  """Return the tag and value from a pbn text line."""
194
- # example pbn line: [Site "Amsterdam, The Netherlands NLD"]
200
+ # example pbn line: [Vulnerable "None"]
195
201
  line = line.strip()
196
202
  space_at = line.find(' ')
197
203
  tag = line[1:space_at]
@@ -2,6 +2,7 @@
2
2
  The Auction class represents an auction for a Board.
3
3
  """
4
4
  import json
5
+ from collections import defaultdict
5
6
 
6
7
  __all__ = ['Auction']
7
8
 
@@ -26,7 +27,8 @@ class Auction(object):
26
27
  First call for the auction (Generally implemented by a rich PBN file)
27
28
  """
28
29
 
29
- def __init__(self, calls: list[Call] | None = None, first_caller: str | int = ''):
30
+ def __init__(self, calls: list[Call] | None = None,
31
+ first_caller: str | int = ''):
30
32
  """Create an auction with the given calls and first_caller."""
31
33
  self._initialise(calls, first_caller)
32
34
 
@@ -124,7 +126,7 @@ class Auction(object):
124
126
 
125
127
  def _get_seat_calls(self) -> dict[str, list[Call]]:
126
128
  """Return a dict of calls by seat."""
127
- seat_calls = {seat: [] for seat in SEATS}
129
+ seat_calls = defaultdict(list)
128
130
  if not self._first_caller:
129
131
  return seat_calls
130
132
 
@@ -132,7 +134,8 @@ class Auction(object):
132
134
  seat_index = self._first_caller
133
135
  else:
134
136
  seat_index = SEATS.index(self._first_caller)
135
- for call in self.calls:
137
+
138
+ for call in self._calls:
136
139
  seat_calls[SEATS[seat_index]].append(call)
137
140
  seat_index += 1
138
141
  seat_index %= 4
@@ -141,7 +144,7 @@ class Auction(object):
141
144
  def to_json(self):
142
145
  """Return a json representation of the class."""
143
146
  context = {
144
- 'calls': [call.name for call in self.calls],
147
+ 'calls': [call.name for call in self._calls],
145
148
  'first_caller': self.first_caller,
146
149
  }
147
150
  return json.dumps(context)
@@ -42,11 +42,12 @@ class Card(object):
42
42
  def __init__(self, name: str, suit_name: str | None = None):
43
43
  """Create the card class."""
44
44
  if suit_name:
45
- name = ''.join([name, suit_name])
45
+ name = name + suit_name
46
46
  if name[:2] == '10':
47
47
  name = f'T{name[2]}'
48
48
  if len(name) != 2:
49
- raise ValueError(f'Card name must contain precisely 2 characters: "{name}"')
49
+ err_msg = 'Card name must contain precisely 2 characters'
50
+ raise ValueError(f'{err_msg}: "{name}"')
50
51
  elif name[0] not in RANKS:
51
52
  raise ValueError(f'Invalid rank in card: "{name}"')
52
53
  elif name[1] not in SUIT_NAMES:
@@ -147,7 +148,8 @@ class Card(object):
147
148
  def suit(self) -> Suit:
148
149
  """
149
150
  The card's suit.
150
- Returns the card's suit (e.g. the object Spades() for spades as a Suit instance.
151
+ Returns the card's suit
152
+ (e.g. the object Spades() for spades as a Suit instance).
151
153
  """
152
154
  return self._suit
153
155