diff options
author | Michał Klichowicz <emkael@tlen.pl> | 2023-10-01 23:42:10 +0200 |
---|---|---|
committer | Michał Klichowicz <emkael@tlen.pl> | 2023-10-01 23:42:10 +0200 |
commit | b3f00e26049c990f06ab4b1b37345d64f0b5c2ae (patch) | |
tree | 820ce5d325e6427645d5af8b160d574b6c453b56 /src/bcdd/DDTable.py | |
parent | 7abe5062e8a9cbd41316090e8891fdcbc026696d (diff) |
Removing double-dummy code from bcdd PBN parsing code
Diffstat (limited to 'src/bcdd/DDTable.py')
-rw-r--r-- | src/bcdd/DDTable.py | 44 |
1 files changed, 7 insertions, 37 deletions
diff --git a/src/bcdd/DDTable.py b/src/bcdd/DDTable.py index 651aec3..a97af48 100644 --- a/src/bcdd/DDTable.py +++ b/src/bcdd/DDTable.py @@ -1,7 +1,6 @@ -from ctypes import c_char_p -from copy import copy +from copy import copy -from .BCalcWrapper import BCalcWrapper +from .PBNBoard import PBNBoard from .Exceptions import DDTableInvalidException, FieldNotFoundException @@ -23,37 +22,8 @@ class DDTable(object): ) return table - _banner_displayed = False - def __init__(self, board): self._board = board; - self._wrapper = BCalcWrapper() - - def _check_for_error(self, solver): - error = self._wrapper.getLastError(solver) - if error: - raise DDTableInvalidException( - 'BCalc error: %s' % (c_char_p(error).value.decode('ascii'))) - - def get_bcalc_table(self, show_banner=True): - if not DDTable._banner_displayed and show_banner: - print('Double dummy analysis provided by BCalc.') - print('BCalc is awesome, check it out: http://bcalc.w8.pl') - DDTable._banner_displayed = True - result = self._get_empty_table() - deal = self._board.get_layout() - solver = self._wrapper.new(b"PBN", deal.encode(), 0, 0) - self._check_for_error(solver) - for denom in range(0, 5): - self._wrapper.setTrumpAndReset(solver, denom) - for player in range(0, 4): - leader = self._wrapper.declarerToLeader(player) - self._wrapper.setPlayerOnLeadAndReset(solver, leader) - result[player][denom] = 13 - self._wrapper.getTricksToTake( - solver) - self._check_for_error(solver) - self._wrapper.delete(solver); - return self._validate_table(result) def get_jfr_table(self): result = self._get_empty_table() @@ -61,7 +31,7 @@ class DDTable(object): abilities = self._board.validate_ability(ability) for player_ability in abilities: player = player_ability[0] - player_id = BCalcWrapper.PLAYERS.index(player) + player_id = PBNBoard.PLAYERS.index(player) denom_id = 4 for tricks in player_ability[1]: result[player_id][denom_id] = int(tricks, 16) @@ -76,8 +46,8 @@ class DDTable(object): player = line_match.group(1)[0] denom = line_match.group(2)[0] tricks = int(line_match.group(3)) - player_id = BCalcWrapper.PLAYERS.index(player) - denom_id = BCalcWrapper.DENOMINATIONS.index(denom) + player_id = PBNBoard.PLAYERS.index(player) + denom_id = PBNBoard.DENOMINATIONS.index(denom) result[player_id][denom_id] = tricks return self._validate_table(result) @@ -91,8 +61,8 @@ class DDTable(object): return self.get_bcalc_table(show_banner) def print_table(self, dd_table): - print('\t' + '\t'.join(BCalcWrapper.DENOMINATIONS)) + print('\t' + '\t'.join(PBNBoard.DENOMINATIONS)) for i in range(0, 4): print('%s%s' % ( - self._wrapper.PLAYERS[i], + PBNBoard.PLAYERS[i], ''.join(['\t' + str(tricks) for tricks in dd_table[i]]))) |