summaryrefslogtreecommitdiff
path: root/bcdd/BCalcWrapper.py
blob: 33b79d2e79be6aa0578f0b73e2bd92b3fc27dddf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
'''
Wrapper class for libbcalcDDS.dll
'''

import os
from ctypes import cdll, c_void_p

from .Exceptions import DllNotFoundException


class BCalcWrapper(object):

    DENOMINATIONS = [ 'C', 'D', 'H', 'S', 'N' ]
    PLAYERS = [ 'N', 'E', 'S', 'W' ]

    def __init__(self):
        dllPath = os.path.join(
            os.path.dirname(__file__),
            '..')
        try:
            self.libbcalcdds = cdll.LoadLibrary(os.path.join(
                dllPath, 'libbcalcdds.dll'))
        except OSError:
            try:
                self.libbcalcdds = cdll.LoadLibrary(os.path.join(
                    dllPath, 'libbcalcdds.so'))
            except OSError:
                self.libbcalcdds = None
        if self.libbcalcdds is None:
            raise DllNotFoundException()

    def __getattr__(self, attrname):
        def _dynamic_method(*args):
            function = getattr(self.libbcalcdds, 'bcalcDDS_' + attrname)
            if attrname == 'new':
                function.restype = c_void_p
            else:
                function.argtypes = [c_void_p]
            return function(*args)
        return _dynamic_method

    def declarerToLeader(self, player):
        return (player + 1) % 4