void SecretBoxArea::Init(GameCondition gameCondition) { secretboxes.clear(); boxSize = getBoxSize(gameCondition.resolution, 8, 12); bool xy[8][16]; for(int i = 0; i < 8; i++) for(int j = 0; j < 12; j++) xy[i][j] = false; while(secretboxes.size() < 8 * 12) { BoxType randomBoxType = (BoxType)IwRandMinMax(1, 4); for(int i = 0; i < 2; i++) { int32 x, y; do { x = IwRandMinMax(0, 8); y = IwRandMinMax(0, 12); } while (xy[x][y]); xy[x][y] = true; SecretBox *s = new SecretBox(randomBoxType); s->position = new CIwSVec2(y * boxSize->x + PADDING * (y + 1), x * boxSize->y + PADDING * (x + 1)); s->size = boxSize; secretboxes.push_back(s); } } }
direct_algo* direct_algo_init() { unsigned int i = 0; direct_algo* newInstance = (direct_algo*)malloc(sizeof(direct_algo)); newInstance->groupsList = (group*)malloc(sizeof(group)); newInstance->groupsList->boxesSize = getBoxSize(0, 0); newInstance->groupsList->boxes = (box*)malloc(sizeof(box)); for(;i < NUMBER_OF_DIMENSIONS_OF_ACTION; i++) { newInstance->groupsList->boxes->centerPosition[i] = 0.5; } newInstance->groupsList->boxes->level = 0; newInstance->groupsList->boxes->stage = 0; newInstance->groupsList->boxes->next = NULL; newInstance->groupsList->boxes->prev = NULL; newInstance->groupsList->lastOne = newInstance->groupsList->boxes; newInstance->groupsList->next = NULL; newInstance->groupsList->prev = NULL; newInstance->groupsList->nextPOGroup = NULL; newInstance->pOGroups = NULL; newInstance->boxesToBeAdded = newInstance->groupsList->boxes; newInstance->groupToAddTheBoxes = NULL; newInstance->epsilon = 0.001; newInstance->crtMax = 0.0; return newInstance; }
Room RoomGenerator::generate() { unsigned currentArea = 0; // Right-pointing-down, right-pointing-up, left-pointing-down, left-pointing-up, // bot-pointing-right, bot-pointing-left, top-pointing-right, top-pointing-left std::uniform_int_distribution<int> dirRand(0, 7); unsigned maxRighti = 0; unsigned maxLefti = 0; unsigned maxBoti = 0; unsigned maxTopi = 0; std::vector<RoomBox> boxes; std::vector<std::vector<int>> boxAdjacencyList; // Generate the root box glm::ivec2 size(getBoxSize(), getBoxSize()); currentArea += size.x * size.y; boxes.push_back(RoomBox()); boxes[0].right = (int)std::ceil(size.x / 2.0f); boxes[0].top = (int)std::ceil(size.y / 2.0f); boxes[0].left = (int)-std::floor(size.x / 2.0f); boxes[0].bottom = (int)-std::floor(size.y / 2.0f); int i = 0; while (currentArea < minimumArea) { RoomBox newBox; glm::ivec2 size(getBoxSize(), getBoxSize()); currentArea += size.x * size.y; unsigned direction = dirRand(this->generator); int matchingBoxi = -1; RoomBox matchingBox; RoomPortal portal; if (direction < 2) { // Match left to right matchingBoxi = maxRighti; matchingBox = boxes[matchingBoxi]; newBox.left = matchingBox.right; newBox.right = newBox.left + size.x; portal.x0 = portal.x1 = newBox.left; } else if (direction < 4) { // Match right to left matchingBoxi = maxLefti; matchingBox = boxes[matchingBoxi]; newBox.right = matchingBox.left; newBox.left = newBox.right - size.x; portal.x0 = portal.x1 = newBox.right; } else if (direction < 6) { // Match top to bottom matchingBoxi = maxBoti; matchingBox = boxes[matchingBoxi]; newBox.top = matchingBox.bottom; newBox.bottom = newBox.top - size.y; portal.y0 = portal.y1 = newBox.top; } else { // Match bottom to top matchingBoxi = maxTopi; matchingBox = boxes[matchingBoxi]; newBox.bottom = matchingBox.top; newBox.top = newBox.bottom + size.y; portal.y0 = portal.y1 = newBox.bottom; } if (direction < 4) { if (direction % 2 == 0) { // Match top to top newBox.top = matchingBox.top; newBox.bottom = newBox.top - size.y; } else { // Match bottom to bottom newBox.bottom = matchingBox.bottom; newBox.top = newBox.bottom + size.y; } portal.y0 = (std::max)(newBox.bottom, matchingBox.bottom); portal.y1 = (std::min)(newBox.top, matchingBox.top); } else { if (direction % 2 == 0) { // Match left to left newBox.left = matchingBox.left; newBox.right = newBox.left + size.x; } else { // Match right to right newBox.right = matchingBox.right; newBox.left = newBox.right - size.x; } portal.x0 = (std::max)(newBox.left, matchingBox.left); portal.x1 = (std::min)(newBox.right, matchingBox.right); } if (newBox.right > boxes[maxRighti].right) { maxRighti = boxes.size(); } if (newBox.left < boxes[maxLefti].left) { maxLefti = boxes.size(); } if (newBox.bottom < boxes[maxBoti].bottom) { maxBoti = boxes.size(); } if (newBox.top > boxes[maxTopi].top) { maxTopi = boxes.size(); } portal.otherBox = boxes.size(); boxes[matchingBoxi].portals.push_back(portal); portal.otherBox = matchingBoxi; newBox.portals.push_back(portal); boxes.push_back(newBox); } Room room(boxesToRoom(boxes)); room.rightmostBox = maxRighti; room.leftmostBox = maxLefti; room.topmostBox = maxTopi; room.bottommostBox = maxBoti; return room; }
void dividePOBoxes(direct_algo* instance) { box* crt = instance->pOGroups->boxes; group* modifiedGroup = instance->pOGroups; group* crtGroup = modifiedGroup->next; group* prevGroup = modifiedGroup; double shift = 1.0 / pow(3, crt->level + 1); unsigned int dimensionToDivide = crt->stage++; double boxSize = 0.0; if(crt->stage == NUMBER_OF_DIMENSIONS_OF_ACTION) { crt->stage = 0; crt->level++; } boxSize = getBoxSize(crt->level, crt->stage); while((crtGroup!= NULL) && (crtGroup->boxesSize > boxSize)) { prevGroup = crtGroup; crtGroup = crtGroup->next; } if((crtGroup == NULL) || (crtGroup->boxesSize < boxSize)) { if(crt->next == NULL) { instance->pOGroups = modifiedGroup->nextPOGroup; if(instance->pOGroups != NULL) instance->crtMaxPOGroup = instance->pOGroups->boxes->value; modifiedGroup->boxes = crt; modifiedGroup->lastOne = crt; modifiedGroup->boxesSize = boxSize; modifiedGroup->next = crtGroup; if(prevGroup != modifiedGroup) modifiedGroup->prev = prevGroup; else modifiedGroup->prev = NULL; modifiedGroup->nextPOGroup = NULL; if(modifiedGroup->prev == NULL) instance->groupsList = modifiedGroup; else modifiedGroup->prev->next = modifiedGroup; if(crtGroup != NULL) crtGroup->prev = modifiedGroup; instance->groupToAddTheBoxes = modifiedGroup; } else { group* newGroup = (group*)malloc(sizeof(group)); newGroup->boxesSize = boxSize; modifiedGroup->boxes = crt->next; modifiedGroup->boxes->prev = NULL; newGroup->boxes = crt; newGroup->lastOne = crt; crt->next = NULL; crt->prev = NULL; newGroup->next = crtGroup; newGroup->prev = prevGroup; newGroup->nextPOGroup = NULL; if(crtGroup != NULL) crtGroup->prev = newGroup; prevGroup->next = newGroup; instance->groupToAddTheBoxes = newGroup; if(instance->pOGroups->boxes->value != instance->crtMaxPOGroup) { instance->pOGroups = modifiedGroup->nextPOGroup; if(instance->pOGroups != NULL) instance->crtMaxPOGroup = instance->pOGroups->boxes->value; } } } else { if(crt->next == NULL) { instance->pOGroups = modifiedGroup->nextPOGroup; if(instance->pOGroups != NULL) instance->crtMaxPOGroup = instance->pOGroups->boxes->value; if(modifiedGroup->prev != NULL) modifiedGroup->prev->next = modifiedGroup->next; else instance->groupsList = modifiedGroup->next; if(modifiedGroup->next != NULL) modifiedGroup->next->prev = modifiedGroup->prev; free(modifiedGroup); } else { modifiedGroup->boxes = crt->next; modifiedGroup->boxes->prev = NULL; crt->next = NULL; crt->prev = NULL; if(instance->pOGroups->boxes->value != instance->crtMaxPOGroup) { instance->pOGroups = instance->pOGroups->nextPOGroup; if(instance->pOGroups != NULL) instance->crtMaxPOGroup = instance->pOGroups->boxes->value; } } addBoxToGroup(crtGroup, crt); instance->groupToAddTheBoxes = crtGroup; } /* The first new box */ instance->boxesToBeAdded = (box*)malloc(sizeof(box)); memcpy(instance->boxesToBeAdded->centerPosition, crt->centerPosition, sizeof(double) * NUMBER_OF_DIMENSIONS_OF_ACTION); instance->boxesToBeAdded->centerPosition[dimensionToDivide] += shift; /*New sample point*/ instance->boxesToBeAdded->level = crt->level; instance->boxesToBeAdded->stage = crt->stage; instance->boxesToBeAdded->prev = NULL; /* the second new box */ instance->boxesToBeAdded->next = (box*)malloc(sizeof(box)); memcpy(instance->boxesToBeAdded->next->centerPosition, crt->centerPosition, sizeof(double) * NUMBER_OF_DIMENSIONS_OF_ACTION); instance->boxesToBeAdded->next->centerPosition[dimensionToDivide] -= shift; /*New sample point*/ instance->boxesToBeAdded->next->level = crt->level; instance->boxesToBeAdded->next->stage = crt->stage; instance->boxesToBeAdded->next->next = NULL; instance->boxesToBeAdded->next->prev = NULL; }
void AGOSEngine_Waxworks::printBox() { uint16 BoxSize; *_boxBufferPtr = 0; _linePtrs[0] = _boxBuffer; if (_boxCR == 0) _boxLineCount++; stopAnimate(105); BoxSize = getBoxSize(); _variableArray[53] = BoxSize; animate(3, 1, 100, 0, 0, 0); changeWindow(5); switch (BoxSize) { case 1: _textWindow->x = 10; _textWindow->y = 163; _textWindow->width = 20; _textWindow->height = 1; _textWindow->textMaxLength = 26; break; case 2: _textWindow->x = 8; _textWindow->y = 160; _textWindow->width = 24; _textWindow->height = 2; _textWindow->textMaxLength = 32; break; case 3: _textWindow->x = 6; _textWindow->y = 156; _textWindow->width = 28; _textWindow->height = 3; _textWindow->textMaxLength = 37; break; case 4: _textWindow->x = 4; _textWindow->y = 153; _textWindow->width = 32; _textWindow->height = 4; _textWindow->textMaxLength = 42; break; case 5: _textWindow->x = 2; _textWindow->y = 150; _textWindow->width = 36; _textWindow->height = 5; _textWindow->textMaxLength = 48; break; default:_textWindow->x = 1; _textWindow->y = 147; _textWindow->width = 38; _textWindow->height = 6; _textWindow->textMaxLength = 50; break; } _textWindow->textColumn = 0; _textWindow->textRow = 0; _textWindow->textColumnOffset = 0; _textWindow->textLength = 0; justifyStart(); waitForSync(99); _boxBufferPtr = _boxBuffer; while (*_boxBufferPtr) justifyOutPut(*_boxBufferPtr++); _boxLineCount = 0; _boxBufferPtr = _boxBuffer; _lineCounts[0] = 0; _lineCounts[1] = 0; _lineCounts[2] = 0; _lineCounts[3] = 0; _lineCounts[4] = 0; _lineCounts[5] = 0; changeWindow(0); }