def test_two_rotations_greedy_depth_two(self): cube = cube_lib.Cube() cube.rotate_face( cube_lib.Rotation(cube_lib.Face.LEFT, is_clockwise=True)) cube.rotate_face( cube_lib.Rotation(cube_lib.Face.UP, is_clockwise=False)) model = mock.Mock() model.predict.return_value = [1.0] # We follow the solver for two steps, and verify that the cube is # solved. self.assertFalse(cube.is_solved()) solver = solver_lib.GreedySolver(cube, model, depth=2) self.assertEqual( solver.apply_next_rotation(), cube_lib.Rotation(cube_lib.Face.UP, is_clockwise=True)) self.assertFalse(solver.cube.is_solved()) self.assertEqual( solver.apply_next_rotation(), cube_lib.Rotation(cube_lib.Face.LEFT, is_clockwise=False)) self.assertTrue(solver.cube.is_solved())
def __init__(self): self.cube=cube.Cube() self.cube.rad_z=0;self.cube.rad_x=0;self.cube.rad_y=0 self.mode=1
def setUp(self): self.cube = c.Cube(3) self.solved = c.Cube(3)
# This is a Simple Feed-Forward Model. import cube import random import tensorflow as tf import numpy as np import os import cubeTrain as ct # Possible Values: FNN, CNN, RNN, MLN NETWORK_TYPE = 'MLN' DEPTH = 6 # Create a nxn Cube orderNum = 2 ncube = cube.Cube(order=orderNum) # Define the training parameters training_epochs = 20 training_batches = 100 batch_size = 5000 # Verification Paramters display_step = 1 test_data_size = 1000 # Solving Paramters total_solv_trials = 100 solvable_limit = 50 solvable_step = 999999
def test_cube_size(): """ Test the cube size is 3 """ c = cube.Cube() assert c.get_size() == 3
def setUp(self) -> None: self.cube = cube.Cube()
def test_swap(self): test_cube = cube.Cube() test_cube.facet_list[0] = 1 test_cube.facet_list[1] = 0 self.cube.swap(0, 1) self.assertEqual(test_cube, self.cube)
def setUp(self) -> None: self.cube = cube.Cube() self.solve_check = cube.SolvabilityChecker(self.cube)
# Implementation of the solver import cube as c import agent as a # Get a new agent and a new cube cube = c.Cube() agent = a.Agent(cube) # Start
from time import time start = time() cube = cb.Cube() for i in range(10000): cube.turn("R") vector = vectorize(cube.cube) print(time() - start) if __name__ == "__main__": file = open("data/removed/removed_1.txt", "r") lines = file.readlines() file.close() import random for i in range(100000): cub = cb.Cube() for j in range(15): thing = random.choice([ "R", "R2", "R'", "L", "L2", "L'", "B", "B2", "B'", "U", "U2", "U'", "F", "F2", "F'", "D", "D2", "D'" ]) cub.turn(thing) if str( unvectorize( ' '.join([str(i) for i in vectorize(cub.cube, True)]), True)) == str(cub) == False: print(cub.cube) # print(vectorize(cub.cube, True)) # print(unvectorize(' '.join([str(i) for i in vectorize(cub.cube, True)]), True)) # print() # speedtest()
def get_neighbors(self): neighbors = [] for move in self.moves: neighbor = cb.Cube(self.state, init_cube=True) neighbor.turn(move) neighbors.append(Node(neighbor, self.depth + 1, parent=self))
if __name__ == '__main__': test_seq_1 = ( "Li Li E L Ei Li B Ei R E Ri Z E L Ei Li Zi U U Ui Ui Ui B U B B B Bi " "Ri B R Z U U Ui Ui Ui B U B B B Ri B B R Bi Bi D Bi Di Z Ri B B R Bi " "Bi D Bi Di Z B B Bi Ri B R Z B L Bi Li Bi Di B D B Bi Di B D B L Bi Li " "Z B B B Bi Di B D B L Bi Li Z B Bi Di B D B L Bi Li Z B B B L Bi Li Bi " "Di B D Z X X F F D F R Fi Ri Di Xi Xi X X Li Fi L D F Di Li F L F F Zi " "Li Fi L D F Di Li F L F F Z F Li Fi L D F Di Li F L F Li Fi L D F Di " "Li F L F F Xi Xi X X Ri Fi R Fi Ri F F R F F F R F Ri F R F F Ri F F F " "F Ri Fi R Fi Ri F F R F F F R F Ri F R F F Ri F F Xi Xi X X R R F D Ui " "R R Di U F R R R R F D Ui R R Di U F R R Z Z Z Z Z Z R R F D Ui R R Di " "U F R R Z Z Z Z R R F D Ui R R Di U F R R Z Z Z Z Z Ri S Ri Ri S S Ri " "Fi Fi R Si Si Ri Ri Si R Fi Fi Zi Xi Xi") moves = test_seq_1.split() print("%s moves:" % len(moves)) print(" ".join(moves)) opt = optimize_moves(moves) print("%s moves:" % len(opt)) print(" ".join(opt)) orig = cube.Cube("OOOOOOOOOYYYWWWGGGBBBYYYWWWGGGBBBYYYWWWGGGBBBRRRRRRRRR") c, d = cube.Cube(orig), cube.Cube(orig) c.sequence(" ".join(moves)) d.sequence(" ".join(opt)) print(c, '\n') print(d) assert c == d
import directionEnum from pygame.locals import * pygame.init() windowHeight = 600 windowWidth = 600 window = pygame.display.set_mode((windowWidth, windowHeight)) GREEN = (20,220,10) virtualWorld = virtualWorld.VirtualWorld() cube1 = cube.Cube(point3D.Point3D(-2.0, 0.0, 10.0), 3.0) cube2 = cube.Cube(point3D.Point3D(2.0, 0.0, 10.0), 3.0) cube3 = cube.Cube(point3D.Point3D(-2.0, 0.0, 5.0), 3.0) cube4 = cube.Cube(point3D.Point3D(2.0, 0.0, 5.0), 3.0) virtualWorld.addElement(cube1) virtualWorld.addElement(cube2) virtualWorld.addElement(cube3) virtualWorld.addElement(cube4) def scale(lines): cameraHeight = virtualWorld.virtualCamera.height cameraWidth = virtualWorld.virtualCamera.width heightScale = windowHeight / cameraHeight widthScale = windowWidth / cameraWidth
import cube import detector import motors if __name__ == "__main__": # Detect the scramble scramble = detector.getScramble() # Generate a solution cube = cube.Cube() cube.insertScramble(scramble) solution = cube.getSolution() # Execute the solution motors.execute(solution)
def get_new_snack(): global s, snack if s.body[0].pos == snack.pos: s.add_cube() snack = cube.Cube(generate_random_snack_pos(s), color=con.green)
def setUp(self) -> None: self.cube = cube.Cube() self.alg = cube.Algorithm("R U R' U'", self.cube)
def test_step_forward_then_backward(self): default_cube = cube.Cube() self.alg.step() self.alg.step_back() self.assertEqual(default_cube, self.cube)
def main(): # Defines global elements to use global window global cube_shape global pyramid_shape global camera global camera_pos global camera_front global camera_up global camera_speed # Change coordinates of camera_pos and camera_up to change camera properties camera_pos = Vec3d(3, 3, 10, 1) camera_front = Vec3d(0, 0, -1, 1) camera_up = Vec3d(0, 1, 0, 1) camera_speed = 0.05 # The second argument is for target. Change for target object camera = Camera(camera_pos, Vec3d(0, 0, 0, 1), camera_up) cube_shape = cube.Cube() pyramid_shape = pyramid.Pyramid() # For now we just pass glutInit one empty argument. I wasn't sure what should or could be passed in (tuple, list, ...) # Once I find out the right stuff based on reading the PyOpenGL source, I'll address this. glutInit(sys.argv) # Select type of Display mode: # Double buffer # RGBA color # Alpha components supported # Depth buffer glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH) # get a 640 x 480 window glutInitWindowSize(640, 480) # the window starts at the upper left corner of the screen glutInitWindowPosition(0, 0) # Okay, like the C version we retain the window id to use when closing, but for those of you new # to Python (like myself), remember this assignment would make the variable local and not global # if it weren't for the global declaration at the start of main. window = glutCreateWindow("Jeff Molofee's GL Code Tutorial ... NeHe '99") # Register the drawing function with glut, BUT in Python land, at least using PyOpenGL, we need to # set the function pointer and invoke a function to actually register the callback, otherwise it # would be very much like the C version of the code. glutDisplayFunc(DrawGLScene) # Uncomment this line to get full screen. # glutFullScreen() # When we are doing nothing, redraw the scene. glutIdleFunc(DrawGLScene) # Register the function called when our window is resized. glutReshapeFunc(ReSizeGLScene) # Register the function called when the keyboard is pressed. glutKeyboardFunc(keyPressed) # Initialize our window. InitGL(640, 480) # Start Event Processing Engine glutMainLoop()
def setUp(self): self.cube = cube.Cube()
def main(): args = sys.argv debug = False i = 0 #check for -v (debug) or too many args if len(args) == 3: while i < len(args): if args[i] == "-v": debug = True del args[i] i = 0 i += 1 if len(args) != 2: print("invalid number/type of arguments") return False #allow user to choose how long the scramble is if sys.argv[1] == "-r": number = input("How many moves would you like to scramble? ") while not helper.is_int(number): print( "please provide a positive integer number for how many moves you want generated" ) number = input("How many moves would you like to scramble? ") demo_cube = cube.Cube() print("Starting Cube:", demo_cube) run_cube(demo_cube, demo_cube.scramble(int(number)), 1, debug) #default random 20 move scramble elif sys.argv[1] == "-d": demo_cube = cube.Cube() print("Starting Cube:", demo_cube) run_cube(demo_cube, demo_cube.scramble(20), 1, debug) #runs the scramble 100 times with given amount of moves elif sys.argv[1] == "-avg": if debug: print( "debug method cannot be run in conjunction with pretty print!") number = input("How many moves would you like to scramble? ") while not helper.is_int(number): print( "please provide a positive integer number for how many moves you want generated" ) number = input("How many moves would you like to scramble? ") average_100(number) elif sys.argv[1] == "-p": if debug: print( "debug method cannot be run in conjunction with pretty print!") pretty_print() #take user input for how to scramble the cube else: instructions = sys.argv[1] split_instructions = instructions.split() for instruction in split_instructions: if len(instruction) not in (1, 2): print( "{} is not a correct instruction (length in correct), please try again" .format(instruction)) exit() if instruction[0] not in ('F', 'B', 'R', 'L', 'U', 'D'): print( "{} is not a correct instruction (first character incorrect), please try again" .format(instruction)) exit() if len(instruction) == 2: if instruction[1] not in ('2', '\''): print( "{} is not a correct instruction (second character incorrect), please try again" .format(instruction)) exit() demo_cube = cube.Cube() print("Starting Cube:", demo_cube) run_cube(demo_cube, split_instructions, 0, debug)
def setUp(self) -> None: self.cube = cube.Cube() self.COLORS = cube.Color
import tensorflow as tf import numpy as np import cube import cube_nn as nn1 import cube_nn_c as nn2 import cube_nn_p2 as nn3 import handle_data as h_d import time import queue as Q import copy import math import sys script, choice = argv q = cube.Cube(True) F2L = False def is_solved(scramble): if (F2L): if (not np.array_equal(scramble[1, :], np.ones(9, ))): return False for i in range(2, 6): if (not np.array_equal(scramble[i, 3:], np.ones(6, ) * i)): return False return True for i in range(6): solved = np.ones(9, ) * i if (not np.array_equal(scramble[i, :], solved)): return False
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE) glEnable(GL_CULL_FACE) glCullFace(GL_BACK) glClearColor(0.0, 0.0, 0.0, 0.0) glLoadIdentity() glOrtho(0.0, width, height, 0.0, -100000.0, 100000.0) glPointSize(1.0) glTranslatef(width / 2, height / 2, 0.0) glScalef(0.25, 0.25, 0.25) glRotatef(180.0, 0.0, 0.0, 1.0) glRotatef(20.0, 1.0, 1.0, 0.0) glutMainLoop() height = 900 width = 1600 keyboard_camera = camera.Camera() box = cube.Cube(1000, constants.cube_indices(), 0.8, 0.2) ball_list = spheres.Spheres(20, 125, 2.0, box.size, 0.8, 0.2) delta_time = delta_time.DeltaTime() main()
def IDcache(depth=5, filename=f"{cb.PREFIX}temp.pickle"): with open(filename, "w"): pass cube = cb.Cube() solver.IDsolve(cube, (None, lambda cube, moves: False), cb.HTM, depth, filename)
BUTTON_NAMES = [['new', 'scramble'], ['do', 'o'], ['solve', 'options']] BUTTONS_SHAPE = (len(BUTTON_NAMES), len(BUTTON_NAMES[0])) assign_button_coordinates(BUTTON_NAMES, WIDTH - BUTTONS_SHAPE[1] * BUTTON_WIDTH // 0.9, HEIGHT - BUTTONS_SHAPE[0] * BUTTON_HEIGHT // 0.9) FONT = pygame.font.SysFont('bahnschrift', 12) TEXT_COLOR = (0, 0, 0) COLOR_CHOICE_WIDTH = WIDTH // 18 COLOR_CHOICE_HEIGHT = COLOR_CHOICE_WIDTH COLOR_CHOICE_X = WIDTH - 6 * COLOR_CHOICE_WIDTH COLOR_CHOICE_Y = 1 assign_color_choice_coordinates(COLOR_CHOICE_X, COLOR_CHOICE_Y) c = cube.Cube() CUBE_WIDTH, CUBE_HEIGHT = WIDTH // 1.2, HEIGHT // 1.5 CUBE_X, CUBE_Y = WIDTH // 15, HEIGHT // 30 assign_cube_coordinates(c, CUBE_X, CUBE_Y, CUBE_WIDTH, CUBE_HEIGHT) moves_to_do = zip(*c.from_notation("R2 U R U R' U' R' U' R' U R'2")) def main_menu(): while True: click = False events = pygame.event.get() for event in events: if event.type == QUIT: pygame.quit() sys.exit()
def test_cube3(self): self.assertEqual(cube.Cube("l"), None)
import cube from species import Population new_cube = cube.Cube() new_cube.scramble() new_pop = Population(new_cube) while new_pop.generation < 5: print(new_pop.best_species()) new_pop.new_generation()
def test_cube1(self): self.assertEqual(cube.Cube(2), 8)
def main(): # create render window window = grapher.Grapher() # create cube models render_models = list() render_models.append(cube.Cube()) render_models.append(cube.Cube()) render_models.append(cube.Cube()) render_models.append(cube.Cube()) render_models[0].set_pos(5, 0, 10) render_models[1].set_pos(-5, 0, 10) render_models[2].set_pos(5, -4, 13) render_models[3].set_pos(-5, -7, 10) # create walls render_models.append(wall.Wall()) render_models[4].set_pos(0, -8, 25) render_models[4].scale = 8 render_models.append(wall.Wall()) render_models[5].set_pos(16, -8, 9) render_models[5].set_rot(0, 90, 0) render_models[5].scale = 8 # create camera cam = camera.Camera() # temp r = 0 s = 0.2 # main loop try: while True: # clear grapher window.clear() # render models in render_models list for rm in render_models: # set global model-space stuff here rm.set_rot_delta(r, r, r) # transform model and get transformed coordinate pairs coords = rm.process(cam, fov) # render segments from coordinate pair list for i in coords: # gather depth coordinates sz = i[0][2] ez = i[1][2] # if segment is completely behind player, skip rendering if sz < 0 and ez < 0: continue # gather transformed coordinates startx = i[0][0] starty = i[0][1] endx = i[1][0] endy = i[1][1] # if segment is partially behind player, clip segment to camera's field of view if sz < 0 or ez < 0: # ffffuuuuuuu pass # draw segment window.draw_line(startx, starty, endx, endy) # draw debug text coords = "Player: (%f, %f, %f)" % (cam.pos_x, cam.pos_y, cam.pos_z) pang = "Player angle: %f" % cam.angle options = "Options: ROT: %d, SPD: %d" % (r, s) window.console_out("3D Engine test - HalfBurntToast") window.console_out(coords) window.console_out(pang) window.console_out(options) # update grapher window.update() # get command input for event in pygame.event.get(): if event.type == pygame.KEYDOWN: if event.key == pygame.K_r: r = int(not r) if event.key == pygame.K_p: cam.reset() print("Reset") # get movement input keys = pygame.key.get_pressed() if keys[pygame.K_w]: ang = numpy.deg2rad(numpy.abs(360 - cam.angle)) cam.pos_z -= numpy.cos(ang) * s cam.pos_x -= numpy.sin(ang) * s if keys[pygame.K_s]: ang = numpy.deg2rad(numpy.abs(360 - cam.angle)) cam.pos_z += numpy.cos(ang) * s cam.pos_x += numpy.sin(ang) * s if keys[pygame.K_a]: ang = numpy.deg2rad(numpy.abs(360 - (cam.angle - 90))) cam.pos_z += numpy.cos(ang) * s cam.pos_x += numpy.sin(ang) * s if keys[pygame.K_d]: ang = numpy.deg2rad(numpy.abs(360 - (cam.angle - 90))) cam.pos_z -= numpy.cos(ang) * s cam.pos_x -= numpy.sin(ang) * s if keys[pygame.K_e]: cam.angle = (cam.angle - 0.6) % 360 if keys[pygame.K_q]: cam.angle = (cam.angle + 0.6) % 360 # if not using any input handling, uncommon the line below #pygame.event.pump() # temp delay. TODO: replace with FPS regulator pygame.time.delay(10) except KeyboardInterrupt: pygame.quit()
def test_cube2(self): self.assertEqual(cube.Cube(-3), -27)