void transformCube(struct Cube_t *cube, enum Move_e move) { struct Cube_t *orig = GlobalAlloc(0, sizeof(struct Cube_t)); CopyMemory(orig, cube, sizeof(struct Cube_t)); moveCube(cube, orig, move); GlobalFree(orig); return; }
void expandCube(struct Cube_t *cube) { #if LEVEL > DEBUG_WARN printf("expandCube()\n"); #endif if (cube->depth >= g_uMaxDepth) return; int m; for (m=0;m<UNIQUE_MOVES;m++) { struct Cube_t *childCube = GlobalAlloc(0, sizeof(struct Cube_t)); CopyMemory(childCube, cube, sizeof(struct Cube_t)); DEBUG printf("moveCube() %u\n", m); moveCube(cube, childCube, m); if (!isFirst(childCube, &rootCube)) { DEBUG printf("cube was not first\n"); GlobalFree(childCube); continue; } pruneClones(childCube, &rootCube); childCube->parent = cube; childCube->lastMove = m; childCube->depth = cube->depth + 1; ZeroMemory(&(childCube->nextMove), sizeof(childCube->nextMove)); cube->nextMove[m] = childCube; DEBUG printMoveSequence(childCube); DEBUG putchar('\n'); DEBUG printCube(childCube); if (compareCube(childCube, &solvedCube)) { printMoveSequence(childCube); printCube(childCube); printf("SOLUTION\n"); exit(0); } else { expandCube(childCube); } } }
void transformCube(Cube *cube, enum Move_e move) { //Cube *orig = GlobalAlloc(0, sizeof(Cube)); Cube *orig = malloc(sizeof(Cube)); //CopyMemory(orig, cube, sizeof(Cube)); memcpy(orig, cube, sizeof(Cube)); moveCube(cube, orig, move); //GlobalFree(orig); free(orig); return; }
void generateCube(Cube *parentCube, enum Move_e thisMove) { Cube *thisCube; #ifndef NDEBUG printMoveSequence(parentCube); debug(", %d\n", thisMove); #endif if (thisMove == -1) { debug("cube is root\n"); thisCube = parentCube; goto justmove; } //alloc space for new cube //thisCube = GlobalAlloc(0, sizeof(Cube)); thisCube = malloc(sizeof(Cube)); //generate new cube //CopyMemory(thisCube, parentCube, sizeof(Cube)); memcpy(thisCube, parentCube, sizeof(Cube)); thisCube->depth = parentCube->depth + 1; moveCube(parentCube, thisCube, thisMove); //check cube validity debug("validating cube\n"); if (!validateCube(&rootCube, thisCube)) { //GlobalFree(thisCube); free(thisCube); return; } //take action and set handles //ZeroMemory(&thisCube->nextMove, sizeof(thisCube->nextMove)); memset(&thisCube->nextMove, '\0', sizeof(thisCube->nextMove)); thisCube->parent = parentCube; thisCube->lastMove = thisMove; parentCube->nextMove[thisMove] = thisCube; //make additional moves if appropriate justmove: debug("checking if cube is solution\n"); if (compareCube(thisCube, &solvedCube)) { printf("cube matched solution\n"); printMoveSequence(thisCube); printf("\n"); printCube(thisCube); pause(); return; } //if (thisCube->depth >= g_uMaxDepth) return; int m; for (m=0; m<UNIQUE_MOVES; m++) { generateCube(thisCube, m); } return; }
void generateCube(struct Cube_t *parentCube, enum Move_e thisMove) { struct Cube_t *thisCube; DEBUG printMoveSequence(parentCube); DEBUG printf(", %d\n", thisMove); if (thisMove == -1) { DEBUG printf("cube is root\n"); thisCube = parentCube; goto justmove; } //alloc space for new cube thisCube = GlobalAlloc(0, sizeof(struct Cube_t)); //generate new cube CopyMemory(thisCube, parentCube, sizeof(struct Cube_t)); thisCube->depth = parentCube->depth + 1; moveCube(parentCube, thisCube, thisMove); //check cube validity DEBUG printf("validating cube\n"); if (!validateCube(&rootCube, thisCube)) { GlobalFree(thisCube); return; } //take action and set handles ZeroMemory(&thisCube->nextMove, sizeof(thisCube->nextMove)); thisCube->parent = parentCube; thisCube->lastMove = thisMove; parentCube->nextMove[thisMove] = thisCube; //make additional moves if appropriate justmove: DEBUG printf("checking if cube is solution\n"); if (compareCube(thisCube, &solvedCube)) { printf("cube matched solution\n"); printMoveSequence(thisCube); printf("\n"); printCube(thisCube); pause(); return; } if (thisCube->depth >= g_uMaxDepth) return; int m; for (m=0;m<UNIQUE_MOVES;m++) { generateCube(thisCube, m); } return; }
void expandCube(Cube *cube) { //if (cube->depth >= g_uMaxDepth) return; int m; for (m=0; m<UNIQUE_MOVES; m++) { //Cube *childCube = GlobalAlloc(0, sizeof(Cube)); Cube *childCube = malloc(sizeof(Cube)); //CopyMemory(childCube, cube, sizeof(Cube)); memcpy(childCube, cube, sizeof(Cube)); debug("moveCube() %u\n", m); moveCube(cube, childCube, m); if (!isFirst(childCube, &rootCube)) { debug("cube was not first\n"); //GlobalFree(childCube); free(childCube); continue; } pruneClones(childCube, &rootCube); childCube->parent = cube; childCube->lastMove = m; childCube->depth = cube->depth + 1; //ZeroMemory(&(childCube->nextMove), sizeof(childCube->nextMove)); memset(&childCube->nextMove, '\0', sizeof(childCube->nextMove)); cube->nextMove[m] = childCube; #ifndef NDEBUG printMoveSequence(childCube); putchar('\n'); printCube(childCube); #endif if (compareCube(childCube, &solvedCube)) { printMoveSequence(childCube); printCube(childCube); printf("SOLUTION\n"); exit(0); } else { expandCube(childCube); } } }
Cube *expandGeneration(Cube *cube, unsigned gen) { Cube *result, *child; if (cube->depth < gen) { //traverse for (int m = 0; m < UNIQUE_MOVES; m++) { if (cube->nextMove[m] == NULL) continue; result = expandGeneration(cube->nextMove[m], gen); if (result != NULL) return result; } } else if (cube->depth == gen) { //expand generation for (int m = 0; m < UNIQUE_MOVES; m++) { assert(cube->nextMove[m] == NULL); child = Cube_New(); verify(memcpy(child->face, cube->face, sizeof(child->face)) == child->face); moveCube(child, cube, m); child->parent = cube; child->lastMove = m; child->depth = cube->depth + 1; if (compareCube(child, &solvedCube)) { cube->nextMove[m] = child; return child; } //if (FALSE) { if (!isFirst(&rootCube, child)) { //GlobalFree(child); free(child); continue; } else { cube->nextMove[m] = child; } } } else { fatal(0, "Something really f****d up here"); } return NULL; }
struct Cube_t *expandGeneration(struct Cube_t *cube, UINT generation) { int m; struct Cube_t *result, *child; if (cube->depth < generation) { //traverse for (m = 0; m < UNIQUE_MOVES; m++) { if (cube->nextMove[m] == NULL) continue; result = expandGeneration(cube->nextMove[m], generation); if (result != NULL) return result; } } else if (cube->depth == generation) { //expand generation for (m = 0; m < UNIQUE_MOVES; m++) { child = GlobalAlloc(0, sizeof(struct Cube_t)); ZeroMemory(child, sizeof(struct Cube_t)); CopyMemory(&child->face, &cube->face, sizeof(struct Face_t[FACES_PER_CUBE])); moveCube(child, cube, m); child->parent = cube; child->lastMove = m; child->depth = cube->depth + 1; if (compareCube(child, &solvedCube)) { cube->nextMove[m] = child; return child; } //if (FALSE) { if (!isFirst(&rootCube, child)) { GlobalFree(child); continue; } else { cube->nextMove[m] = child; } } } else { MessageBox(NULL, "something really f****d up here", NULL, 0); exit(0); } return NULL; }
void ColoredCubeApp::updateScene(float dt) { timer -= dt; std::wostringstream outs; if(timer<=0) { outs.clear(); outs << L"GAME OVER\nFINAL SCORE: " << score; mTimer = outs.str(); return; } outs.precision(2); outs << L"Time: " << timer << L"\n"; outs.precision(3); outs << "Score: " << score; mTimer = outs.str(); //store old position and reset it if collide, very hackish shootCube.setVelocity(moveCube()); auto oldSpot = shootCube.getPosition(); D3DApp::updateScene(dt); leftWall.update(dt); //floor.update(dt); rightWall.update(dt); //ceiling.update(dt); hitCubes->update(dt); avoidCubes->update(dt); //from game jam //if(((int)timer)%5==0) //{ // for(int i = 0; i < 20; i++) // { // if(!tiles[i].getActiveState()) // { // tiles[i].setActive(); // tiles[i].setPosition(Vector3((-5+rand()%10)*3,0,(-5+rand()%10)*3)); // break; // } // } //} //for(int i = 0; i < 20; i++) //{ // tiles[i].update(dt); // //wall[i].update(dt); //} shootCube.update(dt); for(int i = 0; i < 20; i++) { if(shootCube.collided(&tiles[i])) { tiles[i].setInActive(); score++; audio->playCue(GUN_SHOT); //shootCube.setPosition(oldSpot); } //if(shootCube.collided(&wall[i])) //{ // //shootCube.setPosition(oldSpot); // wall[i].setInActive(); //} } int numHits = hitCubes->checkCollisions(shootCube); score+=numHits; int numBadHits = avoidCubes->checkCollisions(shootCube); score-=numBadHits; if(numHits>0) { audio->playCue(GUN_SHOT); } if(numBadHits>0) { audio->playCue(TARGET_SHATTER); } if(shootCube.getPosition().x<-18 || shootCube.getPosition().x>18 || shootCube.getPosition().z<-18 || shootCube.getPosition().z>18) { shootCube.setPosition(oldSpot); } // Build the view matrix. D3DXVECTOR3 pos(0.0f,50.0f,0.001f); D3DXVECTOR3 target(0.0f, 0.0f, 0.0f); D3DXVECTOR3 up(0.0f, 1.0f, 0.0f); D3DXMatrixLookAtLH(&mView, &pos, &target, &up); }