bridgeobjects 0.1.31__tar.gz → 0.1.33__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.
- {bridgeobjects-0.1.31 → bridgeobjects-0.1.33}/PKG-INFO +8 -9
- bridgeobjects-0.1.33/pyproject.toml +24 -0
- bridgeobjects-0.1.33/pyproject.toml.orig +29 -0
- {bridgeobjects-0.1.31 → bridgeobjects-0.1.33/src}/bridgeobjects/__init__.py +8 -7
- bridgeobjects-0.1.33/src/bridgeobjects/_create_pbn_string.py +212 -0
- bridgeobjects-0.1.33/src/bridgeobjects/_create_rbn_string.py +76 -0
- {bridgeobjects-0.1.31 → bridgeobjects-0.1.33/src}/bridgeobjects/_parse_lin_string.py +0 -3
- bridgeobjects-0.1.33/src/bridgeobjects/_parse_pbn_string.py +323 -0
- {bridgeobjects-0.1.31 → bridgeobjects-0.1.33/src}/bridgeobjects/_parse_rbn_string.py +75 -70
- bridgeobjects-0.1.33/src/bridgeobjects/_version.py +1 -0
- {bridgeobjects-0.1.31 → bridgeobjects-0.1.33/src}/bridgeobjects/board.py +135 -98
- bridgeobjects-0.1.33/src/bridgeobjects/constants.py +402 -0
- {bridgeobjects-0.1.31 → bridgeobjects-0.1.33/src}/bridgeobjects/contract.py +2 -4
- {bridgeobjects-0.1.31 → bridgeobjects-0.1.33/src}/bridgeobjects/event.py +34 -24
- {bridgeobjects-0.1.31 → bridgeobjects-0.1.33/src}/bridgeobjects/file_operations.py +11 -26
- {bridgeobjects-0.1.31 → bridgeobjects-0.1.33/src}/bridgeobjects/hand.py +169 -120
- bridgeobjects-0.1.33/src/bridgeobjects/tests/test_auctions.py +101 -0
- bridgeobjects-0.1.33/src/bridgeobjects/tests/test_boards.py +580 -0
- bridgeobjects-0.1.33/src/bridgeobjects/tests/test_calls.py +242 -0
- bridgeobjects-0.1.33/src/bridgeobjects/tests/test_cards.py +185 -0
- bridgeobjects-0.1.33/src/bridgeobjects/tests/test_contracts.py +151 -0
- bridgeobjects-0.1.33/src/bridgeobjects/tests/test_data/lin_input_file_1.lin +33 -0
- bridgeobjects-0.1.33/src/bridgeobjects/tests/test_data/pbn_auction_1.pbn +47 -0
- bridgeobjects-0.1.33/src/bridgeobjects/tests/test_data/pbn_auction_2.pbn +47 -0
- bridgeobjects-0.1.33/src/bridgeobjects/tests/test_data/pbn_input_3.pbn +120 -0
- bridgeobjects-0.1.33/src/bridgeobjects/tests/test_data/pbn_input_file_1.pbn +1287 -0
- bridgeobjects-0.1.33/src/bridgeobjects/tests/test_data/pbn_output_file_1.pbn +22 -0
- bridgeobjects-0.1.33/src/bridgeobjects/tests/test_data/rbn_input_file_1.rbn +24 -0
- bridgeobjects-0.1.33/src/bridgeobjects/tests/test_data/rbn_output_file_1.rbn +124 -0
- bridgeobjects-0.1.33/src/bridgeobjects/tests/test_denominations.py +139 -0
- bridgeobjects-0.1.33/src/bridgeobjects/tests/test_events.py +66 -0
- bridgeobjects-0.1.33/src/bridgeobjects/tests/test_hands.py +946 -0
- bridgeobjects-0.1.33/src/bridgeobjects/tests/test_lin.py +218 -0
- bridgeobjects-0.1.33/src/bridgeobjects/tests/test_pbn.py +237 -0
- bridgeobjects-0.1.33/src/bridgeobjects/tests/test_rbn.py +218 -0
- bridgeobjects-0.1.33/src/bridgeobjects/tests/test_scores.py +460 -0
- bridgeobjects-0.1.33/src/bridgeobjects/tests/test_suits.py +134 -0
- bridgeobjects-0.1.33/src/bridgeobjects/tests/test_trick.py +61 -0
- bridgeobjects-0.1.31/HISTORY.md +0 -332
- bridgeobjects-0.1.31/LICENSE.txt +0 -650
- bridgeobjects-0.1.31/bridgeobjects/_create_pbn_string.py +0 -283
- bridgeobjects-0.1.31/bridgeobjects/_parse_pbn_string.py +0 -302
- bridgeobjects-0.1.31/bridgeobjects/_version.py +0 -1
- bridgeobjects-0.1.31/bridgeobjects/constants.py +0 -271
- bridgeobjects-0.1.31/bridgeobjects/src/.vscode/settings.json +0 -4
- bridgeobjects-0.1.31/pyproject.toml +0 -15
- {bridgeobjects-0.1.31 → bridgeobjects-0.1.33}/README.md +0 -0
- {bridgeobjects-0.1.31 → bridgeobjects-0.1.33/src}/bridgeobjects/_file_constants.py +0 -0
- {bridgeobjects-0.1.31 → bridgeobjects-0.1.33/src}/bridgeobjects/auction.py +0 -0
- {bridgeobjects-0.1.31 → bridgeobjects-0.1.33/src}/bridgeobjects/call.py +0 -0
- {bridgeobjects-0.1.31 → bridgeobjects-0.1.33/src}/bridgeobjects/card.py +0 -0
- {bridgeobjects-0.1.31 → bridgeobjects-0.1.33/src}/bridgeobjects/denomination.py +0 -0
- {bridgeobjects-0.1.31 → bridgeobjects-0.1.33/src}/bridgeobjects/suit.py +0 -0
- {bridgeobjects-0.1.31 → bridgeobjects-0.1.33/src}/bridgeobjects/suit_base.py +0 -0
- {bridgeobjects-0.1.31/bridgeobjects/src → bridgeobjects-0.1.33/src/bridgeobjects/tests}/__init__.py +0 -0
- {bridgeobjects-0.1.31 → bridgeobjects-0.1.33/src}/bridgeobjects/trick.py +0 -0
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: bridgeobjects
|
|
3
|
-
Version: 0.1.
|
|
4
|
-
Summary:
|
|
3
|
+
Version: 0.1.33
|
|
4
|
+
Summary: Objects used in bridge games, for example, board, hand, bid or a contract.
|
|
5
5
|
Author: Jeff
|
|
6
|
-
Author-email: jeffwatkins2000@gmail.com
|
|
7
|
-
Requires-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
Author-email: Jeff <<jeffwatkins2000@gmail.com>>
|
|
7
|
+
Requires-Dist: iniconfig>=2.1.0
|
|
8
|
+
Requires-Dist: packaging>=25.0
|
|
9
|
+
Requires-Dist: pluggy>=1.6.0
|
|
10
|
+
Requires-Dist: pygments>=2.19.2
|
|
11
|
+
Requires-Python: ==3.13.*
|
|
12
12
|
Description-Content-Type: text/markdown
|
|
13
13
|
|
|
14
14
|
# bridgeobjects
|
|
@@ -38,4 +38,3 @@ Richard’s Bridge Notation (RBN) (http://www.rpbridge.net/7a12.htm).
|
|
|
38
38
|
```bash
|
|
39
39
|
pip install bridgeobjects
|
|
40
40
|
```
|
|
41
|
-
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "bridgeobjects"
|
|
3
|
+
version = "0.1.33"
|
|
4
|
+
requires-python = "==3.13.*"
|
|
5
|
+
description = "Objects used in bridge games, for example, board, hand, bid or a contract."
|
|
6
|
+
readme = "README.md"
|
|
7
|
+
include = ["HISTORY.md"]
|
|
8
|
+
dependencies = [
|
|
9
|
+
"iniconfig>=2.1.0",
|
|
10
|
+
"packaging>=25.0",
|
|
11
|
+
"pluggy>=1.6.0",
|
|
12
|
+
"pygments>=2.19.2",
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
[[project.authors]]
|
|
16
|
+
name = "Jeff"
|
|
17
|
+
email = "<jeffwatkins2000@gmail.com>"
|
|
18
|
+
|
|
19
|
+
[dependency-groups]
|
|
20
|
+
dev = ["pytest"]
|
|
21
|
+
|
|
22
|
+
[build-system]
|
|
23
|
+
requires = ["uv-build"]
|
|
24
|
+
build-backend = "uv_build"
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "bridgeobjects"
|
|
3
|
+
version = "0.1.33"
|
|
4
|
+
requires-python = "==3.13.*"
|
|
5
|
+
description = "Objects used in bridge games, for example, board, hand, bid or a contract."
|
|
6
|
+
authors = [
|
|
7
|
+
{ name = "Jeff", email = "<jeffwatkins2000@gmail.com>" },
|
|
8
|
+
]
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
include = [
|
|
11
|
+
"HISTORY.md",
|
|
12
|
+
]
|
|
13
|
+
dependencies = [
|
|
14
|
+
"iniconfig>=2.1.0",
|
|
15
|
+
"packaging>=25.0",
|
|
16
|
+
"pluggy>=1.6.0",
|
|
17
|
+
"pygments>=2.19.2",
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
[dependency-groups]
|
|
21
|
+
dev = [
|
|
22
|
+
"pytest",
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
[build-system]
|
|
26
|
+
requires = [
|
|
27
|
+
"uv-build",
|
|
28
|
+
]
|
|
29
|
+
build-backend = "uv_build"
|
|
@@ -4,22 +4,23 @@
|
|
|
4
4
|
The bridgeobjects package exposes the following classes:
|
|
5
5
|
(inspect the individual modules to see their APIs):
|
|
6
6
|
|
|
7
|
-
constants: various constants used throughout the package,
|
|
7
|
+
constants: various constants used throughout the package,
|
|
8
|
+
e.g. SEATS = ['N', 'E', 'S', 'W'];
|
|
8
9
|
board: represents a board of 4 hands;
|
|
9
|
-
hand: holds the 13 cards dealt to
|
|
10
|
+
hand: holds the 13 cards dealt to the hand;
|
|
10
11
|
card: a single card in a hand, board or trick;
|
|
11
12
|
suit: one of Spades, Hearts, Clubs or diamonds;
|
|
12
|
-
denomination: the name of a call in the auction or contract,
|
|
13
|
+
denomination: the name of a call in the auction or contract,
|
|
14
|
+
it includes the four suits and NT;
|
|
13
15
|
auction: the calls made on a particular board
|
|
14
16
|
contract: the contract reach on a board;
|
|
15
17
|
call: an individual call made to reach a contract
|
|
16
18
|
event: the match or competition at which the boards are played:
|
|
17
19
|
trick: four cards played which one pair wins:
|
|
18
|
-
file_operations: a module to load or save events in a PBN,
|
|
20
|
+
file_operations: a module to load or save events in a PBN,
|
|
21
|
+
RBN or LIN format.
|
|
19
22
|
"""
|
|
20
|
-
|
|
21
|
-
# ic.configureOutput(includeContext=True)
|
|
22
|
-
# install()
|
|
23
|
+
|
|
23
24
|
|
|
24
25
|
from bridgeobjects.constants import *
|
|
25
26
|
from bridgeobjects.board import *
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
"""Processes to create a pbn event."""
|
|
2
|
+
from typing import TYPE_CHECKING
|
|
3
|
+
if TYPE_CHECKING:
|
|
4
|
+
from .board import Board
|
|
5
|
+
|
|
6
|
+
from .event import Event
|
|
7
|
+
from .constants import SUIT_NAMES, RANKS, SEATS
|
|
8
|
+
from ._file_constants import (PBN_VULNERABILITY_CONVERSION,
|
|
9
|
+
PBN_CALL_CONVERSION,
|
|
10
|
+
PBN_VERSION_TEXT, PBN_FORMAT_TEXT,
|
|
11
|
+
PBN_CONTENT_TEXT, PBN_CREATOR_TEXT,
|
|
12
|
+
RBN_VERSION_TEXT, RBN_CREATOR_TEXT)
|
|
13
|
+
|
|
14
|
+
PBN_DATE_FORMAT = '%Y.%m.%d'
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def create_pbn_event_list(events: list[Event], path: str = '') -> list[str]:
|
|
18
|
+
"""Create a list of strings for events in pbn format."""
|
|
19
|
+
output = []
|
|
20
|
+
output = _append_pbn_header()
|
|
21
|
+
if path:
|
|
22
|
+
if not path.is_file():
|
|
23
|
+
output = _append_pbn_header()
|
|
24
|
+
else:
|
|
25
|
+
with open(path, 'r') as pbn_file:
|
|
26
|
+
for line in pbn_file.readlines():
|
|
27
|
+
line = line.replace('\n', '')
|
|
28
|
+
if len(line.replace(' ', '')) > 0 and line[1] != '%':
|
|
29
|
+
output = _append_pbn_header()
|
|
30
|
+
break
|
|
31
|
+
contents = pbn_file.readlines()
|
|
32
|
+
if len(contents) == 0:
|
|
33
|
+
output = _append_pbn_header()
|
|
34
|
+
|
|
35
|
+
for event in events:
|
|
36
|
+
output.extend(_create_pbn_event(event))
|
|
37
|
+
return output
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _create_pbn_event(event: Event) -> list[str]:
|
|
41
|
+
"""Return an event as string in pbn format as a list."""
|
|
42
|
+
# output = [f'[Event "{event.name}"]', f'[Site "{event.site}"]']
|
|
43
|
+
# print(f"a {event=} {output}")
|
|
44
|
+
# if event.date:
|
|
45
|
+
# event_date = event.date.strftime(PBN_DATE_FORMAT)
|
|
46
|
+
# output.append(f'[Date "{event_date}"]')
|
|
47
|
+
# output.append('')
|
|
48
|
+
output = []
|
|
49
|
+
for board in event.boards:
|
|
50
|
+
output.extend(_create_pbn_board_list(board, event))
|
|
51
|
+
return output
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def _append_pbn_header() -> list[str]:
|
|
55
|
+
"""Create a list containing the pbn file header."""
|
|
56
|
+
return [
|
|
57
|
+
PBN_VERSION_TEXT,
|
|
58
|
+
PBN_FORMAT_TEXT,
|
|
59
|
+
PBN_CONTENT_TEXT,
|
|
60
|
+
PBN_CREATOR_TEXT,
|
|
61
|
+
'',
|
|
62
|
+
]
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def create_pbn_board(board: "Board") -> str:
|
|
66
|
+
board_list = _create_pbn_board_list(board)
|
|
67
|
+
return '\n'.join(board_list)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def _create_pbn_board_list(board: "Board", event: Event = None) -> list[str]:
|
|
71
|
+
"""Return a board as a list of strings in pbn format."""
|
|
72
|
+
mandatory_fields = {
|
|
73
|
+
# Mandatory fields - in this order
|
|
74
|
+
'Event': event,
|
|
75
|
+
'Site': board.site,
|
|
76
|
+
'Date': board.date.strftime(PBN_DATE_FORMAT),
|
|
77
|
+
'Board': board.number,
|
|
78
|
+
'West': board.west,
|
|
79
|
+
'North': board.north,
|
|
80
|
+
'East': board.east,
|
|
81
|
+
'South': board.south,
|
|
82
|
+
'Dealer': board.dealer,
|
|
83
|
+
'Vulnerable': board.vulnerable.replace("Both", "All"),
|
|
84
|
+
'Deal': f"{board.dealer}:{get_pbn_deal(board)}",
|
|
85
|
+
'Scoring': '?',
|
|
86
|
+
'Declarer': _question_from_null(board.contract.declarer),
|
|
87
|
+
'Contract': _handle_contract(board),
|
|
88
|
+
'Result': _question_from_null(board.result),
|
|
89
|
+
|
|
90
|
+
'Auction': _create_pbn_auction(board),
|
|
91
|
+
'Play': _create_pbn_play_section(board)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
optional_fields = {
|
|
95
|
+
# Optional fields - alphabetically
|
|
96
|
+
'DealId': board.deal_id,
|
|
97
|
+
'Description': board.description,
|
|
98
|
+
# 'EventDate': board.event.date,
|
|
99
|
+
# 'Generator': board.generator,
|
|
100
|
+
# 'Tag': board.tag,
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
output = []
|
|
104
|
+
output.extend(
|
|
105
|
+
f'[{field} "{value}"]' for field, value in mandatory_fields.items()
|
|
106
|
+
)
|
|
107
|
+
output.extend(
|
|
108
|
+
f'[{field} "{value}"]'
|
|
109
|
+
for field, value in optional_fields.items() if value
|
|
110
|
+
)
|
|
111
|
+
output.append('')
|
|
112
|
+
return output
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def _handle_contract(board: "Board") -> str:
|
|
116
|
+
if board.contract.declarer and board.contract.denomination:
|
|
117
|
+
denomination = board.contract.denomination.name
|
|
118
|
+
if result := board.optimum_result_table[board.contract.declarer][
|
|
119
|
+
denomination
|
|
120
|
+
]:
|
|
121
|
+
board.result = result
|
|
122
|
+
return _question_from_null(board.contract.call.name)
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def _question_from_null(value: str) -> str:
|
|
126
|
+
"""Return a question mark if value is None or ''."""
|
|
127
|
+
return value or "?"
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def get_pbn_deal(board: "Board", delimiter: str = ' ') -> str:
|
|
131
|
+
"""Return a board's hands as a string in pbn format."""
|
|
132
|
+
hands_list = []
|
|
133
|
+
if board.dealer not in SEATS:
|
|
134
|
+
return []
|
|
135
|
+
dealer_index = SEATS.index(board.dealer)
|
|
136
|
+
for index in range(4):
|
|
137
|
+
seat = (dealer_index + index) % 4
|
|
138
|
+
hand = board.hands[seat]
|
|
139
|
+
hand_list = []
|
|
140
|
+
for suit_name in reversed(SUIT_NAMES):
|
|
141
|
+
suit_cards = []
|
|
142
|
+
for rank in reversed(RANKS[1:]):
|
|
143
|
+
suit_cards.extend(
|
|
144
|
+
card.rank
|
|
145
|
+
for card in hand.cards
|
|
146
|
+
if card.name == ''.join([rank, suit_name])
|
|
147
|
+
)
|
|
148
|
+
hand_list.append(''.join(suit_cards))
|
|
149
|
+
hands_list.append('.'.join(hand_list))
|
|
150
|
+
return delimiter.join(hands_list)
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def _create_pbn_auction(board: "Board") -> list[str]:
|
|
154
|
+
"""Return an auction as a pbn list."""
|
|
155
|
+
auction_list = [f'[Auction "{board.dealer}"]']
|
|
156
|
+
"""
|
|
157
|
+
See PBN Spec at https://tistis.nl/pbn/
|
|
158
|
+
|
|
159
|
+
In import format the player in the Auction tag value need not be
|
|
160
|
+
the dealer. For example, the calls are given in a table
|
|
161
|
+
of 4 columns with West in the first column. In that case, each
|
|
162
|
+
player before the dealer has a hyphen ("-") in the
|
|
163
|
+
first auction line.
|
|
164
|
+
|
|
165
|
+
In this case, the player will be the dealer
|
|
166
|
+
"""
|
|
167
|
+
line = []
|
|
168
|
+
for call in board.auction.calls:
|
|
169
|
+
if call.name in PBN_CALL_CONVERSION:
|
|
170
|
+
pbn_call = PBN_CALL_CONVERSION[call.name]
|
|
171
|
+
else:
|
|
172
|
+
pbn_call = call.name
|
|
173
|
+
line.append(pbn_call)
|
|
174
|
+
if len(line) == 4:
|
|
175
|
+
auction_list.append(' '.join(list(line)))
|
|
176
|
+
line = []
|
|
177
|
+
auction_list.append(' '.join(list(line)))
|
|
178
|
+
return auction_list
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
def _create_pbn_play_section(board: "Board") -> list[str]:
|
|
182
|
+
"""Return board's tricks as a pbn list."""
|
|
183
|
+
if not board.tricks:
|
|
184
|
+
return []
|
|
185
|
+
|
|
186
|
+
trick_list = [f'[Play "{board.tricks[0].leader}"]']
|
|
187
|
+
for trick in board.tricks:
|
|
188
|
+
if trick.leader:
|
|
189
|
+
line = []
|
|
190
|
+
for index, card in enumerate(trick.cards):
|
|
191
|
+
if card:
|
|
192
|
+
line.append(''.join([card.name[1], card.name[0]]))
|
|
193
|
+
if trick.note_keys[index]:
|
|
194
|
+
line.append(f'={trick.note_keys[index]}=')
|
|
195
|
+
trick_list.append(' '.join(list(line)))
|
|
196
|
+
return trick_list
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def _write_file(output: list[str], path: str, append: bool) -> bool:
|
|
200
|
+
"""Write the list 'output' to a text file defined by path."""
|
|
201
|
+
if not path.is_file():
|
|
202
|
+
with open(path, 'w') as f_clear_pbn_file:
|
|
203
|
+
f_clear_pbn_file.write('')
|
|
204
|
+
try:
|
|
205
|
+
mode = 'a' if append else 'w'
|
|
206
|
+
with open(path, mode) as f_pbn_file:
|
|
207
|
+
f_pbn_file.write('\n'.join(output))
|
|
208
|
+
return True
|
|
209
|
+
except FileNotFoundError as error:
|
|
210
|
+
error_text = f'invalid file path: {path}. File not written'
|
|
211
|
+
raise FileNotFoundError(error_text) from error
|
|
212
|
+
return False
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
|
|
2
|
+
from .event import Event
|
|
3
|
+
from ._file_constants import (PBN_VULNERABILITY_CONVERSION,
|
|
4
|
+
PBN_CALL_CONVERSION,
|
|
5
|
+
PBN_VERSION_TEXT, PBN_FORMAT_TEXT,
|
|
6
|
+
PBN_CONTENT_TEXT, PBN_CREATOR_TEXT,
|
|
7
|
+
RBN_VERSION_TEXT, RBN_CREATOR_TEXT)
|
|
8
|
+
|
|
9
|
+
from ._create_pbn_string import get_pbn_deal
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def create_rbn_list(events: list[Event]) -> list[str]:
|
|
13
|
+
"""Create a list of strings for events in rbn format."""
|
|
14
|
+
output = [RBN_VERSION_TEXT, RBN_CREATOR_TEXT]
|
|
15
|
+
for event in events:
|
|
16
|
+
output.extend(_create_rbn_event(event))
|
|
17
|
+
return output
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _create_rbn_event(event: Event) -> list[str]:
|
|
21
|
+
"""Return an event as string in rbn format as a list."""
|
|
22
|
+
output = [f'E {event.name}', f'L {event.site}']
|
|
23
|
+
if event.date:
|
|
24
|
+
event_date = event.date.strftime('%Y%m%d')
|
|
25
|
+
output.append(f'D {event_date}')
|
|
26
|
+
output.append(f'M {_question_from_null(event.scoring_method)}')
|
|
27
|
+
for board in event.boards:
|
|
28
|
+
output.extend(_create_rbn_board(board))
|
|
29
|
+
return output
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def _create_rbn_board(board: "Board") -> list[str]:
|
|
33
|
+
"""Return a board as a list of strings in pbn format."""
|
|
34
|
+
output = [f'B {board.number}']
|
|
35
|
+
|
|
36
|
+
if names := _create_rbn_names(board):
|
|
37
|
+
output.append(f'N {names}')
|
|
38
|
+
|
|
39
|
+
# hands
|
|
40
|
+
deal = get_pbn_deal(board, ':')
|
|
41
|
+
output.append(f'H {board.dealer}:{deal}')
|
|
42
|
+
|
|
43
|
+
# auction
|
|
44
|
+
vulnerable = PBN_VULNERABILITY_CONVERSION[board.vulnerable]
|
|
45
|
+
output.append(f'A {board.dealer}{vulnerable}:')
|
|
46
|
+
|
|
47
|
+
# contract
|
|
48
|
+
board_contract = _question_from_null(board.contract.name)
|
|
49
|
+
board_declarer = _question_from_null(board.declarer)
|
|
50
|
+
contract = ':'.join([board_contract, board_declarer])
|
|
51
|
+
if contract != "?:?":
|
|
52
|
+
output.append(f'C {contract}')
|
|
53
|
+
|
|
54
|
+
# result
|
|
55
|
+
result = _question_from_null(board.result)
|
|
56
|
+
if result != "?":
|
|
57
|
+
output.append('[R result')
|
|
58
|
+
output.append('')
|
|
59
|
+
return output
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def _create_rbn_names(board: "Board") -> str:
|
|
63
|
+
"""Return the boards players in rbn format."""
|
|
64
|
+
names = f'{board.north}+{board.south}:{board.west}+{board.east}'
|
|
65
|
+
if names == "+:+":
|
|
66
|
+
names = ""
|
|
67
|
+
if names[:3] == "+:":
|
|
68
|
+
names = names.replace("+:", ";")
|
|
69
|
+
if names[-3:] == ":+":
|
|
70
|
+
names = names.replace(":+", ";")
|
|
71
|
+
return names
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def _question_from_null(value: str) -> str:
|
|
75
|
+
"""Return a question mark if value is None or ''."""
|
|
76
|
+
return value or "?"
|
|
@@ -28,9 +28,6 @@ from .constants import SEATS
|
|
|
28
28
|
from ._file_constants import LIN_VULNERABILITY_CONVERSION
|
|
29
29
|
|
|
30
30
|
|
|
31
|
-
MODULE_COLOUR = 'red'
|
|
32
|
-
|
|
33
|
-
|
|
34
31
|
# TODO test for lin event
|
|
35
32
|
def parse_lin(file_text: list[str]) -> list[Event]:
|
|
36
33
|
"""Populate bridgeobjects objects from a lin file."""
|