int main(int argc, char *argv[]){ signal(SIGINT, SIG_IGN); signal(SIGTSTP, SIG_IGN); pid_t pid1, pid2, pid3, pid4; int winScore, fd; printf("Enter winning score\n"); scanf("%d", &winScore); fd= open("asing6.txt", O_RDWR|O_TRUNC|O_CREAT); printf("This is a 4-player game with a referee\n"); if((pid1=fork()) == 0) child("TOTO",fd); if((pid2=fork()) == 0) child("TITI", fd); if((pid3=fork()) == 0) child("TATA", fd); sleep(1); while(1){ printf("\nReferee: TOTO plays\n\n"); kill(pid1, 16); signal(16, action); pause(); checkScore(fd,winScore); printf("\n\nReferee: TITI plays\n\n"); kill(pid2, 16); signal(16, action); pause(); checkScore(fd,winScore); printf("\nReferee: TATA plays\n\n"); kill(pid3, 16); signal(16, action); pause(); checkScore(fd,winScore); } }
//Begin Main int main() { srand(time(0)); int numWordsInDictionary, i, flag; //flag, when dictionary > 10,000 int choice, score, isPlaying; char word[8], letters[8], bestWord[8]; char ** dictionary = getDictionaryWords(dictionary, &numWordsInDictionary, &flag); //initializing values strcpy(bestWord, ""); //clearing garbage score = 0; isPlaying = 1; if(flag != 0) { printf("Welcome to the Scrabble Practice Program!\n\n"); generateHand(letters); printf("Here are your letters: %s", letters); while(isPlaying == 1) { choice = printMenu(choice); if(choice == 1) { getWord(word); if( checkValid(word, dictionary, numWordsInDictionary) == 1 ) checkScore(word, bestWord, &score); else printf("That word is not found within our current dictionary!\n"); } else break; } printf("Your best word was %s worth %d points.\n", bestWord, score); for(i = 0; i < numWordsInDictionary; i++) free(dictionary[i]); free(dictionary); } else { printf("Error! The dictionary cannot be more than 10,000 words!\n"); free(dictionary); } return 0; }
void Game::timerEvent(QTimerEvent*) { // check to see if any addition is necessary checkAddition(); // advance the scene myScene.advance(); // check to see if the score should be increased checkScore(); // check to see if he wants to jump (and can) checkJump(); // check to see if he is stuck in a wall checkWall(); // check to see if he has hit an obstacle checkLose(); // check to see if removal of items is necessary checkDeath(); }
/***************************************************************************** * * Description: * Advance the game, check if game is over * ****************************************************************************/ static void advanceGame(void) { insertFigure(currFigure, currXpos, currYpos); drawGame(); deleteFigure(currFigure, currXpos, currYpos); /******************************************************* * Check if time to update figure position *******************************************************/ updateDelayTime(); if ((ms - lastUpdate) > delayTimeMs) { lastUpdate = ms; if (isValid(currXpos, currYpos+1, currFigure)) currYpos++; //figure has hit bottom //insert new, random figure on the game board else { insertFigure(currFigure, currXpos, currYpos); currYpos = 0; currXpos = 3; currFigure = rand() % NUM_OF_FIGURE; //check if game is over if (gameOver()) gameStatus = GAME_OVER; } //check score, i.e., if any rows are full checkScore(); } }
/** * @brief search 3x4 -> 3x3 * @param[in] ac_InitState state on start * @param[in] ac_MidState state on first search end * @param[in] ac_MoveLog space moved log */ void search3x4(char* ac_InitState, char* ac_MidState, char* ac_MoveLog) { char ac_CurrState[FIELD_SIZE], ac_CurrMoveLog[SUM_MOVE_MAX], c_CurrSpcPos = searchSpace(ac_InitState, FIELD_SIZE); AVAIL_STATE ac_AvailState[AVAIL_STATE_NUM]; const UINT ui_GoalScore = ANSWER_PLACE; UINT ui_MaxScore = checkScore(ac_InitState); memcpy(ac_CurrState, ac_InitState, FIELD_SIZE); while(ui_MaxScore != ui_GoalScore) { AVAIL_STATE *p_NowState, *p_NextState; UINT ui_SpcPos, ui_AdjaPos; UINT ui_Score = 0, ui_Anum = 0, uii; char ac_Move[2] = {'\0', '\0'}; ui_Score = 0; ui_Anum = 0; memset(ac_AvailState, 0, sizeof(ac_AvailState)); memcpy(ac_AvailState[ui_Anum].ac_Array, ac_CurrState, FIELD_SIZE); ac_AvailState[ui_Anum].c_SpcPos = c_CurrSpcPos; ac_AvailState[ui_Anum].c_PrevPos = 0x7F; for(ui_Anum = 0; ui_Anum < (AVAIL_STATE_NUM - 3); ui_Anum += uii) { ui_SpcPos = ac_AvailState[ui_Anum].c_SpcPos; for(uii = 0; (ui_AdjaPos = (UINT)ac_Adjacent[ui_SpcPos][uii]) != -1; uii++) { if((ac_AvailState[ui_Anum].ac_Array[ui_AdjaPos] == ac_AvailState[ui_Anum].c_PrevPos) || (ac_AvailState[ui_Anum].ac_Array[ui_AdjaPos] == '=')) { continue; } p_NowState = &ac_AvailState[ui_Anum]; p_NextState = &ac_AvailState[ui_Anum + 1]; /* 状態をコピー */ memcpy(p_NextState->ac_Array, p_NowState->ac_Array, FIELD_SIZE); /* 移動 */ p_NextState->ac_Array[ui_SpcPos] = p_NextState->ac_Array[ui_AdjaPos]; p_NextState->ac_Array[ui_AdjaPos] = 0; p_NextState->c_SpcPos = (char)ui_AdjaPos; p_NextState->c_PrevPos = p_NowState->c_SpcPos; ac_Move[0] = getMoveDirection(p_NowState->c_SpcPos, p_NextState->c_SpcPos); strcat(p_NextState->ac_mMoveLog, ac_Move); ui_Score = checkScore(p_NextState->ac_Array); if(ui_Score > ui_MaxScore) { ui_MaxScore = ui_Score; memcpy(ac_CurrState, p_NextState->ac_Array, FIELD_SIZE); c_CurrSpcPos = p_NextState->c_SpcPos; strcat(ac_CurrMoveLog, p_NextState->ac_mMoveLog); ui_Anum = AVAIL_STATE_NUM; /* break */ break; } } } } printf("3x4 clear !\n"); printState((char(*)[FIELD_WIDTH])ac_CurrState); convertState(ac_MidState, ac_CurrState); strcat(ac_MoveLog, ac_CurrMoveLog); }