void Questioner::countdownOver() { //LOG("Questioner cube is %d\n",(int) myCube ); myGameDrawer->drawQuestionerBackground(myCube); currQuestion = Question(myGameDrawer, myCube, yCurrQuestion); prevQuestion = Question(myCube); }
void unitTest() { TreeType tree = InitTree(); printf("After initlizing tree:\n"); PrintTree(tree); PositionType question = 0; PositionType answer = 5; printf("IsLeaf test 1: %s\n", IsLeaf(tree, question) ? "error" : "pass"); printf("IsLeaf test 2: %s\n", IsLeaf(tree, answer) ? "pass" : "error"); printf("Top test: %s\n", Top(tree) == 0 ? "pass" : "error"); printf("Question test 1: %s\n", strcmp(Question(tree, question), "Is it furry?") == 0 ? "pass" : "error"); printf("Question test 2: %s\n", strcmp(Question(tree, answer), "Is it a lizard?") == 0 ? "pass" : "error"); printf("%s\n", Question(tree, answer)); ReplaceNode(tree, 7, "a kitten", "Is it an adult?"); PrintTree(tree); }
void addDetailedVerbQuestions(Quiz &quiz, const SweDictionary &sweDict, const quint16 &count) { QString questionText; QList<Verb> &verbs = sweDict.getRandomVerbs(count); for (int i = 0; i < verbs.size(); i++) { questionText.append("What are the forms of \""); questionText.append(verbs.at(i).getEnglishTranslation()); questionText.append("\" in swedish?"); QList<QString> answer; answer.append(verbs.at(i).getImperativForm()); answer.append(verbs.at(i).getInfinitivForm()); answer.append(verbs.at(i).getPresensForm()); answer.append(verbs.at(i).getPreteritumForm()); answer.append(verbs.at(i).getSupinumForm()); const Question &q = Question(questionText, answer, Question::VERB); quiz.addQuestion(q); questionText.clear(); } delete &verbs; }
/* * Play the "animal" game, in which the program attempts to guess an animal * that the user is thinking of by asking yes or no questions. Eventually, * the program either will guess the user's animal or run out of questions * to ask. In the latter case, the program will ask the user to provide a * yes-or-no question that would distinguish between the user's animal and * the program's best guess. * The data structure of questions and guesses is essentially a binary tree, * with each internal node having a "yes" branch and a "no" branch. Leaves * of the tree represent animals to be guessed by the program. If the program * fails to guess the user's animal, it replaces one of the leaves of the tree * by a node containing the new question, whose children are the program's * best guess and the animal provided by the user. * The structure of the program is simple. It initializes the question/guess * data structure, then plays games as long as the user is interested. In each * game, the program starts at the top of the tree (the root) and progresses * toward the bottom (the leaves) depending on the user's responses. Once it * reaches a leaf, it either has won or lost, and handles the situation as * described above. */ int main () { TreeType tree; PositionType pos; char *newQuestion, *newAnswer; tree = InitTree (); // unitTest(); printf("%s", "Think of an animal. I will try to guess what it is.\n" "Please answer my questions with yes or no.\n"); while (TRUE) { pos = Top (tree); while (!IsLeaf (tree, pos)) { pos = Answer (Question (tree, pos))? YesNode (tree, pos): NoNode (tree, pos); } if (Answer (Guess (tree, pos))) { printf ("I got it right!\n"); } else { GetNewInfo (tree, pos, &newAnswer, &newQuestion); ReplaceNode (tree, pos, newAnswer, newQuestion); } if (!Answer ("Want to play again? ")) { exit (0); } } return 0; }
void addDetailedNounQuestions(Quiz &quiz, const SweDictionary &sweDict, const quint16 &count) { QString questionText; QList<Noun> &nouns = sweDict.getRandomNouns(count); for (int i = 0; i < nouns.size(); i++) { questionText.append("What are the forms of \""); questionText.append(nouns.at(i).getEnglishTranslation()); questionText.append("\" in swedish?"); //const QString &singForm = nouns.at(i).getBestSingForm(); QList<QString> answer; answer.append(nouns.at(i).getEnEtt()); answer.append(nouns.at(i).getBestSingForm()); answer.append(nouns.at(i).getObestSingForm()); answer.append(nouns.at(i).getBestPlurForm()); answer.append(nouns.at(i).getObestPlurForm()); const Question &q = Question(questionText, answer, Question::NOUN); quiz.addQuestion(q); questionText.clear(); } delete &nouns; }
/* * Play the "animal" game, in which the program attempts to guess an animal * that the user is thinking of by asking yes or no questions. Eventually, * the program either will guess the user's animal or run out of questions * to ask. In the latter case, the program will ask the user to provide a * yes-or-no question that would distinguish between the user's animal and * the program's best guess. * The data structure of questions and guesses is essentially a binary tree, * with each internal node having a "yes" branch and a "no" branch. Leaves * of the tree represent animals to be guessed by the program. If the program * fails to guess the user's animal, it replaces one of the leaves of the tree * by a node containing the new question, whose children are the program's * best guess and the animal provided by the user. * The structure of the program is simple. It initializes the question/guess * data structure, then plays games as long as the user is interested. In each * game, the program starts at the top of the tree (the root) and progresses * toward the bottom (the leaves) depending on the user's responses. Once it * reaches a leaf, it either has won or lost, and handles the situation as * described above. */ int main (int argc, char *argv[]) { char *treefile = NULL; TreeType tree; PositionType pos; char *newQuestion, *newAnswer; if (argc > 1) { treefile = argv[1]; } tree = InitTree (treefile); printf("%s", "Think of an animal. I will try to guess what it is.\n" "Please answer my questions with yes or no.\n"); while (TRUE) { pos = Top (tree); while (!IsLeaf (tree, pos)) { pos = Answer(Question(tree,pos))? YesNode(tree,pos): NoNode(tree,pos); } if (Answer (Guess (tree, pos))) { printf ("I got it right!\n"); } else { GetNewInfo (tree, pos, &newAnswer, &newQuestion); ReplaceNode (tree, pos, newAnswer, newQuestion); } if (!Answer ("Want to play again? ")) { WriteTree(tree, treefile); exit (0); } } }
void Game::receiveQuestionFromDB(QList<QStringList> questionLists) { QList<Question> questionObjects = QList<Question>(); int random = 349; for(QStringList & questionList : questionLists) { Question q = Question(opposingCandidate, questionList, random); questionObjects.append(q); random += 13; } emit returnQuestions(questionObjects); }
BOOL SystemHandler::killTrace() { OMsgs msg; OString Title(30); OString Question(100); msg.loadString(APP_TITLE, 30, Title.text); msg.loadString(SURE_TO_EXIT, 100, Question.text); if (WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, Question.text, Title.text, GTPM_ICO, MB_YESNO | MB_ICONQUESTION | MB_DEFBUTTON1)==MBID_YES) WinPostMsg(NULLHANDLE, WM_QUIT, (MPARAM)0, (MPARAM)100); return(TRUE); // continue by default }
//add commando met een positie int QuestionList::add(Question::QuestionType type, std::string& question_string, std::string *answers, int amount_of_answers, int position) { //pointer bij houden naaar het oudestuk geheugen Question* old_questions(questions_); //hulp variabelen int index(0); bool skipped(false); //nieuw stuk geheugen alloceren questions_ = new Question[amount_of_questions_ + 1]; //over de vragen lopen while (index < (amount_of_questions_ + 1)) { //vraag moet ingevoegd worden if (index == (position - 1)) { Question q = Question(index + 1, type, question_string, answers, amount_of_answers); questions_[index] = q; //ervoor zorgen dat de destructor de antwoorden niet dealloceert q.copied = true; //we hebben een index geskipped in de oude array skipped = true; } else { if (skipped) { questions_[index] = old_questions[index - 1]; //index loopt gewoon door dus moet je 1 achteruit in de oude kijken questions_[index].increase_id(); //vragen moeten nu een nummer hoger hebben old_questions[index - 1].copied = true; } else { questions_[index] = old_questions[index]; //we moet de antwoorden niet verwijderen want dat zou een probleem zijn old_questions[index].copied = true; } } index++; } amount_of_questions_++; dirty = true; //oude vragen dealloceren delete[] old_questions; //positie terug geven voor het antwoord op het commando return position; }
void PredicateDialog::onDeletePredicate() { Glib::RefPtr < Gtk::TreeView::Selection > ref = mTreePredicateList-> get_selection(); if (ref) { Gtk::TreeModel::iterator iter = ref->get_selected(); if (iter) { if (Question(_("Are you sure you want to delete this predicate?"))) { mPredicateNameEntry->set_text(""); mTextViewFunction->get_buffer()->set_text(""); mHeaderPred->set_text(""); Gtk::TreeModel::Row row = *iter; std::string name(row.get_value(m_viewscolumnrecord.name)); m_model->erase(iter); Gtk::TreeModel::Children children = m_model->children(); m_iter = children.begin(); // Delete the element in the vector for (std::vector < std::string > ::iterator it = mPredicateName.begin(); it != mPredicateName.end(); ) { if ( *it == name ) { it = mPredicateName.erase(it); } else { ++it; } } if (mPredicateFunction.find(name) != mPredicateFunction.end()) { mPredicateFunction.erase(name); } setSensitivePredicate(false); } } } }
void addSimpleAdjectiveQuestions(Quiz &quiz, const SweDictionary &sweDict, const quint16 &count) { QString questionText; QList<Adjective> &adjectives = sweDict.getRandomAdjectives(count); for (int i = 0; i < adjectives.size(); i++) { questionText.append("What is "); questionText.append(adjectives.at(i).getEnglishTranslation()); questionText.append(" in swedish?"); const QString &posForm = adjectives.at(i).getPositivForm(); QList<QString> answer; answer.append(posForm); const Question &q = Question(questionText, answer, Question::ADJECTIVE); quiz.addQuestion(q); questionText.clear(); } delete &adjectives; }
void addSimpleVerbQuestions(Quiz &quiz, const SweDictionary &sweDict, const quint16 &count) { QString questionText; QList<Verb> &verbs = sweDict.getRandomVerbs(count); for (int i = 0; i < verbs.size(); i++) { questionText.append("What is "); questionText.append(verbs.at(i).getEnglishTranslation()); questionText.append(" in swedish?"); const QString &infForm = verbs.at(i).getInfinitivForm(); QList<QString> answer; answer.append(infForm); const Question &q = Question(questionText, answer, Question::VERB); quiz.addQuestion(q); questionText.clear(); } delete &verbs; }
int main(void) { char answer='y'; srand((int)time(NULL)); Start(); while(answer=='y') { BettingPrint(); Choice(); Progress(); if(YourMoney()==0) break; else answer=Question(); } system("PAUSE"); return 0; }
void addDetailedAdjectiveQuestions(Quiz &quiz, const SweDictionary &sweDict, const quint16 &count) { QString questionText; QList<Adjective> &adjectives = sweDict.getRandomAdjectives(count); for (int i = 0; i < adjectives.size(); i++) { questionText.append("What are the forms of \""); questionText.append(adjectives.at(i).getEnglishTranslation()); questionText.append("\" in swedish?"); QList<QString> answer; answer.append(adjectives.at(i).getPositivForm()); answer.append(adjectives.at(i).getKomparativForm()); answer.append(adjectives.at(i).getSuperlativForm()); const Question &q = Question(questionText, answer, Question::ADJECTIVE); quiz.addQuestion(q); questionText.clear(); } delete &adjectives; }
MessageWindow::Response MessageWindow::Question(Window *window, const String& text, Buttons buttons) { return Question(window, text, "", buttons); }
MessageWindow::Response MessageWindow::Question(const String& text, const String& caption, Buttons buttons) { return Question(nullptr, text, caption, buttons); }
void Questioner::repaintNewCube(unsigned int cube) { //LOG("repainting New Questioner Cube\n"); myCube = cube; myGameDrawer->drawQuestionerBackground(myCube); currPan = vec(0,0); targetPan = vec(0,0); yCurrQuestion = FIRST_QUESTION_HEIGHT; int *questionHolder; if(panning) { panning = 0; if( currPan == targetPan) { if(currQuestion.equals(prevQuestion)) { currQuestion = newQuestion; //print both curr and prev questionHolder = currQuestion.retrieveQuestion(); currQuestion = Question(myGameDrawer, myCube, 4, questionHolder,0); questionHolder = prevQuestion.retrieveQuestion(); prevQuestion = Question(myGameDrawer, myCube, 8, questionHolder,1); } else { currQuestion = newQuestion; //print just curr questionHolder = currQuestion.retrieveQuestion(); currQuestion = Question(myGameDrawer, myCube, 4, questionHolder,0); } } else { prevQuestion = currQuestion; currQuestion = newQuestion; //print both curr and prev questionHolder = currQuestion.retrieveQuestion(); currQuestion = Question(myGameDrawer, myCube, 4, questionHolder,0); questionHolder = prevQuestion.retrieveQuestion(); prevQuestion = Question(myGameDrawer, myCube, 8, questionHolder,1); } } else { //print curr and prev if(totalAsked) { questionHolder = currQuestion.retrieveQuestion(); currQuestion = Question(myGameDrawer, myCube, 4, questionHolder,0); questionHolder = prevQuestion.retrieveQuestion(); prevQuestion = Question(myGameDrawer, myCube, 8, questionHolder,1); } else { questionHolder = currQuestion.retrieveQuestion(); currQuestion = Question(myGameDrawer, myCube, 4, questionHolder,0); } } }
Test::Test() { // qDebug() << "Test construction"; points = 0; for (int i=0; i < 20; i ++) q[i] = Question(); //qDebug() << "end Test construction"; }
void Questioner::runGame(TimeDelta myDelta) { if(panning) { timePanning += myDelta.milliseconds(); if(timePanning > TIME_TO_CORRECT && !corrQuestAns) { corrQuestAns = 1; currQuestion.updateToCorrect(); } currPan = doPanning(targetPan,timePanning); if(currPan == targetPan) { prevQuestion.clean(); prevQuestion = currQuestion; currQuestion = newQuestion; panning = 0; } } else if(currQuestion.answered()) { yCurrQuestion = yCurrQuestion - 6; if(yCurrQuestion < 0) { yCurrQuestion += 18; } newQuestion = Question(myGameDrawer, myCube, yCurrQuestion); targetPan = currPan - vec(0,48); if(currPan.y < 0) { targetPan.y = targetPan.y += 144; currPan.y = currPan.y += 144; } timePanning = 0; panning = 1; corrQuestAns = 0; int correct = currQuestion.wasRight(); if(!correct) { if(longestStreak < currStreak) { longestStreak = currStreak; } currStreak = 0; } else { currStreak += correct; //LOG("currStreak = %d questioner with cubeID = %d\n",currStreak, (int)myCube); totalCorrect += correct; if(!(currStreak % 5)) { extraTime = 1; } } totalAsked++; } //LOG("Questioner about to return runGame()\n"); }
/// <summary> /// Handle new body data /// <param name="nTime">timestamp of frame</param> /// <param name="nBodyCount">body data count</param> /// <param name="ppBodies">body data in frame</param> /// </summary> void CColorBasics::ProcessBody(INT64 nTime, int nBodyCount, IBody** ppBodies) { if (m_hWnd) { HRESULT hr = S_OK; D2D1_POINT_2F start; start.x = 1500.0; start.y = 800.0; D2D1_POINT_2F quit; quit.x = 300.0; quit.y = 800.0; //int width = 0; //int height = 0; if (SUCCEEDED(hr) && m_pCoordinateMapper) { // 先に実行しているProcessColor()にて行っているのでコメント //hr = m_pDrawColor->BeginDraw(); DetectionResult nEngaged[6] = { DetectionResult_Unknown }; PointF lean; //RECT rct; //GetClientRect(GetDlgItem(m_hWnd, IDC_VIDEOVIEW), &rct); //width = rct.right; //height = rct.bottom; UINT64 nTrackBody = 10; for (int i = 0; i < nBodyCount; ++i) { IBody* pBody = ppBodies[i]; if (pBody) { // 手旗二人での対戦モードを想定してインデックスを取得する。 // 本来はゲーム前に対戦の二人wフィックスしておくべきだろうが。 // // トラッキングされているボディかはちゃんと確かめること。 BOOLEAN bTracked = false; hr = pBody->get_IsTracked(&bTracked); // Engaged()は使えるみたい。これは、視野に入ってきた人を認識するものだろう。 hr = pBody->get_Engaged(&nEngaged[i]); pBody->get_Lean(&lean); // 以下はまだ使えないようだ //hr = pBody->GetAppearanceDetectionResults((UINT)i, &nEngaged[i]); if (SUCCEEDED(hr) && bTracked) { // トラッキングが無効な場合のインデックスは0が返るので使い方に注意!! UINT64 nBodyIndex = 0; hr = pBody->get_TrackingId(&nBodyIndex); Joint joints[JointType_Count]; D2D1_POINT_2F jointPoints[JointType_Count]; HandState leftHandState = HandState_Unknown; HandState rightHandState = HandState_Unknown; pBody->get_HandLeftState(&leftHandState); pBody->get_HandRightState(&rightHandState); hr = pBody->GetJoints(_countof(joints), joints); if (SUCCEEDED(hr)) { // スクリーン座標に変換 for (int j = 0; j < _countof(joints); ++j) { jointPoints[j] = BodyToScreen(joints[j].Position); } // ここに頭部に丸を描いて、ボディ番号を表示 m_pDrawColor->DrawHead(jointPoints[JointType_Head], i, nEngaged[i], lean); // 手先がある領域にきたら実行 // ボタンのような // 現状、複数人が認識されても実行するので、本来は最初に認識された一人のみにする必要がある。 float xy[2] = { 0.0 }; if (!m_bSemaphore) { if (m_pSemaphore[0]) { delete m_pSemaphore[0]; m_pSemaphore[0] = NULL; } if (m_pSemaphore[1]) { delete m_pSemaphore[1]; m_pSemaphore[1] = NULL; } m_nButton = 1; xy[0] = jointPoints[JointType_HandTipRight].x - start.x; xy[1] = jointPoints[JointType_HandTipRight].y - start.y; if (sqrt( xy[0]*xy[0] + xy[1]*xy[1] ) < 100.0 ) { if (nTrackBody == 10 || nTrackBody == nBodyIndex) { m_nButton = 0; nTrackBody = nBodyIndex; } } } else { // 手旗スタート // 手旗判定 if (m_pSemaphore[0] == NULL) { m_pSemaphore[0] = new Semaphore( &nBodyIndex ); } else { if (m_pSemaphore[1] == NULL && !m_pSemaphore[0]->ItsMe(&nBodyIndex)) { m_pSemaphore[1] = new Semaphore(&nBodyIndex); } } // カウント // 基本ポーズでのデータ取得 // 手旗本番処理 // 手旗の判定に画像と同等のフレームは必要はないのでは。 // タイマーでBodyフレームを取得し、それで手旗判定を行う。 if (m_pSemaphore[0]) { m_pSemaphore[0]->SetSignalType(&nBodyIndex, jointPoints, m_pDrawColor); } if (m_pSemaphore[1]) { m_pSemaphore[1]->SetSignalType(&nBodyIndex, jointPoints, m_pDrawColor); } //m_pSemaphore[0]->Practice(nTime, jointPoints, m_pDrawColor); // quitボタン処理 m_nButton = 2; // 基本ポーズ用の表示 xy[0] = jointPoints[JointType_HandTipLeft].x - quit.x; xy[1] = jointPoints[JointType_HandTipLeft].y - quit.y; if (sqrt( xy[0]*xy[0] + xy[1]*xy[1] ) < 100.0 ) { if (nTrackBody == 10 || nTrackBody == nBodyIndex) { m_nButton = 0; nTrackBody = nBodyIndex; } } } m_pDrawColor->DrawBody(joints, jointPoints); //m_pDrawColor->DrawHand(leftHandState, jointPoints[JointType_HandLeft]); //m_pDrawColor->DrawHand(rightHandState, jointPoints[JointType_HandRight]); Detect(pBody); //break; } } } } if (!m_bSemaphore) { // このボタン処理でウィンドウにメッセージを送っている m_pDrawColor->DrawButton(start, m_nButton); } else { m_pDrawColor->DrawButton(quit, m_nButton); } // 二人対戦モードのお題表示 if (Question(nTime)) { m_pDrawColor->DrawButton(quit, 0); } m_pDrawColor->EndDraw(); } } }