/* -*- c++ -*- FILE: Puzzlest.cpp RCS REVISION: $Revision: 1.13 $ COPYRIGHT: (c) 1999 -- 2003 Melinda Green, Don Hatch, and Jay Berkenbilt - Superliminal Software LICENSE: Free to use and modify for non-commercial purposes as long as the following conditions are adhered to: 1) Obvious credit for the source of this code and the designs it embodies are clearly made, and 2) Ports and derived versions of 4D Magic Cube programs are not distributed without the express written permission of the authors. DESCRIPTION: Implementation of PuzzleState class */ #include "Puzzlest.h" #include "Polymgr.h" #include "Math4d.h" #include "Preferences.h" PuzzleState::PuzzleState(Preferences& p, PolygonManager4D *polymgr) : preferences(p) { m_polymgr = polymgr; reset(p.getLength()); } /* * Set the puzzle to the pristine state */ void PuzzleState::reset(int new_length) { if (new_length != -1) { this->length = new_length; nstickers = NFACES * length * length * length; } int i, nstickersperface = length * length * length; for(i=0; idim) { case 0: total_angle = 2 * PI / 3 * dir; break; case 1: total_angle = 2 * PI / 2 * dir; break; case 2: total_angle = 2 * PI / 4 * dir; break; default: abort(); } /* * Calculate rotation center; it's the center of the face containing * the grip */ whichax = -1; for (i = 0; i < NDIMS; ++i) { if (ABS(grip->coords[i]) == 3) { center[i] = grip->coords[i]; whichax = i; } else center[i] = 0; } assert(INRANGE(0 <=, whichax, coords); Math4d::get4dRotMatrix(center, real_stickercoords, total_angle, realmat); for (i = 0; i < 4; ++i) for (j = 0; j < 4; ++j) { mat[i][j] = ROUND(realmat[i][j]); assert(ABS(realmat[i][j] - mat[i][j]) < .0001); } sgn = SGN(center[whichax]); nranges = m_polymgr->makeRangesInt(slicesmask, whichax, sgn, ranges); } /*=========================================================*/ for (i = 0; i < nstickers; ++i) { struct stickerspec tempsticker; tempsticker.id_within_cube = i; m_polymgr->fillStickerspecFromId(&tempsticker); for (j = 0; j < nranges; ++j) { if (INRANGE(ranges[j][0] <=, tempsticker.coords[whichax], <=ranges[j][1])) { VXM4i(tempsticker.coords, tempsticker.coords, mat); m_polymgr->fillStickerspecFromCoords(&tempsticker); assert(INRANGE(0 <=, tempsticker.id_within_cube,