private void OnAsk(QuestionData question) { StringBuilder sb = new StringBuilder(); sb.AppendFormat("{0}. {1} Answer 1-{2}: ", _step + 1, question.Question.Value, question.Answers.Count); for (int i = 0; i < question.Answers.Count; i++) { sb.AppendFormat("{0}. {1}", i + 1, question.Answers[i]); if (i < question.Answers.Count - 1) { sb.Append(", "); } } //show question tw.RespondMessage(sb.ToString()); _currentQuestion = question; //start listening for answers State = State.ListeningForAnswers; _startedListening = DateTime.Now; Task.Run(async delegate { await Task.Delay(TimeSpan.FromSeconds(NUM_SECONDS_TO_WAIT)); ListenForAnswers(); }, cancel.Token); }
private void Stop() { //clear state _step = 0; _stepOfLastProposal = 0; _answerCount.Clear(); _startedListening = DateTime.MinValue; _userThatStartedGame = null; _session = null; _signature = null; _currentQuestion = null; //cancel cancel.Cancel(); }
private void Hello(MessageInfo message) { _step = 0; var response = akinatorApi.NewSession(message.Username); this._session = response.parameters.identification.session; this._signature = response.parameters.identification.signature; this._userThatStartedGame = message.Username; QuestionData question = new QuestionData(response); tw.RespondMessage(string.Format("20 Questions has started! You will have {0} seconds to answer and the top answer will be submitted.", NUM_SECONDS_TO_WAIT)); OnAsk(question); }
private void SendAnswer(int answerID) { if (State != State.ListeningForAnswers) { return; } State = State.Started; var response = akinatorApi.Answer(this._session, this._signature, this._step, answerID); QuestionData question = new QuestionData(response); //clear the last round of answers _answerCount.Clear(); _step++; if (_step >= MAX_QUESTIONS) { //always present answers at cap GetCharacters(); } else if (_step - _stepOfLastProposal < MIN_STEPS_BETWEEN_PROPOSAL) { //don't present answers too often OnAsk(question); } else if (question.Progression > THRESHOLD || _step - _stepOfLastProposal == MAX_BEFORE_FIRST_PROPOSAL) { //if we meet the threshold or it or we're due to make a guess anyway if (_step + 5 >= MAX_QUESTIONS) { //if we're near the end keep asking OnAsk(question); } else { //present the answer! GetCharacters(); } } else { OnAsk(question); } }