void write(Field* f, Chunk* chn) { int dy = 2; for (int y = 3; y < Field::HEIGHT; y++) add(y + dy, " " + f->line(y)); writeNext(chn, dy); writeScore(f->score, dy); }
void ScoreWindow::incDefeats() { _previousWon = false; _defeats++; _totalScore -= defeatScore + _continuousDefeats * continuousScore; _continuousWins = 0; _continuousDefeats++; writeScore(); }
void ScoreWindow::incWins() { if (_previousWon == false) _previousWon = true; _wins++; _totalScore += winScore + _continuousWins * continuousScore; _continuousWins++; _continuousDefeats = 0; writeScore(); }
void ScoreManager::resetScore(void) { if ( gameScore > highScore ) { highScore = gameScore; writeScore(); postHighScore(); } // floorHitCount = 0; gameScore = 0; lives = 5; postScore(); postLives(); }
void addScore() { int i, dlg; TScore s; SYSTEMTIME t; if(playtime<=0 || playtime>65535 || symetric || level || (size!=6 && size!=9 && size!=12)) return; readScore(); //fill in a score record GetLocalTime(&t); s.date.wDay=(BYTE)t.wDay; s.date.wMonth=(BYTE)t.wMonth; s.date.wYear=t.wYear; s.date.wMinute=(BYTE)t.wMinute; s.date.wHour=(BYTE)t.wHour; s.playtime=(WORD)playtime; //get table TscoreTab *a= getScoreTab((BYTE)gameType, (BYTE)size, (BYTE)diag, (BYTE)killer, (BYTE)greater, (BYTE)consecutive, (BYTE)oddeven); TScore *scoreTable= a->score; //InsertSort for(i=0; i<Dscore; i++){ if(s.playtime < scoreTable[i].playtime || !scoreTable[i].playtime) break; } if(i<Dscore){ //ask for player name dlg= (int)DialogBoxParam(inst, MAKEINTRESOURCE(IDD_NAME), hWin, (DLGPROC)NameProc, 0); convertT2W(playerName, w); wcscpy(s.name, w); if(dlg!=IDCANCEL){ //add new record to the score table a->lastScore=i; for(int j=Dscore-1; j>i; j--) scoreTable[j]=scoreTable[j-1]; scoreTable[i]=s; //save to disk writeScore(); //show table DialogBoxParam(inst, MAKEINTRESOURCE(IDD_HISCORE), hWin, (DLGPROC)ScoreProc, 0); } else{ //delete empty table if(!scoreTable[0].playtime){ assert(a==::score); ::score=a->next; delete a; } } } }
void ScoreWindow::readScore() { FILE* fp = fopen(saveFile.c_str(), "r"); const int lineLength = 30; char line[lineLength]; if (fp == NULL) { if (errno == ENOENT) fprintf(stderr, "%s does not exist. Creating.\n", saveFile.c_str()); writeScore(); return; } if (fgets(line, lineLength, fp) == NULL) goto ERROR; if (sscanf(line, "Wins = %d", &_wins) != 1) goto ERROR; if (fgets(line, lineLength, fp) == NULL) goto ERROR; if (sscanf(line, "Defeats = %d", &_defeats) != 1) goto ERROR; if (fgets(line, lineLength, fp) == NULL) goto ERROR; if (sscanf(line, "Continuous Wins = %d", &_continuousWins) != 1) goto ERROR; if (fgets(line, lineLength, fp) == NULL) goto ERROR; if (sscanf(line, "Continuous Defeats = %d", &_continuousDefeats) != 1) goto ERROR; int tmp; if (fgets(line, lineLength, fp) == NULL) goto ERROR; if (sscanf(line, "Previous Won = %d", &tmp) != 1) goto ERROR; _previousWon = (tmp == 0 ? false : true); if (fgets(line, lineLength, fp) == NULL) goto ERROR; if (sscanf(line, "Undos = %d", &_undos) != 1) goto ERROR; if (fgets(line, lineLength, fp) == NULL) goto ERROR; if (sscanf(line, "Total Score = %d", &_totalScore) != 1) goto ERROR; fclose(fp); return; ERROR: fprintf(stderr, "Error encountered while reading %s\n", saveFile.c_str()); fclose(fp); }
ScoreBoard::ScoreBoard(Renderer * r, Game * g, sf::Vector2f pos){ visual = r; game = g; position.x = pos.x; position.y = pos.y; font.loadFromFile("resources/fonts/kenvector_future.ttf"); background.setTexture( *visual->getTexture("resources/textures/backgroundScoreboard.png") ); float newWidth = blocksizeToScale( visual->getSize().x, 1366 ); float newHeight = blocksizeToScale( visual->getSize().y, 1040); background.setScale( newWidth, newHeight ); loadFile("scores.txt"); addScore("lol", 11); addScore("Kees", 1000); addScore("Jaap", 10); createText(); writeScore("scores_nieuw.txt"); }
int TickFct_Score(int state){ static unsigned char scoreTotal = 0; switch(state){ case SE_SMStart: state = SE_Wait; break; case SE_Wait: state = SE_Wait; writeScore(scoreTotal); if(scoreFlag&&scoreTotal < 5){ scoreFlag = 0; scoreTotal++; } if(scoreTotal == 5){ winFlag = 1; resetFlag = 1; } if(scoreReset){ scoreTotal = 0; scoreReset = 0; } break; default: state = SE_SMStart; break; } return state; }
void ScoreWindow::decUndos() { _undos--; _totalScore += undoScore; writeScore(); }
void ScoreWindow::incUndos() { _undos++; _totalScore -= undoScore; writeScore(); }
void Window::save() { scr = quadro->saveSocore; boxLayout = new QHBoxLayout(); if(boxLayout == NULL){ qDebug() << "boxLayout Falhou!"; chek = true; }else{ qDebug() << "boxLayout Sucesso!"; } labelNome = new QLabel("Nome: ",this); if(labelNome == NULL){ qDebug() << "labelNome Falhou!"; chek = true; }else{ qDebug() << "labelNome Sucesso!"; } botaoSave = new QPushButton("Save",this); if(botaoSave == NULL){ qDebug() << "botaoSave Falhou!"; chek = true; }else{ qDebug() << "botaoSave Sucesso!"; } edit = new QLineEdit(this); if(edit == NULL){ qDebug() << "edit Falhou!"; chek = true; }else{ qDebug() << "edit Sucesso!"; } newWindow = new QWidget; if(newWindow == NULL){ qDebug() << "newWindow Falhou!"; chek = true; }else{ qDebug() << "newWindow Sucesso!"; } if(chek == true) { falhaCritica(); }else{ boxLayout->addWidget(labelNome); boxLayout->addWidget(edit); boxLayout->addWidget(botaoSave); newWindow -> setLayout(boxLayout); newWindow -> show(); if(readScore() == false){ connect(botaoSave,SIGNAL(clicked()),this,SLOT(writeScore())); }else{ connect(botaoSave,SIGNAL(clicked()),this,SLOT(readWriteScore())); } } }
//------------------------------------------------------------------ LRESULT CALLBACK WndMainProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int i, notif; Tsquare *t; switch(message){ case WM_PAINT: { static PAINTSTRUCT ps; BeginPaint(hWnd, &ps); paint(ps.hdc, &ps.rcPaint); EndPaint(hWnd, &ps); } break; case WM_LBUTTONDOWN: lbutton(lParam); break; case WM_RBUTTONDOWN: rbutton(lParam); break; case WM_LBUTTONUP: if(inserting){ ReleaseCapture(); inserting=false; insertGroup(); resetSolution(); } break; case WM_MOUSEMOVE: if(inserting){ t= hitTest(lParam); if(t && t!=insSquares[insLen-1] && insLen<Nsymbol){ insSquares[insLen++]=t; } } #ifdef _DEBUGM mousemove(lParam); #endif break; case WM_TIMER: if(!IsIconic(hWin)){ playtime++; statusTime(); checkShowErr(false); } break; case WM_KEYDOWN: key(wParam); break; case WM_GETMINMAXINFO: { LPMINMAXINFO lpmm = (LPMINMAXINFO)lParam; lpmm->ptMinTrackSize.x = 250; lpmm->ptMinTrackSize.y = 200+toolH; break; } case WM_SIZE: width=LOWORD(lParam); height=HIWORD(lParam); SendMessage(toolbar, TB_AUTOSIZE, 0, 0); SendMessage(statusbar, WM_SIZE, 0, 0); onMoved(); invalidate(); break; case WM_MOVE: onMoved(); break; case WM_CLOSE: SendMessage(hWin, WM_COMMAND, ID_EXIT, 0); break; case WM_QUERYENDSESSION: writeini(); return TRUE; case WM_DESTROY: PostQuitMessage(0); break; case WM_COMMAND: notif=HIWORD(wParam); wParam=LOWORD(wParam); if(setLang(wParam)) break; if(wParam>=ID_SYMBOL && wParam<unsigned(ID_SYMBOL+size)){ select(wParam-ID_SYMBOL); break; } if(wParam>=ID_SIZE+4 && wParam<=ID_SIZE+Msize){ if(askNew()) break; size=wParam-ID_SIZE; newGameFormat(); numButtons(); break; } if(wParam>=ID_MULTI && wParam<ID_MULTI+sizeA(gameTypeA)-1){ if(askNew()) break; gameType=wParam-ID_MULTI; newGameFormat(); break; } switch(wParam){ case ID_CLEAR: noScore=true; init(false); invalidate(); break; case ID_CLEAR_ALL: noScore=true; initSquare(false); invalidate(); break; case ID_EDITOR: if(!editor){ if((undoPos==0 || done==Nsquare) && isGenerated()){ initSquare(false); } editor=true; playtime=0; noScore=true; editorChanged(); } break; case ID_EDITOR_END: if(editor){ endEditor(); editor=false; editorChanged(); } break; case ID_SOLVE: case ID_SOLVE1: if(testTotal()) break; noScore=true; if(done<Nsquare){ waitOn(); #ifdef _DEBUG DWORD time=getTickCount(); #endif Nsolution=0; curSolution=-1; //find all solutions (up to Msolution) undoAllPos=undoPos; if(wParam==ID_SOLVE1) resolve1(); else resolve(); freeGroups(); #ifdef _DEBUG status(4, _T("%d ms"), getTickCount()-time); #endif waitOff(); } if(Nsolution>0){ i=curSolution; curSolution++; if(curSolution>=Nsolution) curSolution=0; if(Nsolution>1){ if(i<0){ status(4, _T("%d %s"), Nsolution, lng(662, "solutions")); } else{ status(4, _T("%d/%d"), curSolution+1, Nsolution); } } rdSolution(); } else{ //easy solution (without recurse) or not solvable curSolution=0; status(4, _T("")); } checkErr(); invalidate(); break; case ID_CHEAT: noScore=true; if(errTime<0){ waitOn(); hint(); waitOff(); } checkShowErr(true); break; case ID_UNDO: undo(); checkErr(); break; case ID_REDO: redo(); checkErr(); break; case ID_UNDO_SYMBOL: undoSymbol(); checkErr(); break; case ID_REDO_SYMBOL: redoSymbol(); checkErr(); break; case ID_UNDO_ALL: undoAll(); checkErr(); break; case ID_REDO_ALL: while(redo()); checkErr(); break; case ID_DEL: select(-1); break; case ID_INS: select(-2); break; case ID_SIGN: select(-3); break; case ID_CONS: select(-4); break; case ID_EVEN: select(-5); break; case ID_EXIT: writeini(); DestroyWindow(hWin); break; case ID_DIAGONAL: if(askNew()) break; diag=!diag; newGameFormat(); break; case ID_SYMETRIC: if(askNew()) break; symetric=!symetric; newGameFormat(); break; case ID_LEVEL: if(DialogBox(inst, MAKEINTRESOURCE(IDD_LEVEL), hWnd, (DLGPROC)LevelProc)){ if(!editor) newGame(); } break; case ID_SHOWERR: DialogBox(inst, MAKEINTRESOURCE(IDD_ERRTIME), hWnd, (DLGPROC)ShowErrProc); break; case ID_KILLER: if(askNew()) break; killer=!killer; newGameFormat(); numButtons(); break; case ID_GREATER: if(askNew()) break; greater=!greater; newGameFormat(); break; case ID_CONSECUTIVE: if(askNew()) break; consecutive=!consecutive; newGameFormat(); if(selectedNum==-4 && !consecutive) select(-1); break; case ID_ODDEVEN: if(askNew()) break; oddeven=!oddeven; newGameFormat(); if(selectedNum==-5 && !oddeven) select(-1); break; case ID_DIGITS: case ID_LETTERS: case ID_COLORS: symbol0=wParam-350; checkMenus(); invalidate(); numButtons(); break; case ID_NEWGAME: if(editor) SendMessage(hWnd, WM_COMMAND, ID_EDITOR_END, 0); else newGame(); break; case ID_DELINI: delreg=true; break; case ID_DELHISCORE: if(MessageBox(hWnd, lng(799, "Do you really want to delete all hiscores ?"), title, MB_YESNO|MB_ICONQUESTION|MB_DEFBUTTON2) == IDYES){ for(TscoreTab *tab=score; tab;){ TscoreTab *t1= tab->next; delete tab; tab=t1; } score=0; writeScore(); } break; case ID_BEST_SCORES: DialogBox(inst, MAKEINTRESOURCE(IDD_HISCORE), hWnd, (DLGPROC)ScoreProc); break; case ID_COLORDLG: DialogBox(inst, MAKEINTRESOURCE(IDD_COLORS), hWin, (DLGPROC)ColorProc); break; case ID_ABOUT: DialogBox(inst, MAKEINTRESOURCE(IDD_ABOUT), hWnd, (DLGPROC)AboutProc); break; case ID_HELP_README: { TCHAR *buf=(TCHAR*)_alloca(2*MAX_PATH); getExeDir(buf, lng(13, "readme.txt")); if(ShellExecute(0, _T("open"), buf, 0, 0, SW_SHOWNORMAL)==(HINSTANCE)ERROR_FILE_NOT_FOUND){ msglng(730, "Cannot open %s", buf); } } break; case ID_WRBMP: if(saveFileDlg(&bmpOfn, hWnd, 0)){ wrBmp(bmpFn, bmpOfn.nFilterIndex); } break; case ID_SAVE: if(saveFileDlg(&gameOfn, hWnd, OFN_OVERWRITEPROMPT)){ save(gameFn); } break; case ID_OPEN: if(openFileDlg(&gameOfn, hWnd, OFN_FILEMUSTEXIST|OFN_HIDEREADONLY)){ open(gameFn); checkErr(); } break; case ID_CLEAR_GRP: resetSolution(); for(i=0; i<Ngroup; i++){ delGroup(&group[i]); } invalidate(); break; case ID_CLEAR_SGN: case ID_CLEAR_CONS: resetSolution(); for(i=0; i<Nboard; i++){ if(wParam==ID_CLEAR_SGN){ putSign(0, &board[i], 0); putSign(0, &board[i], 1); } if(wParam==ID_CLEAR_CONS){ putCons(false, &board[i], 0); putCons(false, &board[i], 1); } } invalidate(); break; case ID_MARKS: noScore=true; showMarks(); break; case ID_DELMARKS: delAllMarks(); break; case ID_PDF: if(askNew()) break; DialogBox(inst, MAKEINTRESOURCE(IDD_PDF), hWnd, (DLGPROC)PdfProc); numButtons(); break; } break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
void VarSelectorFind::getVariables(const Data& iData, int iInit, float iOffset, const Location& iLocation, std::vector<std::string>& iVariables) const { Input* inputF = iData.getInput(); Input* inputO = iData.getObsInput(); std::vector<std::string> variables; inputF->getVariables(variables); int locationId = iLocation.getId(); // Members std::vector<Member> members; inputF->getMembers(members); std::vector<std::string> varList; std::vector<std::string> varRemaining = variables; int numDays = (int) Global::getTimeDiff(mEndDate, 0, 0, mStartDate, 0, 0)/24; std::vector<float> obsTarget; obsTarget.resize(numDays); // Load the target observations for(int d = 0; d < numDays; d++) { int currDate = Global::getDate(mStartDate, 24*d); obsTarget[d] = inputO->getValue(currDate, iInit, iOffset, iLocation.getId(), 0, mVariable); } std::map<std::string, std::vector<float> > forecasts; std::vector<std::pair<std::string, float> > corrs; SelectorAnalog selector(makeOptionsObs(mVariable), iData); Parameters par; selector.getDefaultParameters(par); for(int v = 0; v < (int) variables.size(); v++) { std::string currVar = variables[v]; // Load the observations /* std::vector<float> obs; obs.resize(numDays); for(int d = 0; d < numDays; d++) { int currDate = Global::getDate(mStartDate, 24*d); obs[d] = inputO->getValue(currDate, iInit, iOffset, iLocation.getId(), 0, variables[v]); } */ double startTime = Global::clock(); // Load forecasts forecasts[currVar].resize(numDays-mTrainingDays); for(int d = mTrainingDays; d < numDays; d++) { int currDate = Global::getDate(mStartDate, 24*d); std::vector<float> values; inputF->getValues(currDate, iInit, iOffset, iLocation.getId(), currVar, values); forecasts[currVar][d-mTrainingDays] = Global::mean(values); } // For each day, find the analog that would have been the best std::vector<float> forecastsAtBest; forecastsAtBest.resize(numDays-mTrainingDays); for(int d = mTrainingDays; d < numDays; d++) { int currDate = Global::getDate(mStartDate, 24*d); //Global::logger->setDateInfo(currDate, d-mTrainingDays+1, numDays-mTrainingDays); std::vector<Field> slices; selector.select(currDate, iInit, iOffset, iLocation, mVariable, par, slices); // Get the forecasts at these times std::vector<float> temp; for(int i = 0; i < (int) slices.size(); i++) { // Since the observation dataset is used, past dates may be outside the range // TODO: This would be a problem since the selector only picks the n best analogs // TODO: Hard coded 10 if(temp.size() < 10) { if(slices[i].getDate() >= mStartDate && slices[i].getDate() <= mEndDate) { float value = inputF->getValue(slices[i].getDate(), slices[i].getInit(), slices[i].getOffset(), iLocation.getId(), slices[i].getMember().getId(), variables[v]); temp.push_back(value); //if(variables[v] == "CloudCover") // std::cout << "DATES: " << slices[i].getDate() << " " << value << std::endl; } } } float fcst = Global::mean(temp); // Forecasts at the best obs forecastsAtBest[d-mTrainingDays] = fcst; } // Compute the score float corr = Global::corr(forecasts[currVar], forecastsAtBest); if(Global::isValid(corr)) { float score = -corr; std::pair<std::string, float> p(variables[v], score); corrs.push_back(p); writeScore(variables[v], corr); } double endTime = Global::clock(); //std::cout << "Time = " << endTime - startTime << std::endl; } // Sort std::sort(corrs.begin(), corrs.end(), Global::sort_pair_second<std::string, float>()); assert(iVariables.size() == 0); // Check how many to add std::vector<std::string> currVars; std::vector<int> currVarsI; std::vector<std::string> bestVars; float bestScore = Global::INF; for(int v = 0; v < mMaxVars; v++) { if(v < corrs.size()) { std::string currVar = corrs[v].first; // Check that current variable isn't correlated to any added variables float varCorr = 0; for(int vv = 0; vv < currVars.size(); vv++) { varCorr = Global::corr(forecasts[currVar], forecasts[currVars[vv]]); std::cout << " varCorr[" << currVar << "," << currVars[vv] << "] = " << varCorr << std::endl; } if(!Global::isValid(varCorr) || fabs(varCorr) < mMaxVarCrossCorrelation) { currVars.push_back(currVar); currVarsI.push_back(v); float score = VarSelector::run(iData, iInit, iOffset, iLocation, currVars, *mDetMetric); std::cout << "Scores:"; for(int vv = 0; vv < currVars.size(); vv++) { std::cout << " " << currVars[vv]; } std::cout << " " << score << std::endl; if(score < bestScore) { bestScore = score; bestVars = currVars; } } } } iVariables = bestVars; }
int main(void) { int addScore, position, pauseSel; // Initializations PLL_Init(); // Clock set at 80 MHz LCD_Init(); Board_Init(); Input_Init(); DAC_Init(); Random_Init(NVIC_ST_CURRENT_R); Timer2_Init(80000000); // time interrupt Timer1_Init(2000); // sound interrupt EnableInterrupts(); generateRandomTile(); drawAllTiles(); writeScore(0); writeHighscore(0); writeTime(0); displayHighestTile(); while(1) { // draw arrow if ready if (arrowReady == 1) { // acknowledge flag arrowReady = 0; // draw arrow drawArrow(); } // write time if ready if (timeReady == 1) { // acknowledge flag timeReady = 0; // write time writeTime(elapsedTime); } // Play mode and button1 is pushed if(Button1 && !pauseMode && !gameOver) { // Play sound playSound = 1; // shift and merge tiles towards arrow position = getSliderPosition(); if (position == 1) { shiftLeft(); addScore = mergeLeft(); shiftLeft(); } else if (position == 2) { shiftUp(); addScore = mergeUp(); shiftUp(); } else if (position == 3) { shiftRight(); addScore = mergeRight(); shiftRight(); } else { shiftDown(); addScore = mergeDown(); shiftDown(); } eraseBoard(); drawAllTiles(); // update score score += addScore; addScore = 0; writeScore(score); displayHighestTile(); // delay before adding new tile delay(200); // create new tile if (countEmptyTiles() != 0) { generateRandomTile(); } drawAllTiles(); // update highest tile image displayHighestTile(); // check if game over if (checkGameOver() == 1) { gameOver = 1; } // unset flag Button1 = 0; } // button 2 is pause else if (Button2 && !gameOver && !pauseMode) { pauseMode = 1; pauseSel = 0; // disable arrow and timer NVIC_ST_CTRL_R = 0; TIMER2_CTL_R = 0x00000000; LCD_DrawFilledRect(prevX,prevY,20,20,BLACK); // draw pause mode screen drawPauseMode(); // acknowledge button Button2 = 0; // wait until button is pushed while (pauseMode) { // Button 1 selects current pause selection button if (Button1) { // acknowledge button Button1 = 0; Button2 = 0; pauseMode = 0; // if pause selection = "continue" (pauseSel = 0), continue with game if (pauseSel == 0) { // redraw screen eraseBoard(); drawAllTiles(); // enable gameplay NVIC_ST_CTRL_R = 0x07; TIMER2_CTL_R = 0x00000001; } // if pause selection = "restart" (pauseSel = 0), end game else if (pauseSel == 1) { if (score > highscore) { writeHighscore(score); } score = 0; eraseScore(); writeScore(0); clearBoard(); eraseBoard(); pauseMode = 0; generateRandomTile(); drawAllTiles(); elapsedTime = 0; eraseTime(); writeTime(0); displayHighestTile(); NVIC_ST_CTRL_R = 0x07; TIMER2_CTL_R = 0x00000001; } } // Button 2 changes pause selection else if (Button2) { Button2 = 0; if (pauseSel == 0) { pauseSel = 1; LCD_DrawRect(144,112,58,16,BLACK); LCD_DrawRect(222,112,51,16,WHITE); } else if (pauseSel == 1) { pauseSel = 0; LCD_DrawRect(222,112,51,16,BLACK); LCD_DrawRect(144,112,58,16,WHITE); } } } } // game over if (gameOver == 1) { NVIC_ST_CTRL_R = 0; TIMER2_CTL_R = 0x00000000; LCD_DrawFilledRect(156,38,100,20,BLACK); LCD_SetTextColor(255,255,240); LCD_Goto(30,5); printf("GAME OVER"); while (Button1 == 0 && Button2 == 0) {} Button1 = 0; Button2 = 0; LCD_DrawFilledRect(prevX,prevY,20,20,BLACK); drawGameOver(score, elapsedTime); if (score > highscore) { writeHighscore(score); gameOverHighscore(score); } // wait til button is pushed while (Button1 == 0 && Button2 == 0) {} // acknowledge buttons Button1 = 0; Button2 = 0; // start new game score = 0; eraseScore(); writeScore(0); clearBoard(); eraseBoard(); pauseMode = 0; generateRandomTile(); drawAllTiles(); elapsedTime = 0; eraseTime(); writeTime(0); displayHighestTile(); NVIC_ST_CTRL_R = 0x07; TIMER2_CTL_R = 0x00000001; // finish game over mode gameOver = 0; } } }