def new(self):
     a = input('Quer começar de novo? S para SIM ou qualquer outra para NÃO. ')
     if a == 'S' or a == 's':
         clear('cls')
         self.play()
     else:
         return
    def play(self):
        clear('cls')
        matrix = self.final_matrix()
        matrix[0][0] = '#'
        first_play = True

        while matrix[-1][-1] != '#':

            if first_play == True:
                print('REGRAS: Você só pode mover o robo (#) para baixo (S) ou para direita (D)')
                print('        Você NÃO pode mover o robo para as casas marcadas com `x´')
                print('        O objetivo é mover o robo até o canto inferior direito\n')
                self.print_matrix(matrix)
                first_play = False
            movement = input('Informe uma jogada. D para direita ou S para baixo. Aperte ENTER para sair. ')
            clear('cls')

            if movement == 'd' or movement == 'D':
                self.move_right(matrix)
                first_play = False
            elif movement == 's' or movement == 'S':
                self.move_down(matrix)
                first_play = False
            elif movement == '':
                return
            self.print_matrix(matrix)
            if self.possible(matrix) == True:
                break
        if self.win(matrix) == True:
            print('\n********************** PARABÉNS VOCÊ GANHOU!!! **********************\n')
        self.new()
        return
 def generate_matrix(self):
     max_rows = self.size_row()
     max_cols = self.size_col()
     matrix = []
     for rows in range(max_rows):
         new_row = []
         for cols in range(max_cols):
             new_row.append('o')
         matrix.append(new_row)
     clear('cls')
     return matrix
예제 #4
0
def restart():
    print('''
Main Menu
=========
Type P to Play
''')

    choice = input('Input Here: ').upper()

    if choice != 'P':
        os.clear('cls')
        restart()
예제 #5
0
def rematch():
    global priority, a, b, c, d, e, f, g, h, i, wins
    a, b, c, d, e, f, g, h, i = ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '
    clear('cls')
    print('TicTacToe bot by shizzzerrr v1.0')
    print(f'bot {wins}:0 player')
    print('Waiting 3 seconds...')
    sleep(3)
    if random.random() > 0.5:
        print('Bot has first turn.')
        priority = 1

    else:
        print('Player has first turn.')
        priority = 2

    clear('cls')

    game()
	def key(self):
	    while(1):
                os.clear()
		print "use arrow keys to control robot"
		print "UP arrow/Down Arrow/Left Arrow/Right Arrow"		
		print "hit q thrice to exit"
        	
        	fd = sys.stdin.fileno()
		old_settings = termios.tcgetattr(fd)
		try:
			tty.setraw(sys.stdin.fileno())
			ch = sys.stdin.read(3)
		finally:
			termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
		k=ch
        	if k=='':
			continue
	        if k=='\x1b[A':
        	        print "up"
			self.straight()
			self.stop()
			continue
        	elif k=='\x1b[B':
        	        print "down"
			self.back()
			self.stop()
			continue
        	elif k=='\x1b[C':
        	        print "right"
			self.right()
			self.stop()
			continue
        	elif k=='\x1b[D':
        	        print "left"
			self.left()
			self.stop()
			continue
		elif k=='qqq':
			print "bye"
			break
       		else:
                	print "not an arrow key!"
예제 #7
0
def menu():
    global priority, a, b, c, d, e, f, g, h, i
    a, b, c, d, e, f, g, h, i = ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '
    clear('cls')
    print('TicTacToe bot by shizzzerrr v1.0')
    input('Press "Enter" to start game :')

    if random.random() > 0.5:
        print('Bot has first turn.')
        priority = 1

    else:
        print('Player has first turn.')
        priority = 2

    sleep(3)

    clear('cls')

    game()
예제 #8
0
5.6
>>> int(5.6)
5
>>> round(5.6)
6
>>> round(5.4)
5
>>> round(5.5)
6
>>> round(5.67, 1)
5.7
>>> round(5.678, 2)
5.68
>>> float(5)
5.0
>>> os.clear('system')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'os' has no attribute 'clear'
>>> os.system('clear')

0
>>> True
True
>>> False
False
>>> true
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'true' is not defined
>>> false
예제 #9
0
def refresh_screen():
    clear("cls")
    print_header()
    board.display()
예제 #10
0
import os
os.clear()
예제 #11
0
def game():
    clear('cls')
    global priority, a, b, c, d, e, f, g, h, i, wins
    field(a, b, c, d, e, f, g, h, i)
    if a == b == c != ' ' or d == e == f != ' ' or g == h == i != ' ' or a == d == g != ' ' or b == e == h != ' ' or c == f == i != ' ' or a == e == i != ' ' or c == e == g != ' ':
        print('Bot wins.')
        wins += 1
        print('\nNew game? (y|n)')
        if input('>>> ') == 'y':
            rematch()
        else:
            clear('cls')
            exit()
    elif a != ' ' and b != ' ' and c != ' ' and d != ' ' and e != ' ' and f != ' ' and g != ' ' and h != ' ' and i != ' ':
        print('Draw.')
        print('\nNew game? (y|n)')
        if input('>>> ') == 'y':
            rematch()
        else:
            clear('cls')
            exit()
    else:
        if priority % 2 == 0:
            print(
                'Write coordinates of your turn. (examples : a1, b2, c1, a3.)')
            player_turn()
            priority += 1
            game()
        else:
            #ГОРИЗОНТАЛИ
            if a == b == 'o' and c == ' ':
                c = 'o'
            elif a == c == 'o' and b == ' ':
                b = 'o'
            elif b == c == 'o' and a == ' ':
                a = 'o'

            elif d == e == 'o' and f == ' ':
                f = 'o'
            elif e == f == 'o' and d == ' ':
                d = 'o'
            elif d == f == 'o' and e == ' ':
                e = 'o'

            elif g == h == 'o' and i == ' ':
                i = 'o'
            elif h == i == 'o' and g == ' ':
                g = 'o'
            elif g == i == 'o' and h == ' ':
                h = 'o'
            #ВЕРТИКАЛИ
            elif a == d == 'o' and g == ' ':
                g = 'o'
            elif a == g == 'o' and d == ' ':
                d = 'o'
            elif d == g == 'o' and a == ' ':
                a = 'o'

            elif b == e == 'o' and h == ' ':
                h = 'o'
            elif e == h == 'o' and b == ' ':
                b = 'o'
            elif b == h == 'o' and e == ' ':
                e = 'o'

            elif c == f == 'o' and i == ' ':
                i = 'o'
            elif c == i == 'o' and f == ' ':
                f = 'o'
            elif f == i == 'o' and c == ' ':
                c = 'o'
            #ДИАГОНАЛИ
            elif a == e == 'o' and i == ' ':
                i = 'o'
            elif a == i == 'o' and e == ' ':
                e = 'o'
            elif e == i == 'o' and a == ' ':
                a = 'o'

            elif c == e == 'o' and g == ' ':
                g = 'o'
            elif e == g == 'o' and c == ' ':
                c = 'o'
            elif c == g == 'o' and e == ' ':
                e = 'o'

            #ГОРИЗОНТАЛИ
            elif a == b == 'x' and c == ' ':
                c = 'o'
            elif a == c == 'x' and b == ' ':
                b = 'o'
            elif b == c == 'x' and a == ' ':
                a = 'o'

            elif d == e == 'x' and f == ' ':
                f = 'o'
            elif e == f == 'x' and d == ' ':
                d = 'o'
            elif d == f == 'x' and e == ' ':
                e = 'o'

            elif g == h == 'x' and i == ' ':
                i = 'o'
            elif h == i == 'x' and g == ' ':
                g = 'o'
            elif g == i == 'x' and h == ' ':
                h = 'o'
            #ВЕРТИКАЛИ
            elif a == d == 'x' and g == ' ':
                g = 'o'
            elif a == g == 'x' and d == ' ':
                d = 'o'
            elif d == g == 'x' and a == ' ':
                a = 'o'

            elif b == e == 'x' and h == ' ':
                h = 'o'
            elif e == h == 'x' and b == ' ':
                b = 'o'
            elif b == h == 'x' and e == ' ':
                e = 'o'

            elif c == f == 'x' and i == ' ':
                i = 'o'
            elif c == i == 'x' and f == ' ':
                f = 'o'
            elif f == i == 'x' and c == ' ':
                c = 'o'
            #ДИАГОНАЛИ
            elif a == e == 'x' and i == ' ':
                i = 'o'
            elif a == i == 'x' and e == ' ':
                e = 'o'
            elif e == i == 'x' and a == ' ':
                a = 'o'

            elif c == e == 'x' and g == ' ':
                g = 'o'
            elif e == g == 'x' and c == ' ':
                c = 'o'
            elif c == g == 'x' and e == ' ':
                e = 'o'

            else:
                if (a == 'x' or c == 'x' or g == 'x' or i == 'x') and e == ' ':
                    e = 'o'
                elif a == ' ' and d == b == ' ':
                    a = 'o'
                elif c == ' ' and b == f == ' ':
                    c = 'o'
                elif g == ' ' and d == h == ' ':
                    g = 'o'
                elif i == ' ' and h == f == ' ':
                    i = 'o'
                elif a == ' ':
                    a = 'o'
                elif b == ' ':
                    b = 'o'
                elif c == ' ':
                    c = 'o'
                elif d == ' ':
                    d = 'o'
                elif e == ' ':
                    e = 'o'
                elif f == ' ':
                    f = 'o'
                elif g == ' ':
                    g = 'o'
                elif h == ' ':
                    h = 'o'
                elif i == ' ':
                    i = 'o'
            priority += 1
            game()
예제 #12
0
    def downloadNrrdFile(self,
                         server,
                         serverPath,
                         studyId,
                         patientId,
                         caseId,
                         ext,
                         localStoragePath,
                         cacheOn,
                         sshMode=True,
                         privateKeySSH=None):
        """Download Header and Raw data in a Nrrd file.
        Returns the full local path for the nhrd file (header)                 
        """

        localFile = "{0}/{1}{2}.nhdr".format(localStoragePath, caseId, ext)

        # If cache mode is not activated or the file does not exist locally, proceed to download
        if (not cacheOn or not os.path.isfile(localFile)):
            error = False

            try:
                if os.path.isfile(localFile):
                    # Delete file previously to avoid confirmation messages
                    print("Remove cached files: " + localFile)
                    try:
                        os.clear(localFile)
                        os.clear("{0}/{1}{2}.raw.gz".format(
                            localStoragePath, caseId, ext))
                    except:
                        print("Error when deleting local files ({0})".format(
                            localFile))

                # Make sure that the ssh key has not too many permissions if it is used (otherwise scp will return an error)
                if privateKeySSH:
                    os.chmod(privateKeySSH, 0o600)

                # Download header
                if (os.sys.platform == "win32"):
                    localStoragePath = localStoragePath.replace('/',
                                                                '\\') + '\\'

                    if sshMode:
                        if privateKeySSH:
                            privateKeyCommand = "-privatekey={0}".format(
                                privateKeySSH)
                        else:
                            privateKeyCommand = ""
                        params = [("%s\\CIP_GetImage_Resources\\WinSCP.com" % self.modulePath) ,"/command", 'open {0} {1}'.format(server, privateKeyCommand), \
                                    'get {0}/{1}/{2}/{3}/{3}{4}.nhdr {5}'.format(serverPath, studyId, patientId, caseId, ext, localStoragePath), "exit"]
                    else:
                        params = [
                            'copy', "{0}\\{1}\\{2}\\{3}\\{3}{4}.nhdr".format(
                                serverPath, studyId, patientId, caseId, ext),
                            localStoragePath
                        ]

                else:
                    # Unix
                    if sshMode:
                        keyCommand = (
                            "-i %s " % privateKeySSH
                        ) if privateKeySSH else ""  # Set a command if privateKeySsh has any value (non empty)
                        params = [
                            'scp', "{0}{1}:{2}/{3}/{4}/{5}/{5}{6}.nhdr".format(
                                keyCommand, server, serverPath, studyId,
                                patientId, caseId, ext), localStoragePath
                        ]
                    else:
                        params = [
                            'cp', "{0}/{1}/{2}/{3}/{3}{4}.nhdr".format(
                                serverPath, studyId, patientId, caseId, ext),
                            localStoragePath
                        ]
                    fullStrCommand = " ".join(params)

                (result, output, error) = self.executeDownloadCommand(params)

                if (result == Util.ERROR):
                    print("Error when executing download command. Params:")
                    print(params)
                    if (error == None):
                        error = "Unnknown error"
                    raise Exception(error)

                # Download raw data (just update a parameter)
                if (os.sys.platform == "win32"):
                    if sshMode: paramToModify = 3
                    else: paramToModify = 1
                else:
                    # Unix
                    paramToModify = 1

                # Replace the name of the parameter
                params[paramToModify] = params[paramToModify].replace(
                    ".nhdr", ".raw.gz")

                # Dowload the raw data
                (result, output, error) = self.executeDownloadCommand(params)

                if (result == Util.ERROR):
                    print("Error when executing download command. Params:")
                    print(params)
                    if (error == None):
                        error = "Unnknown error"
                    raise Exception(error)

                # If everything goes well, check the the path of the Nrrd file to verify that the file have been correctly downlaoded
                missingFiles = ""
                if not os.path.isfile(localFile):
                    missingFiles = missingFiles + localFile + ";"
                if not os.path.isfile(localFile.replace(".nhdr", ".raw.gz")):
                    missingFiles = missingFiles + localFile.replace(
                        ".nhdr", ".raw.gz") + ";"
                if missingFiles:
                    raise Exception(
                        "The download command did not return any error message, but the following files have not been downloaded: "
                        + missingFiles)

            except Exception as ex:
                # There was en error in the preferred method. If we are in a Unix system, we will try the backup method
                if os.sys.platform != "win32":
                    print((
                        "There was an error when downloading some of the files: "
                        + error))
                    print("Trying alternative method...")
                    self.executeDowloadCommand_Backup(fullStrCommand)

                    # If everything goes well, check the the path of the Nrrd file to verify that the file have been correctly downlaoded
                    missingFiles = ""
                    if not os.path.isfile(localFile):
                        missingFiles = missingFiles + localFile + ";"
                    if not os.path.isfile(localFile.replace(
                            ".nhdr", ".raw.gz")):
                        missingFiles = missingFiles + localFile.replace(
                            ".nhdr", ".raw.gz") + ";"
                    if missingFiles:
                        raise Exception(
                            "After a second attempt, the following files have not been downloaded: "
                            + missingFiles)

                    print("Apparently it worked!")
                else:
                    raise ex

        else:
            print("File {0} already cached".format(localFile))

        # Return path to the Nrrd header file
        return localFile