Beispiel #1
0
    def clic(self, event, manuelle=False):
        # Eviter que de jouer pendant le tour de l'ordi
        choix = self.choix_j1 if self.joueur == 1 else self.choix_j2
        if (choix.get() != "humain"):
            return None

        # On récupère les coordonnées du clic
        x, y = 0, 0
        if (manuelle is False):
            x, y = event.x, event.y
            if (self.show_debug is True):
                print("Clic détecté (" + str(x) + ", " + str(y) + ")")

        # On vérifie qu'on clique bien dans les limites du plateau de jeu puis on trouve de quelle case il s'agit
        if ((x > self.padding and y > self.padding
             and x < self.longueur * self.cote_image + self.padding
             and y < self.hauteur * self.cote_image + self.padding)
                or manuelle is True):
            if (manuelle is False):
                x = truncate((x - self.padding) / 32)
                y = truncate((y - self.padding) / 32)
                case = str(y) + str(x)
            else:
                case = self.input.get()
            if (self.show_debug is True): print("Case = " + case)

            # Si possible, on joue puis on recalcule les scores et on passe au joueur suivant
            if (self.peutJouer is True):
                estValide = joue(self.damier, self.joueur, case)
                if (estValide is True):
                    self.apres_coup()

            self.affiche()
Beispiel #2
0
def throttle_order(cube, ex_pair, indiv, ex_id, side, amount, val, price):
    # Check for available balance
    if side == 'sell':
        bal = indiv['bal'][ex_pair.base_currency_id, ex_id]
        if amount > bal:
            # Insufficient balance. Reducing order amount
            amount = bal
            val = amount * price
            log.debug(f'{cube} Reducing {ex_pair} order to {amount} \
                        {ex_pair.base_currency}')
    else:  # buy
        bal = indiv['bal'][ex_pair.quote_currency_id, ex_id]
        if val > bal:
            # Insufficient balance. Reducing order amount
            val = bal
            amount = val / price
            log.debug(f'{cube} Reducing {ex_pair} order to {amount} \
                       {ex_pair.base_currency}')

    log.debug(f'{cube} truncating precision')
    try:
        params = {
            'base': ex_pair.base_currency.symbol,
            'quote': ex_pair.quote_currency.symbol
        }
        d = api_request(cube, 'GET', ex_pair.exchange.name, '/details', params)
    except AttributeError:
        # Exchange is probably external... not performing minimum checks
        log.warning(f'{cube} No details for {ex_pair}')
        d = None
    else:
        if d:
            if '.' in str(d['min_amt']):
                precision = len(str(d['min_amt']).split('.')[1])
                amount = round(amount, precision)
                log.debug(f'Precision: {precision}')
            elif amount >= 1:
                amount = truncate(amount)

            log.debug(f'Amount: {amount}')

    return amount, val
def raiseAttributeError():
    return math.truncate(1.0)
def raiseAttributeError():
    return math.truncate(1.0)
Beispiel #5
0
 def __trunc__(self):
     return math.truncate(self.value)
#Breaking a Number

import math

number = float(input('Digite algum número:'))
print(math.truncate(number))
Beispiel #7
0
def pixels_to_block_coord(x, y):
    y_ = truncate(y) // BLOCK_HEIGHT
    absolute_x = truncate(x) // BLOCK_WIDTH
    x_ = absolute_x % ROOM_WIDTH
    return x_, y_