Example #1
0
    def __readCommand(self):
        try:
            choice = input("Your Choice: >> ").strip(" ")
            if choice == "0":
                return "0", None

            noOfAttempts = int(input("No. of Attempts: >> "))
            if noOfAttempts <= 0 or noOfAttempts > 50:
                raise MyException("No. of attempts must be in range [1,50].")
            return choice, noOfAttempts
        except ValueError:
            raise MyException("No. of attempts must be an integer number.")
Example #2
0
 def __round(self):
     (self.__cipher, self.__decipher) = self.__initialiseCipher()
     if self.__operand == "+":
         self.__addWords()
     else:
         self.__subtractWords()
     if self.__currentWord == self.__resultWord:
         raise MyException("Solution found!")
     print(str(self) + "\n It is not a solution.")
Example #3
0
    def __cryptarithmeticGame(self, noOfAttempts):
        operand = input("Operand (+, -): >> ")
        if operand != "+" and operand != "-":
            raise MyException("Operand must be one of: +, -")
        firstWord = input("First Word: >> ").strip(" ").upper()
        secondWord = input("Second Word: >> ").strip(" ").upper()
        resultWord = input("Result Word: >> ").strip(" ").upper()

        cryptarithmeticGame = CryptarithmeticGame(noOfAttempts, operand,
                                                  firstWord, secondWord,
                                                  resultWord)
        cryptarithmeticGame.play()
Example #4
0
    def __initialiseCipher(self):
        cipher = {}
        decipher = {0: "_",
                    1: "_",
                    2: "_",
                    3: "_",
                    4: "_",
                    5: "_",
                    6: "_",
                    7: "_",
                    8: "_",
                    9: "_",
                    10: "_",
                    11: "_",
                    12: "_",
                    13: "_",
                    14: "_",
                    15: "_",
                    -1: "-"}

        options = []
        options.extend(range(16))

        lettersList = []
        lettersList.extend(self.__deconstructWord(self.__firstWord))
        lettersList.extend(self.__deconstructWord(self.__secondWord))
        lettersList.extend(self.__deconstructWord(self.__currentWord))

        firstLetterList = [self.__firstWord[0], self.__secondWord[0], self.__resultWord[0]]

        for letter in lettersList:
            if letter not in cipher.keys():
                if len(options) == 0:
                    raise MyException("There are more than 16 unique letters in the equation.")
                value = random.choice(options)
                if letter in firstLetterList:
                    if len(options) == 1 and options[0] == 0:
                        return self.__initialiseCipher()
                    while value == 0:
                        value = random.choice(options)
                cipher[letter] = value
                decipher[value] = letter
                options.remove(value)

        return cipher, decipher
Example #5
0
    def __round(self):
        for row in self.__board:
            for square in row:
                square.shuffleSquare()

        try:
            for row in range(self.__n):
                boardRow = self.getRow(row)
                for number in range(1, self.__n + 1):
                    boardRow.index(number)
            for column in range(self.__n):
                boardColumn = self.getColumn(column)
                for number in range(1, self.__n + 1):
                    boardColumn.index(number)

            raise MyException("Solution found!")
        except ValueError:
            print(str(self) + "\n It is not a solution.")
Example #6
0
 def __round(self):
     (self.__numberTable, self.__symbolTable) = self.__initiateTables()
     self.__placeGeometricForms()
     if self.__isSolution():
         raise MyException("Solution found!")
     print(str(self) + "\n\nIt is not a solution.")