Commit 1f359b32 by Guillaume CLOCHARD

### Merge branch 'tuto' into 'master'

```Amélioration du tuto

Ajout de la progression dans le tuto, autres petits détails

See merge request !15```
parents 28ab5548 9b9d3975
 from utils import Array, codeToColor, codeToGroup, colorize from numpy import copy as np_copy from numpy import copy as np_copy, array_equal as np_array_equal from copy import deepcopy PETITS_CUBES = ['FU','FRU','FR','FRD','FD','LFD','FL','LFU','LU','LD', ... ... @@ -990,6 +990,50 @@ class Cube(): else: return "Erreur dans les paramètres de la fonction" def resolu(self): """ resolu() Détermine si le cube est résolu :Returns: {Bool} """ ok = { #1ère couronne 'FU' : Array([1, 5]), 'FRU': Array([1, 2, 5]), 'RU' : Array([2, 5]), 'RBU': Array([2, 3, 5]), 'BU' : Array([3, 5]), 'BLU': Array([3, 4, 5]), 'LU' : Array([4, 5]), 'LFU': Array([4, 1, 5]), #2ème couronne 'FR' : Array([1, 2]), 'BR' : Array([3, 2]), 'BL' : Array([3, 4]), 'FL' : Array([1, 4]), #3ème couronne 'FD' : Array([1, 0]), 'FRD': Array([1, 2, 0]), 'RD' : Array([2, 0]), 'RBD': Array([2, 3, 0]), 'BD' : Array([3, 0]), 'BLD': Array([3, 4, 0]), 'LD' : Array([4, 0]), 'LFD': Array([4, 1, 0]), } for (k,v) in self.cubes.items(): if not np_array_equal(v, ok[k]): return False return True def copy(self): """ copy ... ...
This diff is collapsed.
 ... ... @@ -37,7 +37,7 @@ if __name__=="__main__": """ :Example: python poqb.py python poqb.py -c YYYYYYYYYOOOBBBRRRGGGOOOBBBRRRGGGOOOBBBRRRGGGWWWWWWWWW python poqb.py -cYYYYYYYYYOOOBBBRRRGGGOOOBBBRRRGGGOOOBBBRRRGGGWWWWWWWWW python poqb.py --cube=YYYYYYYYYOOOBBBRRRGGGOOOBBBRRRGGGOOOBBBRRRGGGWWWWWWWWW """ ... ... @@ -54,8 +54,8 @@ if __name__=="__main__": print('Résolution de :', "".join([colorize(x) for x in cube])) tuto(cube_lu, resolution) print('Résolution de :', "".join([colorize(x) for x in cube])) print('Résolution de :', "".join([colorize(x) for x in cube]) +'\n') resolution = " ".join([translate_mvt(x) for x in resolution]) print("Exécuter la manoeuvre {}".format(resolution)) print("Exécuter la manoeuvre : {}".format(resolution) +'\n')
 from time import sleep from utils import clear, readArgs from utils import clear, readArgs, colorize, translate_mvt, newGetch, TermColors from algo import algo_cfop SPEED = 2 #écrans / sec ... ... @@ -13,18 +13,52 @@ def tuto(cube, mouvements): mouvements {List} Suite de mouvements à appliquer sur le cube pour le résoudre, calculée par algo_cfop() """ #lecture des paramètres params = readArgs() speed = float(params['speed']) if 'speed' in params else SPEED resolution = " ".join([translate_mvt(x) for x in mouvements]) mouvementsDone = [] mouvementsRestants = list(mouvements) clear() print("Exécution de la manoeuvre : {}".format(resolution) ) print(cube) for m in mouvements: clear() mouvementsRestants.remove(m) method = getattr(cube, 'rot_' + m) method() print( "Exécution de la manoeuvre : " #les mouvements effectués + TermColors.green + \ "{}".format(" ".join([translate_mvt(x) for x in mouvementsDone]))+ \ TermColors.end + ' ' + #le mouvement actuel TermColors.bgGreen + translate_mvt(m) + TermColors.end + \ #les mouvements restant " {}".format(" ".join([translate_mvt(x) \ for x in mouvementsRestants]) ) + '\n' ) print(cube) print(m) sleep(1 / speed) print("Rotation : ", m +'\n\n') mouvementsDone.append(m) if 'auto' not in params: print('Press any key to continue . . .\n') newGetch() else: sleep(1 / speed) if __name__ == '__main__': from lire_entree import lecture_cube ... ...
 ... ... @@ -4,6 +4,7 @@ from os import name as os_name import subprocess import getopt COULEURS = ['W', 'B', 'R', 'G', 'O', 'Y'] def Array(arr): ... ... @@ -287,6 +288,16 @@ def ftl_valide(c): return facettes == valide def cfop_valide(cube, mouvements): """ cfop_valide :Returns: {Boolean} True si la suite de mouvements appliquée sur cube donne bien un cube résolu """ cube.mouvements(mouvements) return cube.resolu() def translate_mvt(mvt): """ ... ... @@ -319,10 +330,11 @@ def readArgs(): optlist, args = getopt.getopt( sys.argv[1:], 'c:s:t', 'c:s:ta', ['cube=', 'speed=', 'tuto'] 'tuto', 'auto'] ) arguments = {k: v for k, v in optlist} #on tranforme la list en dict ... ... @@ -345,6 +357,12 @@ def readArgs(): if '--tuto' in arguments: result['tuto'] = arguments['--tuto'] #--tuto override -t if '-a' in arguments: result['auto'] = arguments['-a'] if '--auto' in arguments: result['auto'] = arguments['--auto'] #--auto override -a return result def clear(): ... ... @@ -360,6 +378,29 @@ def clear(): else: subprocess.call("clear") # linux/mac def newGetch(): """ newGetch Ecoute le premier caractère saisi par l'user Voir : http://code.activestate.com/recipes/134892/ """ if os_name == 'nt': # windows from msvcrt import getch return getch() else: # linux/mac import tty, termios fd = sys.stdin.fileno() old_settings = termios.tcgetattr(fd) try: tty.setraw(sys.stdin.fileno()) ch = sys.stdin.read(1) finally: termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) return ch if __name__ == '__main__': print("Test unixTermColors") ... ...
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!