void LVConvertModel(const model *model_in, LVlinear_model *model_out){ // Convert svm_model to LVsvm_model model_out->nr_class = model_in->nr_class; model_out->nr_feature = model_in->nr_feature; model_out->bias = model_in->bias; int nr_class = model_in->nr_class; int nr_feature = model_in->nr_feature; // Label if (model_in->label != nullptr){ LVResizeNumericArrayHandle(model_out->label, nr_class); MoveBlock(model_in->label, (*(model_out->label))->elt, nr_class * sizeof(int32_t)); (*model_out->label)->dimSize = model_in->nr_class; } else{ (*model_out->label)->dimSize = 0; } // w int32_t nr_w = nr_feature * nr_class; // If bias is present, the feature vector increases by one if (model_in->bias >= 0) nr_w += nr_class; if (model_out->w != nullptr){ LVResizeNumericArrayHandle(model_out->w, nr_w); MoveBlock(model_in->w, (*(model_out->w))->elt, nr_w * sizeof(double)); (*model_out->w)->dimSize = nr_w; } else{ (*model_out->w)->dimSize = 0; } }
void Shuffle( HWND hwnd ) { enum { LEFT = 0, RIGHT = 1, UP = 2, DOWN = 3}; srand(time(0) ); // 초기 빈곳은 4,4 이다. int empty_x = COUNT-1; // <<--- int empty_y = COUNT-1; // <<--- int count = 0; while( 1 ) { // 랜덤 값을 0~3을 얻는다. switch( ( rand() % 4) ) { // 랜덤 값에 따라 빈곳의 위,아래, 좌,우 중 1개를 얻는다. case LEFT: empty_x = max(0, empty_x - 1 ); break; case RIGHT:empty_x = min(COUNT-1, empty_x + 1 ); break; // <<---- case UP: empty_y = max(0, empty_y - 1 ); break; case DOWN: empty_y = min(COUNT-1, empty_y + 1 ); break; // <<---- } // 선택된 블록을 이동 해본다. 이동 불가능 할수도 있다. 250번 섞을때까지! if ( MoveBlock( hwnd, empty_x, empty_y) ) { ++count; if ( count == COUNT * 50 ) break; // 250 번 섞는다. Sleep(50); // 1블록을 섞은후에 0.05s 대기 한다. } } }
void LVConvertModel(const model &model_in, LVlinear_model &model_out){ // Convert svm_model to LVsvm_model model_out.nr_class = model_in.nr_class; model_out.nr_feature = model_in.nr_feature; model_out.bias = model_in.bias; int nr_class = model_in.nr_class; int nr_feature = model_in.nr_feature; // Label if (model_in.label != nullptr){ LVResizeNumericArrayHandle(model_out.label, nr_class); MoveBlock(model_in.label, (*(model_out.label))->elt, nr_class * sizeof(int32_t)); (*model_out.label)->dimSize = model_in.nr_class; } else{ (*model_out.label)->dimSize = 0; } // n is equal to nr_feature, incremented if bias is present int n = nr_feature; if (model_in.bias >= 0) n++; // nr_w is equal to nr_class with one exception int nr_w; if (model_in.nr_class == 2 && model_in.param.solver_type != MCSVM_CS) nr_w = 1; else nr_w = model_in.nr_class; if (model_in.w != nullptr){ LVResizeNumericArrayHandle(model_out.w, n*nr_w); MoveBlock(model_in.w, (*(model_out.w))->elt, nr_w * n * sizeof(double)); (*model_out.w)->dimSize = nr_w*n; } else{ (*model_out.w)->dimSize = 0; } }
void LVException::populateErrorCluster(lvError * err) { std::string debugInfo; err->code = m_code; err->status = true; if (m_debug){ debugInfo = "<<DEBUGINFO: File="; debugInfo += m_file; debugInfo += " Line="; debugInfo += std::to_string(m_line); debugInfo += ">> "; m_messageLength += debugInfo.size(); } // Check if the existing string handle is valid. if (DSCheckHandle(err->source) == mgNoErr) { // Handle valid: Check if it needs to be resized if ((m_messageLength + sizeof(int32_t)) > DSGetHandleSize(err->source)) { DSSetHandleSize(err->source, sizeof(int32_t) + m_messageLength); } } else { // Handle invalid: Create a new string handle err->source = (LStrHandle)DSNewHandle(sizeof(int32_t) + m_messageLength); } if (m_debug) { // Move the string data (with debug info) debugInfo += this->what(); MoveBlock(debugInfo.c_str(), (*err->source)->str, m_messageLength); } else { // Move the string data (without debug info) MoveBlock(this->what(), (*err->source)->str, m_messageLength); } // Set the string length variable (*err->source)->cnt = static_cast<int32>(m_messageLength); }
void OnLButtonDown(HWND hwnd, BOOL fDoubleClick, int x, int y, UINT keyFlags) { // 게임이 실행중이 아니거나 게임판을 벗어난 경우 if ( (!g_bRunning) || ( x < OX ) || ( x > OX + g_szFull.cx) || ( y < OY ) || ( y > OY + g_szFull.cy ) ) return ; // 좌표(pixel) 블록 x,y 구하기 int xBlock = (x - OX) / g_szBlock.cx; int yBlock = (y - OY) / g_szBlock.cy; // 이동 가능 하면 이동. 불가능하는 FALSE 가 나오는 함수. if ( ! MoveBlock( hwnd, xBlock, yBlock) ) MessageBeep( 0 ); }
void LVlinear_print_function(const char * message){ LVUserEventRef *usrEv = loggingUsrEv; if (usrEv != nullptr && message != nullptr){ // Filter out the progress messages (.....) if (strcmp(message, ".") != 0){ // Move the string to a handle size_t length = strlen(message); LStrHandle lvmsg = (LStrHandle)DSNewHandle(sizeof(int32_t) + length); MoveBlock(message, (*lvmsg)->str, length); (*lvmsg)->cnt = static_cast<int32>(length); // Post the string to the user event PostLVUserEvent(*usrEv, &lvmsg); } } }
void GetNextBlock() { for(int x=0; x<4; x++) for(int y=0; y<4; y++) if(BlockMatrix[x][y] != BLANK) ScreenBackgroundLayout[BlockX+x][BlockY+y] = BlockMatrix[x][y]; //stop the block moving down CheckForLine(); //checking if lines are filled AssignShape(NextShape, NextColor); //assign new block NextShape = GetRandomShape(); //assign next shape NextColor = GetRandomColor(); //assign next color DisplayNextShape(); //display next block BlockX = 7; //restore value of BlockX & BlockY BlockY = 0; if(MoveBlock(LEFT)) //if block collides with something return 1 { GameOver=1; } }
void RotateBlock() { int TempBlockMatrix[4][4]; for(int i=0; i<4; i++) for(int j=0; j<4; j++) TempBlockMatrix[i][j] = BlockMatrix[i][j]; switch(CurrentShape) { case SHAPE_O: //in case O no change return; case SHAPE_L: //Changes 8 pos around (1,1) point case SHAPE_L2: case SHAPE_S: case SHAPE_S2: case SHAPE_T: BlockMatrix[0][0] = TempBlockMatrix[2][0]; BlockMatrix[0][2] = TempBlockMatrix[0][0]; BlockMatrix[2][2] = TempBlockMatrix[0][2]; BlockMatrix[2][0] = TempBlockMatrix[2][2]; BlockMatrix[0][1] = TempBlockMatrix[1][0]; BlockMatrix[1][2] = TempBlockMatrix[0][1]; BlockMatrix[2][1] = TempBlockMatrix[1][2]; BlockMatrix[1][0] = TempBlockMatrix[2][1]; break; case SHAPE_I: BlockMatrix[0][1] = TempBlockMatrix[1][0]; //Changes only 3 position BlockMatrix[1][0] = TempBlockMatrix[0][1]; BlockMatrix[1][2] = TempBlockMatrix[2][1]; BlockMatrix[2][1] = TempBlockMatrix[1][2]; BlockMatrix[1][3] = TempBlockMatrix[3][1]; BlockMatrix[3][1] = TempBlockMatrix[1][3]; break; } if(DetectCollision(REFRESH)) { for(int i=0; i<4; i++) for(int j=0; j<4; j++) BlockMatrix[i][j] = TempBlockMatrix[i][j]; return; } MoveBlock(REFRESH); }
// UpdateGame(TetrisGame* game) - main update function for the game, calls all support functions void UpdateGame(TetrisGame* game) { //what is the games state? switch(game->state) { case TITLE_SCREEN: //change the transparency values for the cursor on the level select so that it //'glows' game->transparency += game->transparencyIncrement; if(game->transparency > 1.0f) { game->transparency = 1.0f; game->transparencyIncrement = -game->transparencyIncrement; } else if(game->transparency < 0.0f) { game->transparency = 0.0f; game->transparencyIncrement = -game->transparencyIncrement; } break; case NEED_NEW_BLOCK: //the game needs a new block so set the current block pos to the //start point for all blocks game->currentBlockPos[0] = game->NewBlockStartPoint[0]; game->currentBlockPos[1] = game->NewBlockStartPoint[1]; //choose a new block ChooseNextBlock(game); //change the game state to block falling game->state = BLOCK_FALLING; //set the current rotation to the 0 index game->currentRotation = 0; //update the score and level for the game, it may be enough lines //for a new level UpdateScoreAndLevel(game); //however if there is a collision at this start position we //have reached the conditions for a game over! if(IsThereCollision(game,1000,game->currentRotation)) { game->state = GAME_OVER; } break; case BLOCK_FALLING: //increment fall counter game->fallCounter++; //if the fall counter is high enough, move the block and //reset the counter if(game->fallCounter > game->fallRate) { game->fallCounter = 0; MoveBlock(DOWN,game); } game->colorOffset += game->colorInterval; if(game->colorOffset > 1.0f || game->colorOffset < 0.0f) { game->colorInterval = -game->colorInterval; } break; case CHECK_BOARD: //if there are some lines completed if(CheckBoardForLines(game)) { //if there is a 'tetris' play a special sound if(game->numLinesCompleted == 4) g_engine->p_audio->Play("madeTetris",game->effectsVolume); //put the state into flicering lines game->state = FLICKER_LINES; //add some particle effects! } else { //other wise just choose/select a new block game->state = NEED_NEW_BLOCK; } break; case FLICKER_LINES: //call the code to flicker lines if a line has been completed FlickerLines(game); break; case DESTROY_BLOCKS: //remove the completed lines from the gameboard RemoveLines(game); //update the score, lines completed,update state etc game->numLinesScored += game->numLinesCompleted; game->state = NEED_NEW_BLOCK; g_engine->p_audio->Play("madeLine",game->effectsVolume); break; case GAME_OVER: //it's game over so start the sequence! GameOverSequence(game); break; } }
void CGameFrameWork::AnimateObjects() { if (m_bMove && m_vecBlock.size() < 16) { MoveBlock(); int cnt = 0; for (auto p = m_vecBlock.cbegin(); p != m_vecBlock.cend(); ++p) if (dynamic_cast<CBlock*>(*p)->GetBlockState() == BLOCK_MOVE) ++cnt; if (0 == cnt) { m_bMove = false; /////////////////////////////////////////////////////// if (!m_bReplay) { CreateBlock(); if (m_bRecord) m_vecRecord.push_back(RecordData(elapsedTime.count(), m_eKeyDir, m_NewBlockPos)); } else CreateBlock(m_vecRecord[m_nReplayCnt++].newBlockPos); /////////////////////////////////////////////////////// for (auto p = m_vecBlock.begin(); p != m_vecBlock.end();) { if (dynamic_cast<CBlock*>(*p)->GetBlockInfo().addCheck == 1) { SAFE_DELETE(*p); p = m_vecBlock.erase(p); continue; } else if (dynamic_cast<CBlock*>(*p)->GetBlockInfo().addCheck == 2) { int val = dynamic_cast<CBlock*>(*p)->GetBlockInfo().value; dynamic_cast<CBlock*>(*p)->SetBlockValue(val * 2); dynamic_cast<CBlock*>(*p)->SetBlockBmp(val * 2); dynamic_cast<CBlock*>(*p)->SetBlockAddCheck(0); m_nScore += val * 2; } ++p; } } } for (auto p = m_vecBlock.begin(); p != m_vecBlock.end(); ++p) { int idx = dynamic_cast<CBlock*>(*p)->GetBlockInfo().index; Point2D pt = dynamic_cast<CBoard*>(m_pBoard)->GetTile()[idx]->pos; if (pt.x != dynamic_cast<CBlock*>(*p)->GetBlockInfo().pos.x || pt.y != dynamic_cast<CBlock*>(*p)->GetBlockInfo().pos.y) { dynamic_cast<CBlock*>(*p)->Move(); } else dynamic_cast<CBlock*>(*p)->SetBlockState(BLOCK_STOP); } }
int TetrisPlay(int param) { static int flag = 0; if(!flag){ flag = 1; InitialMatrix(); CreateBlock(&curBlock); // Create next block CreateBlock(&nextBlock); GetCurrentLine(curBlock.y); DisplayScoreLevel(); } //while(1) { int key; TetrisAction action; DebugDump(); // Check valid if(!CheckBlock(&curBlock,TA_None)){ // Game over printf("Game over!\n"); } key = GetKey(); switch(key){ case KEY_LEFT: action = TA_Left; score++; break; case KEY_RIGHT: action = TA_Right; score+=10; break; case KEY_UP: action = TA_Rotate; score+=100; break; case KEY_DOWN: action = TA_Down; score+=1000; break; case KEY_PAUSE: break; default: action = TA_Down; break; } if(CheckBlock(&curBlock,action)){ MoveBlock(&curBlock,action); }else if(action == TA_Down){ ScoreUp(DropBlock(&curBlock)); CopyBlock(&curBlock,&nextBlock); CreateBlock(&nextBlock); GetCurrentLine(curBlock.y); } } return 0; }
int main(){ int gd=DETECT, gm; int Return=0; char Key, ScanCode; int Counter=0; //Divide total delay & take multiple input initgraph(&gd, &gm,"c:\\tc\\bgi"); //initialize graphics mode randomize(); //Randomize block's shapes & color cleardevice(); //clear screen InitPalette(); //for setting color pallete InitMatrix(); //Initialize Matrix GetImages(); //Saving the images StartScreen(); //for start screen cleardevice(); //clear screen AssignShape(GetRandomShape(), GetRandomColor()); //for the falling block NextShape=GetRandomShape(); NextColor=GetRandomColor(); DisplayScreen(); //Show main screen DisplayNextShape(); //show next brick MoveBlock(LEFT); //keep the block on center & check game over while(kbhit()) getch(); //empty the keyboard input while (!Quit && !GameOver) { //Moving the blocks down if(++Counter >= Speed) //For controling the speed { Counter=0; MoveBlock(DOWN); SoundDrop(); } if(kbhit()) //For the arrow keys { Key = getch(); if(Key == 0) { ScanCode = getch(); if(ScanCode == KEY_UP) RotateBlock(); else if(ScanCode == KEY_LEFT) MoveBlock(LEFT); else if(ScanCode == KEY_RIGHT) MoveBlock(RIGHT); else if(ScanCode == KEY_DOWN) { Score++; //increase score PrintScore(); MoveBlock(DOWN); } if(!Return) SoundDrop(); Return = 0; } else if(Key == KEY_ENTER || Key == KEY_SPACE) //Rotating bricks RotateBlock(); else if(Key == 'P' || Key == 'p') //For pause { MessageBox(" Paused"); while(kbhit()) getch(); //clear the keyboard input for(int x=0; x<COLS; x++) for(int y=0; y<ROWS; y++) PreviousScreenLayout[x][y] -= 1; //Clear the present screen layout to refresh the whole screen UpdateScreen(); //refresh screen } else if(Key == KEY_ESC) //For quit { char ret = MessageBox("Are you sure, you want to Quit?", 563, 2); if(ret == 'y' || ret == 'Y' || ret == KEY_ENTER) { Quit = 1; break; } cleardevice(); //Clear the message box while(kbhit()) getch(); //Clear the keyboard input for(int x=0; x<COLS; x++) for(int y=0; y<ROWS; y++) PreviousScreenLayout[x][y] -= 1; // Clear the present screen layout to refresh the whole screen UpdateScreen(); //refresh screen DisplayScreen(); //show the main screen again DisplayNextShape(); //show next brick box } else if(Key == 's' || Key == 'S') //For sound on/off { SoundOn = !SoundOn; } else if(Key=='a' || Key=='A') //For author { MessageBox("Author: Aguntuk Group",450); cleardevice(); //Clear the message box while(kbhit()) getch(); //Clear the keyboard input for(int x=0;x<COLS;x++) for(int y=0;y<ROWS;y++) PreviousScreenLayout[x][y] -=1; //Clear the present screen layout to refresh the whole screen UpdateScreen(); //refresh screen DisplayScreen(); //show the main screen again DisplayNextShape(); //show next brick box } } delay(6); //For moving down the blocks slowly } if(GameOver) //For game over option { DisplayBlock(6,0); //For display the top most brick ShowGameOver(); //For display game over message box } restorecrtmode(); //For closing graphicg mode return 0; }
void DoBuildStairs( vec3_t vMin, vec3_t vMax ){ BuildStairsRS rs; strcpy( rs.mainTexture, GetCurrentTexture() ); // ensure we have something selected if ( g_FuncTable.m_pfnSelectedBrushCount() != 1 ) { DoMessageBox( "Invalid number of brushes selected, chose 1 only", "Error", MB_OK ); return; } // tell Radiant we want to access the selected brushes g_FuncTable.m_pfnAllocateSelectedBrushHandles(); // get handle to size definition brush brush_t *brush = (brush_t*)g_FuncTable.m_pfnGetSelectedBrushHandle( 0 ); // cant release until we delete the brush, if we do... // ask user for type, size, etc.... if ( DoBuildStairsBox( &rs ) == IDOK ) { // calc brush size vec3_t size; VectorSubtract( vMax, vMin, size ); if ( ( (int)size[2] % rs.stairHeight ) != 0 ) { // stairs must fit evenly into brush DoMessageBox( "Invalid stair height\nHeight of block must be divisable by stair height", "Error", MB_OK ); } else { // Remove Size Brush g_FuncTable.m_pfnDeleteBrushHandle( brush ); // Get Step Count int numSteps = (int)size[2] / rs.stairHeight; if ( rs.style == STYLE_CORNER ) { BuildCornerStairs( vMin, vMax, numSteps, rs.mainTexture, rs.riserTexture ); } else { // Get Step Dimensions float stairHeight = (float)rs.stairHeight; float stairWidth; if ( ( rs.direction == MOVE_EAST ) || ( rs.direction == MOVE_WEST ) ) { stairWidth = ( size[0] ) / numSteps; } else{ stairWidth = ( size[1] ) / numSteps; } // Build Base For Stair (bob's style) if ( rs.style == STYLE_BOB ) { Build_Wedge( rs.direction, vMin, vMax, TRUE ); } // Set First Step Starting Position vMax[2] = vMin[2] + stairHeight; SetInitialStairPos( rs.direction, vMin, vMax, stairWidth ); // Build The Steps for ( int i = 0; i < numSteps; i++ ) { if ( rs.style == STYLE_BOB ) { Build_StairStep_Wedge( rs.direction, vMin, vMax, rs.mainTexture, rs.riserTexture, rs.bUseDetail ); } else if ( rs.style == STYLE_ORIGINAL ) { Build_StairStep( vMin, vMax, rs.mainTexture, rs.riserTexture, rs.direction ); } // get step into next position MoveBlock( rs.direction, vMin, vMax, stairWidth ); vMax[2] += stairHeight; if ( rs.style == STYLE_BOB ) { vMin[2] += stairHeight; // wedge bottom must be raised } } } } } g_FuncTable.m_pfnReleaseSelectedBrushHandles(); }