summaryrefslogtreecommitdiff
path: root/dealconvert/formats
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2019-05-21 00:47:36 +0200
committeremkael <emkael@tlen.pl>2019-05-21 00:47:36 +0200
commitd10d3dd8967c76ce34d61bf2ea980487549de4d8 (patch)
tree1e12fe67ead5da89f9905f545adeb9d392eb38d6 /dealconvert/formats
parenteee3954a793379611684ac01b1a4f217a16048d7 (diff)
BER format support
Diffstat (limited to 'dealconvert/formats')
-rw-r--r--dealconvert/formats/ber.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/dealconvert/formats/ber.py b/dealconvert/formats/ber.py
index 0303407..66c289e 100644
--- a/dealconvert/formats/ber.py
+++ b/dealconvert/formats/ber.py
@@ -1,6 +1,44 @@
from . import DealFormat
+from .. import dto
class BERFormat(DealFormat):
+ number_warning = 'WARNING: .ber file format assumes consequent deal numbers from 1'
+ cards = 'AKQJT98765432'
+
@property
def suffix(self):
return '.ber'
+
+ def parse_content(self, content):
+ print self.number_warning
+ dealset = []
+ number = 1
+ while True:
+ deal_str = content.read(52)
+ if len(deal_str) > 0:
+ if len(deal_str) < 52:
+ print 'WARNING: truncated .ber input: %s' % (deal_str)
+ break
+ deal = dto.Deal()
+ deal.number = number
+ deal.dealer = deal.get_dealer(number)
+ deal.vulnerable = deal.get_vulnerability(number)
+ for suit in range(0, 4):
+ for card in range(0, 13):
+ deal.hands[int(deal_str[suit*13 + card])-1][suit].append(self.cards[card])
+ dealset.append(deal)
+ number += 1
+ else:
+ break
+ return dealset
+
+
+ def output_content(self, out_file, dealset):
+ print self.number_warning
+ for board in dealset:
+ deal_str = [''] * 52
+ for i, hand in enumerate(board.hands):
+ for j, suit in enumerate(hand):
+ for card in suit:
+ deal_str[j*13 + self.cards.index(card)] = str(i + 1)
+ out_file.write(''.join(deal_str))