summaryrefslogtreecommitdiff
path: root/dealconvert/formats
diff options
context:
space:
mode:
Diffstat (limited to 'dealconvert/formats')
-rw-r--r--dealconvert/formats/__init__.py4
-rw-r--r--dealconvert/formats/cds.py2
-rw-r--r--dealconvert/formats/dup.py2
-rw-r--r--dealconvert/formats/pbn.py31
4 files changed, 29 insertions, 10 deletions
diff --git a/dealconvert/formats/__init__.py b/dealconvert/formats/__init__.py
index 9c37cf9..cdd8703 100644
--- a/dealconvert/formats/__init__.py
+++ b/dealconvert/formats/__init__.py
@@ -3,6 +3,10 @@ import glob
class DealFormat(object):
cards = 'AKQJT98765432'
+
+ def __init__(self, interactive=True):
+ self.interactive = interactive
+
def parse(self, input_file):
with open(input_file, 'rb') as content:
return self.parse_content(content)
diff --git a/dealconvert/formats/cds.py b/dealconvert/formats/cds.py
index f624612..c7eeb5a 100644
--- a/dealconvert/formats/cds.py
+++ b/dealconvert/formats/cds.py
@@ -9,7 +9,7 @@ class CDSFormat(DealFormat):
def suffix(self):
return '.cds'
- def __init__(self):
+ def __init__(self, interactive=True):
self.rzd_format = RZDFormat()
def parse_content(self, content):
diff --git a/dealconvert/formats/dup.py b/dealconvert/formats/dup.py
index 1a2e1ba..19dca0f 100644
--- a/dealconvert/formats/dup.py
+++ b/dealconvert/formats/dup.py
@@ -10,7 +10,7 @@ class DUPFormat(DealFormat):
def suffix(self):
return '.dup'
- def __init__(self):
+ def __init__(self, interactive=True):
self.bri = BRIFormat()
self.dge = DGEFormat()
diff --git a/dealconvert/formats/pbn.py b/dealconvert/formats/pbn.py
index ead8fdd..bc52462 100644
--- a/dealconvert/formats/pbn.py
+++ b/dealconvert/formats/pbn.py
@@ -1,4 +1,8 @@
-import re
+import re, sys, warnings
+
+from bcdd.PBNBoard import PBNBoard
+from bcdd.DDTable import DDTable
+from bcdd.ParScore import ParScore
from . import DealFormat
from .. import dto
@@ -115,21 +119,32 @@ class PBNFormat(DealFormat):
def output_content(self, out_file, dealset):
for board in dealset:
- out_file.write('[Event "%s"]\r\n' % (board.event))
- out_file.write('[Board "%d"]\r\n' % (board.number))
- out_file.write('[Dealer "%s"]\r\n' % (
+ lines = []
+ lines.append('[Event "%s"]' % (board.event))
+ lines.append('[Board "%d"]' % (board.number))
+ lines.append('[Dealer "%s"]' % (
'NESW'[board.dealer]
))
- out_file.write('[Vulnerable "%s"]\r\n' % (
+ lines.append('[Vulnerable "%s"]' % (
('All' if board.vulnerable['EW'] else 'NS') if
board.vulnerable['NS'] else
('EW' if board.vulnerable['EW'] else 'None')
))
- out_file.write('[Deal "N:%s"]\r\n' % (
+ lines.append('[Deal "N:%s"]' % (
' '.join([
'.'.join([''.join(suit) for suit in hand])
for hand in board.hands
])))
for field in board.extra_fields:
- out_file.write(field + '\r\n')
- out_file.write('\r\n')
+ lines.append(field)
+ try:
+ dd_board = PBNBoard(lines)
+ dd_table = DDTable(dd_board).get_dd_table(self.interactive)
+ dd_contract = ParScore(dd_board).get_par_contract(dd_table)
+ dd_board.save_dd_table(dd_table)
+ dd_board.save_par_contract(dd_contract)
+ lines = [field.raw_field for field in dd_board.fields]
+ except Exception as e:
+ warnings.warn('unable to determine double-dummy data: %s' % e)
+ for line in lines + ['']:
+ out_file.write(line + '\r\n')