Ejemplo n.º 1
0
    def createAccount(self, acct, bal):
        # this should return True if account create successful else false
        # Should be able to create savings and checking, but not loans
        # SHOULD THERE BE createLoan()?
        #TODO: CHECK FOR MIN BALANCES
        """
        Summary line.
        Creates various accounts for the user

        Parameters
        ----------
        acct: str
            account type as string either "Savings" or "Checking"
        bal: int
            account starting balance

        Returns
        -------
        True if success False if else

        """
        if self.__doesExist(acct):
            print("You already have an account of this type")
            return False

        if acct == "Savings" or acct == 0 and self.accounts["Savings"]:
            if bal < Savings.getMinBal():
                print(
                    "You must open an account with a balance greater than or equal to ${}"
                    .format(Savings.getMinBal()))
                return False
            self.savings = Savings(bal)
            self.accounts["Savings"] = True
            return True
        elif acct == "Checking" or acct == 1 and self.account["Checking"]:
            if bal < Checking.getMinBal():
                print(
                    "You must open an account with a balance greater than or equal to ${}"
                    .format(Checking.getMinBal()))
                return False
            self.checking = Checking(bal)
            self.accounts["Checking"] = True
            return True
        elif acct == "Cancel" or acct == "x" or acct == -1:
            print("Create cancelled")
            return False
        else:
            acctType = input(
                "Please enter account type (Savings, or Checking): ")
            return self.createAccount(acctType)

        return False
Ejemplo n.º 2
0
 def draw():
     liste = master.winfo_children()
     count = 0
     for i in liste:
         if i['text'] == 'O' or i['text'] == 'X':
             count += 1
     if count == n**2 and ch.checkIfSomeoneWon(Board) == None:
         return 'draw'
Ejemplo n.º 3
0
def start_checking(update, context):
    done_list = []

    credentials = context.user_data['credentials']
    context.bot.send_message(chat_id=update.effective_chat.id,
                             text='Running')

    while context.user_data['credentials'][-1]['link'] != 'stop':
        done_list = Checking.start(update, context, done_list)

        if len(done_list) == len(credentials):
            break
        time.sleep(0.01)

    context.bot.send_message(chat_id=update.effective_chat.id,
                             text='DONE')
Ejemplo n.º 4
0
    def buttonCommand(event):

        global t
        global turned
        global flag
        global Round
        global winners
        global scoreboard

        def clearBoard(b):
            for x in range(len(b)):
                for t in range(len(b[x])):
                    b[x][t] = '?'

        winner = ch.checkIfSomeoneWon(Board)

        def update():
            global Round
            if cTf() != 1:
                Round += 1
            clearBoard(Board)
            destroyLabels()
            createLabels()
            scoreboard = Label(
                master,
                bg='black',
                fg='white',
                text=('Round ' + str(Round) + '--> X: ' + str(winners['X']) +
                      ' , O: ' + str(winners['O'])))
            scoreboard.grid(row=0, column=n + 1, rowspan=1)

        if winner != None:
            winners[winner] += 1
            update()

        info = event.widget.grid_info()
        dicti = {'X': 'red', 'O': 'blue'}
        coordinates = (info['row'], info['column'])
        x, y = coordinates
        liste = master.winfo_children()
        count = 0

        for widget in liste:
            if widget['text'] == 'X' and widget['bg'] == 'red' or widget[
                    'text'] == 'O' and widget['bg'] == 'blue':
                count += 1
            if (x, y) not in turned:
                turned.update({(x, y): 0})
        if cTf() == 1:
            master.unbind('<Button 1>', buttonCommand)

        if turned[(x, y)] == 0:
            if t == 1:
                flag = 'X'
                t = 0
                Label(master,
                      bg='red',
                      text='X',
                      borderwidth=10,
                      relief="groove",
                      width=30,
                      height=10).grid(row=x, column=y)
                Board[x][y] = 'X'

            else:
                flag = 'O'
                t = 1
                Label(master,
                      bg='blue',
                      text='O',
                      borderwidth=10,
                      relief="groove",
                      width=30,
                      height=10).grid(row=x, column=y)
                Board[x][y] = 'O'
            turned[(x, y)] = 1

        winner = ch.checkIfSomeoneWon(Board)

        if winner != None:
            winners[winner] += 1
            update()

        if draw() == 'draw':
            winners['O'] += 1
            winners['X'] += 1
            update()
Ejemplo n.º 5
0
    def buttonCommand(event):

        global t
        global turned
        global flag
        global Round
        global winners
        global scoreboard
        global moveList

        def clearBoard(b):
            for x in range(len(b)):
                for t in range(len(b[x])):
                    b[x][t] = '?'

        def update():
            global Round
            Round += 1
            clearBoard(Board)
            destroyLabels()
            createLabels()
            scoreboard = Label(
                master,
                bg='black',
                fg='white',
                text=('Round ' + str(Round) + '--> X: ' + str(winners['X']) +
                      ' , O: ' + str(winners['O'])))
            scoreboard.grid(row=0, column=n + 1, rowspan=1)

        winner = ch.checkIfSomeoneWon(Board)

        if winner != None:
            print(1)
            winners[winner] += 1
            liste = []
            for i in copy:
                liste.append(copy[i])
            moveList = liste
            update()

        info = event.widget.grid_info()
        coordinates = (info['row'], info['column'])
        x, y = coordinates
        liste = master.winfo_children()
        count = 0

        for widget in liste:
            if widget['text'] == 'X' and widget['bg'] == 'red' or widget[
                    'text'] == 'O' and widget['bg'] == 'blue':
                count += 1
            if (x, y) not in turned:
                turned.update({(x, y): 0})

        if cTf() == 1:
            master.unbind('<Button 1>', buttonCommand)

        if draw() == 'draw':
            print('draw')
            moveList = copy
            winners['O'] += 1
            winners['X'] += 1
            update()

        if turned[(x, y)] == 0:
            if person == 'X':
                Label(master,
                      bg='red',
                      text='X',
                      borderwidth=10,
                      relief="groove",
                      width=30,
                      height=10).grid(row=x, column=y)
                Board[x][y] = 'X'

                moveList.remove((x, y))
                makeAutoMove(moveList, pc)

            if person == 'O':
                Label(master,
                      bg='blue',
                      text='O',
                      borderwidth=10,
                      relief="groove",
                      width=30,
                      height=10).grid(row=x, column=y)

                Board[x][y] = 'O'
                moveList.remove((x, y))
                makeAutoMove(moveList, pc)

            turned[(x, y)] = 1

        if draw() == 'draw':
            moveList = copy
            winners['O'] += 1
            winners['X'] += 1
            update()

        winner = ch.checkIfSomeoneWon(Board)
        if winner != None:
            print(2)
            winners[winner] += 1
            liste = []
            for i in copy:
                liste.append(copy[i])
            moveList = liste
            update()

        if cTf() == 1:
            master.unbind('<Button 1>', buttonCommand)
Ejemplo n.º 6
0
def orientation_down(snake, food):

    event = KEY_DOWN

    snake_above = []
    snake_right = []
    snake_left = []

    for x in range(len(snake)):
        if x >= 3:
            snake_above.append([(snake[x][0] - 1), snake[x][1]])
            snake_right.append([snake[x][0], (snake[x][1] + 1)])
            snake_left.append([snake[x][0], (snake[x][1] - 1)])

    if (snake[0][0] == food[0]) or (food[0] < snake[0][0]):
        if food[1] > snake[0][1]:
            event = KEY_RIGHT

            if snake[0] in snake_left[1:]:
                event = KEY_DOWN

        elif food[1] < snake[0][1]:
            event = KEY_LEFT

            if snake[0] in snake_right[1:]:
                event = KEY_DOWN

        # else:
        #     if snake[0] not in snake_left[1:]:
        #         event = KEY_RIGHT
        #
        #     elif snake[0] not in snake_right[1:]:
        #         event = KEY_LEFT

    if snake[0] in snake_above[1:]:

        if Checking.check_left(snake) and Checking.check_right(snake):

            if Checking.distance_left(snake) > Checking.distance_right(snake):
                event = KEY_LEFT

                if Checking.check_enclosed(snake, "Left", "Down"):
                    event = KEY_RIGHT

                    if snake[0] in snake_left[1:]:
                        event = KEY_LEFT

            else:
                event = KEY_RIGHT

                if Checking.check_enclosed(snake, "Right", "Up"):
                    event = KEY_LEFT

                    if snake[0] in snake_right[1:]:
                        event = KEY_RIGHT

        elif Checking.check_left(snake):
            event = KEY_RIGHT

            if snake[0][1] == 58:
                event = KEY_LEFT

        elif Checking.check_right(snake):
            event = KEY_LEFT

            if snake[0][1] == 1:
                event = KEY_RIGHT

        else:
            event = KEY_RIGHT

    if snake[0][0] == 18:

        if Checking.check_enclosed(snake, "Left",
                                   "Down") and Checking.check_enclosed(
                                       snake, "Right", "Down"):
            if Checking.distance_wall_left(
                    snake) > Checking.distance_wall_right(snake):
                event = KEY_LEFT

                if snake[0] in snake_right[1:]:
                    event = KEY_RIGHT

            else:
                event = KEY_RIGHT

                if snake[0] in snake_left[1:]:
                    event = KEY_LEFT

        elif Checking.check_enclosed(snake, "Left", "Down"):
            event = KEY_RIGHT

            if snake[0][1] == 58:
                event = KEY_LEFT

        elif Checking.check_enclosed(snake, "Right", "Down"):
            event = KEY_LEFT

            if snake[0][1] == 1:
                event = KEY_RIGHT

        else:
            if Checking.distance_wall_left(
                    snake) > Checking.distance_wall_right(snake):
                event = KEY_LEFT

                if snake[0] in snake_right[1:]:
                    event = KEY_RIGHT

            else:
                event = KEY_RIGHT

                if snake[0] in snake_left[1:]:
                    event = KEY_LEFT

    if event == KEY_LEFT:
        if Checking.check_left(snake) and Checking.check_right(snake):
            if Checking.check_enclosed(snake, "Left", "Down"):
                event = KEY_RIGHT

                if snake[0] in snake_left[1:]:
                    event = KEY_LEFT

    if event == KEY_RIGHT:
        if Checking.check_left(snake) and Checking.check_right(snake):
            if Checking.check_enclosed(snake, "Right", "Down"):
                event = KEY_LEFT

                if snake[0] in snake_right[1:]:
                    event = KEY_RIGHT

    return event
Ejemplo n.º 7
0
def orientation_right(snake, food):

    event = KEY_RIGHT

    snake_above = []
    snake_below = []
    snake_left = []

    for x in range(len(snake)):
        if x >= 3:
            snake_above.append([(snake[x][0] - 1), snake[x][1]])
            snake_below.append([(snake[x][0] + 1), snake[x][1]])
            snake_left.append([snake[x][0], (snake[x][1] - 1)])

    if (snake[0][1] == food[1]) or (food[1] < snake[0][1]):
        if food[0] > snake[0][0]:
            event = KEY_DOWN

            if snake[0] in snake_above[1:]:
                event = KEY_RIGHT

        elif food[0] < snake[0][0]:
            event = KEY_UP

            if snake[0] in snake_below[1:]:
                event = KEY_RIGHT

        # else:
        #     if snake[0] not in snake_above[1:]:
        #         event = KEY_DOWN
        #
        #     elif snake[0] not in snake_below[1:]:
        #         event = KEY_UP

    if snake[0] in snake_left[1:]:

        if Checking.check_up(snake) and Checking.check_down(snake):

            if Checking.distance_up(snake) > Checking.distance_down(snake):
                event = KEY_UP

                if Checking.check_enclosed(snake, "Up", "Right"):
                    event = KEY_DOWN

                    if snake[0] in snake_above[1:]:
                        event = KEY_UP

            else:
                event = KEY_DOWN

                if Checking.check_enclosed(snake, "Down", "Right"):
                    event = KEY_UP

                    if snake[0] in snake_below[1:]:
                        event = KEY_DOWN

        elif Checking.check_up(snake):
            event = KEY_DOWN

            if snake[0][0] == 18:
                event = KEY_UP

        elif Checking.check_down(snake):
            event = KEY_UP

            if snake[0][0] == 11:
                event = KEY_DOWN

        else:
            event = KEY_DOWN

    if snake[0][1] == 58:

        if Checking.check_enclosed(snake, "Up",
                                   "Right") and Checking.check_enclosed(
                                       snake, "Down", "Right"):
            if Checking.distance_wall_top(
                    snake) > Checking.distance_wall_bottom(snake):
                event = KEY_UP

                if snake[0] in snake_below[1:]:
                    event = KEY_DOWN

            else:
                event = KEY_DOWN

                if snake[0] in snake_above[1:]:
                    event = KEY_UP

        elif Checking.check_enclosed(snake, "Up", "Right"):
            event = KEY_DOWN

            if snake[0][0] == 18:
                event = KEY_UP

        elif Checking.check_enclosed(snake, "Down", "Right"):
            event = KEY_UP

            if snake[0][0] == 1:
                event = KEY_DOWN

        else:
            if Checking.distance_wall_top(
                    snake) > Checking.distance_wall_bottom(snake):
                event = KEY_UP

                if snake[0] in snake_below[1:]:
                    event = KEY_DOWN

            else:
                event = KEY_DOWN

                if snake[0] in snake_above[1:]:
                    event = KEY_UP

    if event == KEY_UP:
        if Checking.check_up(snake) and Checking.check_down(snake):
            if Checking.check_enclosed(snake, "Up", "Right"):
                event = KEY_DOWN

                if snake[0] in snake_above[1:]:
                    event = KEY_UP

    if event == KEY_DOWN:
        if Checking.check_up(snake) and Checking.check_down(snake):
            if Checking.check_enclosed(snake, "Down", "Right"):
                event = KEY_UP

                if snake[0] in snake_below[1:]:
                    event = KEY_DOWN

    return event
Ejemplo n.º 8
0
    if Xinput == 'quit':
        break

    try:
        rowloc, columnloc = int(Xinput[0]), int(Xinput[2])
    except:
        print('Invalid input, you wasted your turn')
    try:
        if board[rowloc][columnloc] == '?':
            board[rowloc][columnloc] = 'X'
        else:
            print('That location is already full, you wasted your turn.')
    except:
        print('That location is not in the board, you wasted your turn.')

    a = ch.checkIfSomeoneWon(board, numberOfRounds)
    if a != '?':
        break
    #O plays
    Oinput = (
        input('It is your turn o, enter your location in format of 1,2: '))
    if Oinput == 'quit':
        break
    try:
        rowloc, columnloc = int(Oinput[0]), int(Oinput[2])
    except:
        print('Invalid input, you wasted your turn')
    try:
        if board[rowloc][columnloc] == '?':
            board[rowloc][columnloc] = 'O'
        else:
Ejemplo n.º 9
0
class Customer(Person):
    def __init__(self, name, birthdate, phoneNumber, address, ssn):
        """
        Summary line.
        Initializing the variables.

        Parameters
        ----------
        name: str
            name of the customer
        birthdate: str
            birthdate of the customer
            passed as MM/DD/YYYY
        phonenumber: int
            phonenumber of the customer
        address: str
            address of the customer
        ssn: int
            Social securtiy number of the customer

        Returns
        -------
        Doesn't return anything

        """
        Person.__init__(self, name, birthdate, phoneNumber, address)
        self.isMinor = True if self.getAge() < 18 else False
        self.ssn = ssn  #What are we going to use this for? identifying loans?
        self.accounts = {
            "Savings": False,
            "Checking": False,
            "Loan": False
        }  # this is just an easy way to keep track of what accounts are open

    def getInfo(self):
        """
        Summary line.
        Returns customer info

        Parameters
        ----------
        None

        Returns
        -------
        Returns # of accounts open
        Initialized customer info

        Does NOT return balances - see checkBalance()
        """
        exists = []
        for account in self.accounts:
            if self.__doesExist(account):
                exists.append(account)

        return "Name: {}\nBirthdate: {}\nPhone Number: {}\nAddress: {}\nMinor: {}\nAccounts open:{}".format(
            self.name, self.birthdate, self.phoneNumber, self.address,
            self.isMinor, ", ".join(exists))

    def __doesExist(self, acct):
        """
        Summary:
            check for account existance
        Description:
            Checks the initialized self.accounts dictionary and returns wether an account exists or not

        Parameters
        _________

        acct: str
            Account type either "Savings" or "Checking" or "Loan"

        Returns
        _______
        Boolean
            Returns True if account exists False if account doesnt exist or doesnt match any keywords

        """
        try:
            return self.accounts[acct]
        except KeyError:
            print("Non-Valid account type {}".format(acct))
            return False

    def createAccount(self, acct, bal):
        # this should return True if account create successful else false
        # Should be able to create savings and checking, but not loans
        # SHOULD THERE BE createLoan()?
        #TODO: CHECK FOR MIN BALANCES
        """
        Summary line.
        Creates various accounts for the user

        Parameters
        ----------
        acct: str
            account type as string either "Savings" or "Checking"
        bal: int
            account starting balance

        Returns
        -------
        True if success False if else

        """
        if self.__doesExist(acct):
            print("You already have an account of this type")
            return False

        if acct == "Savings" or acct == 0 and self.accounts["Savings"]:
            if bal < Savings.getMinBal():
                print(
                    "You must open an account with a balance greater than or equal to ${}"
                    .format(Savings.getMinBal()))
                return False
            self.savings = Savings(bal)
            self.accounts["Savings"] = True
            return True
        elif acct == "Checking" or acct == 1 and self.account["Checking"]:
            if bal < Checking.getMinBal():
                print(
                    "You must open an account with a balance greater than or equal to ${}"
                    .format(Checking.getMinBal()))
                return False
            self.checking = Checking(bal)
            self.accounts["Checking"] = True
            return True
        elif acct == "Cancel" or acct == "x" or acct == -1:
            print("Create cancelled")
            return False
        else:
            acctType = input(
                "Please enter account type (Savings, or Checking): ")
            return self.createAccount(acctType)

        return False

    def checkBalance(self, acct=None):
        #TODO: return true and false and just print information since this is a interface class(it interfaces between classes
        """
        Summary:
            Checks account balances and prints if they exist
        Description:
            Checks for account existance - if no accounts exists cancel or if the specific account doesnt exist cancel
        Parameters
        _________

        acct: str
            Either "Checking", "Savings", or "Loan" if left empty the user is prompted

        Returns
        _______
        Boolean
            True if account check succeeds false if not
        """
        numAccts = 0
        for account in self.accounts:
            if self.accounts[account]:
                numAccts += 1

        if numAccts == 0:
            print("Please create an account first")
            return False

        if acct == "Cancel" or acct == "x" or acct == -1:
            print("Check cancelled")
            return False
        elif self.__doesExist(
                acct
        ):  #use this method rather than just self.accounts[acct] to catch keyErrors
            if acct == "Savings":
                print("Your {} account balance is: {}".format(
                    acct.lower(), self.savings.getBalance()))
            elif acct == "Checking":
                print("Your {} account balance is: {}".format(
                    acct.lower(), self.checking.getBalance()))
            elif acct == "Loan":
                print("Your {} account balance is: {}".format(
                    acct.lower(), self.loan.getBalance()))
            return True
        elif acct in self.accounts:
            print("Please create the {} account first".format(acct))
            return False
        else:
            acct = input(
                "Please enter account type (Savings, Checking, or Loan): ")
            print(self.checkBalance(acct))
            return False

    def askForLoan(self, managerId=0):
        #check for correct manager id before creating loan - or should this all be taken care of from the manager standpoint
        print("NOT YET IMPLEMENTED")

    def depositTo(self, acct, ammt):
        """
        Summary:
            deposits to spefied account
            prints an error on fail

        Parameters
        _________

        acct: str
            Account type either "Savings" or "Checking"
        ammt: int
            Ammount to be deposited to acct

        Returns
        _______
        Boolean
            Returns True on success and False on fail

        """
        if self.__doesExist(acct):
            if acct == "Savings":
                self.savings.deposit(ammt)
                return True
            elif acct == "Checking":
                self.checking.deposit(ammt)
                return True
        else:
            print("No account of {} type exists".format(acct))
            return False

    def withdrawFrom(self, acct, ammt):
        """
        Summary:
            Withdraw from account
            prints an error on fail

        Parameters
        _________

        acct: str
            Account type either "Savings" or "Checking"

        ammt: int
            Ammount to withdraw from acct

        Returns
        _______
        Bool
           Returns true on success false on fail

        """
        if self.__doesExist(acct):
            if acct == "Savings":
                out = self.savings.withdraw(ammt)
                print(out)
                if isinstance(out, int):
                    return True
                else:
                    return False
            elif acct == "Checking":
                out = self.checking.withdraw(ammt)
                print(out)
                if isinstance(out, int):
                    return True
                else:
                    return False
        else:
            print("No account of {} type exists".format(acct))
            return False

    def makePayment(self, ammt):
        #allows for making payments on loans ONLY
        print("NOT YET IMPLEMENTED")