summaryrefslogtreecommitdiff
path: root/dealconvert/formats/dge.py
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2019-05-22 00:39:06 +0200
committeremkael <emkael@tlen.pl>2019-05-22 00:39:06 +0200
commite227c0167081b62fd9689e3f965fcb8dcfa3bc9d (patch)
treec315e224ddd243565b669f24e8f5224a285b34e3 /dealconvert/formats/dge.py
parent768c601f9d99cfd3712a3531a74b48b0d2719820 (diff)
Factoring out BRI and DGE formats, as they're part of DUP format
Diffstat (limited to 'dealconvert/formats/dge.py')
-rw-r--r--dealconvert/formats/dge.py51
1 files changed, 30 insertions, 21 deletions
diff --git a/dealconvert/formats/dge.py b/dealconvert/formats/dge.py
index 21d3044..93eb971 100644
--- a/dealconvert/formats/dge.py
+++ b/dealconvert/formats/dge.py
@@ -37,35 +37,44 @@ class DGEFormat(DealFormat):
deal.number = number
deal.dealer = deal.get_dealer(number)
deal.vulnerable = deal.get_vulnerability(number)
- hand = 0
- suit_count = -1
- suit = None
- for char in deal_str[0:68]:
- if char in self.suits:
- suit = self.suits[char]
- suit_count += 1
- if suit_count == 4:
- suit_count = 0
- hand += 1
- else:
- if suit is None:
- print 'ERROR: invalid .dge line: %s' % (deal_str)
- sys.exit()
- else:
- deal.hands[hand][suit].append(char)
+ deal.hands = self.parse_hands(deal_str[0:68])
dealset.append(deal)
number += 1
else:
break
return dealset
+ def parse_hands(self, deal_str):
+ deal = dto.Deal()
+ hand = 0
+ suit_count = -1
+ suit = None
+ for char in deal_str[0:68]:
+ if char in self.suits:
+ suit = self.suits[char]
+ suit_count += 1
+ if suit_count == 4:
+ suit_count = 0
+ hand += 1
+ else:
+ if suit is None:
+ print 'ERROR: invalid .dge line: %s' % (deal_str)
+ sys.exit()
+ else:
+ deal.hands[hand][suit].append(char)
+ return deal.hands
+
def output_content(self, out_file, dealset):
print self.number_warning
for deal in dealset:
- deal_str = ''
- for hand in deal.hands:
- for suit, cards in enumerate(hand):
- deal_str += self.suit_indicator(suit)
- deal_str += ''.join(cards)
+ deal_str = self.single_deal_output(deal)
deal_str += chr(0) * 60
out_file.write(deal_str)
+
+ def single_deal_output(self, deal):
+ deal_str = ''
+ for hand in deal.hands:
+ for suit, cards in enumerate(hand):
+ deal_str += self.suit_indicator(suit)
+ deal_str += ''.join(cards)
+ return deal_str