-
Notifications
You must be signed in to change notification settings - Fork 6
[20Q Game] Fix Offline Startup Crash #75
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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; | ||
|
||
|
@@ -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; | ||
|
||
private boolean filterApplied = false; | ||
private boolean emotionShown = false; | ||
private String winner = ""; | ||
|
||
public GamingTwentyQuestionsState(String stateIdentifier, StateParameters params) { | ||
super(stateIdentifier, params); | ||
startAW(); | ||
} | ||
|
||
private void startAW(){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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()); | ||
|
||
|
@@ -83,6 +105,11 @@ public Output react(Interpretation input) { | |
String intent = getIntent (input); | ||
Linguistics.UtteranceSentiment inputSentiment = getInference().inferSentiment(input); | ||
|
||
if(!network){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
|
@@ -253,7 +280,7 @@ private Output processUserGuessAnswer(String intent){ | |
|
||
private void resetGame(){ | ||
|
||
aw = new AkiwrapperBuilder().setFilterProfanity(true).build(); | ||
startAW(true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
There was a problem hiding this comment.
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