Skip to content
This repository has been archived by the owner on Sep 17, 2019. It is now read-only.

[20Q Game] Fix Offline Startup Crash #75

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.markozajc.akiwrapper.core.entities.Question;
import com.markozajc.akiwrapper.Akiwrapper.Answer;
import com.markozajc.akiwrapper.core.entities.Guess;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import roboy.context.Context;
Expand All @@ -29,12 +30,12 @@
public class GamingTwentyQuestionsState extends State {


private static final double PROBABILITY_THRESHOLD = 0.6;
private final static double PROBABILITY_THRESHOLD = 0.6;
private final static String TRANSITION_GAME_ENDED = "gameEnded";

private final Logger LOGGER = LogManager.getLogger();

private Akiwrapper aw = new AkiwrapperBuilder().setFilterProfanity(true).build();
private Akiwrapper aw;
private Question nextQuestion = null;
private Guess currentGuess = null;

Expand All @@ -43,18 +44,39 @@ public class GamingTwentyQuestionsState extends State {
private boolean guessesAvailable = false;
private boolean gameFinished = false;
private boolean stopGame = false;
private boolean network = false;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Give this a better name


private boolean filterApplied = false;
private boolean emotionShown = false;
private String winner = "";

public GamingTwentyQuestionsState(String stateIdentifier, StateParameters params) {
super(stateIdentifier, params);
startAW();
}

private void startAW(){
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This definitely needs changing. Name needs to be changed, way the logic works needs to be changed.

startAW(false);
}
private void startAW(boolean force){
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename Force

if(force || aw==null){
try{
aw = new AkiwrapperBuilder().setFilterProfanity(true).build();
network=true;
}catch (Exception e){
aw = null;
LOGGER.warn("Exception Init AkiWrapper. Please check your network connection.");
if(LOGGER.getLevel().isLessSpecificThan(Level.DEBUG))e.printStackTrace();
}
}
}

@Override
public Output act() {

startAW();
if(!network){
return Output.say("A network connection is required to play this game, should I try and look for a connection again?");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change this string

}
if(!userReady){
return Output.say(PhraseCollection.AKINATOR_INTRO_PHRASES.getRandomElement());

Expand Down Expand Up @@ -83,6 +105,11 @@ public Output react(Interpretation input) {
String intent = getIntent (input);
Linguistics.UtteranceSentiment inputSentiment = getInference().inferSentiment(input);

if(!network){
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alter this, there's probably a cleaner way to do this

if(inputSentiment == Linguistics.UtteranceSentiment.NEGATIVE) gameFinished=true;
return Output.sayNothing();
}

if(checkUserSaidStop(input)){
gameFinished = true;
return Output.sayNothing();
Expand Down Expand Up @@ -253,7 +280,7 @@ private Output processUserGuessAnswer(String intent){

private void resetGame(){

aw = new AkiwrapperBuilder().setFilterProfanity(true).build();
startAW(true);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really what you want to do, is it even required that we reset AW. Can you get to this state without AW being set

declined.clear();
userReady = false;
guessesAvailable = false;
Expand Down