Skip to content
Open
Show file tree
Hide file tree
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
12 changes: 11 additions & 1 deletion src/main/java/gameData/StateManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import gameData.enums.Difficulty;
import gameData.enums.TurnState;
import gameData.enums.VoiceState;
import gameVoiceHandler.intents.speeches.Speeches;

/**
* Created by corentinl on 1/23/16.
Expand All @@ -25,7 +26,8 @@ public class StateManager {

private boolean hitOrMissedQuestionAsked = false;

private static String lastQuestionAsked = "";
private static String lastQuestionAsked = Speeches.WELCOME + Speeches.PROMPT_FOR_INSTRUCTIONS;
private static String lastReprompt = Speeches.PROMPT_FOR_INSTRUCTIONS;

public StateManager(int gridSize,
int numberOfShips,
Expand Down Expand Up @@ -212,6 +214,14 @@ public void setLastQuestionAsked(String lastQuestionAsked) {
this.lastQuestionAsked = lastQuestionAsked;
}

public String getLastReprompt() {
return lastReprompt;
}

public void setLastReprompt(String lastReprompt) {
StateManager.lastReprompt = lastReprompt;
}

public boolean isHitOrMissedQuestionAsked() {
return hitOrMissedQuestionAsked;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,26 +48,23 @@ public SpeechletResponse handleIntent(Intent intent, GameDataInstance gameDataIn
speechOutput += Speeches.YOUR_TURN;
String repromptText = Speeches.YOUR_TURN + InstructionsUtil.fireInstructions(stateManager);
stateManager.setLastQuestionAsked(repromptText);
stateManager.setLastReprompt(repromptText);

stateManager.setTurnState(TurnState.PLAYER);

return SpeechesGenerator.newAskResponse(speechOutput, false, repromptText, false);
}
} else {
speechOutput = stateManager.getLastQuestionAsked();
return SpeechesGenerator.newAskResponse(speechOutput, false, speechOutput, false);
speechOutput = Speeches.INCORRECT_HIT_MISS + stateManager.getLastReprompt();
return SpeechesGenerator.newAskResponse(speechOutput, false, stateManager.getLastReprompt(), false);
}
} else {
String speechOutput = Speeches.WAS_YOUR_TURN + stateManager.getLastQuestionAsked();
return SpeechesGenerator.newAskResponse(speechOutput, false, stateManager.getLastQuestionAsked(), false);
String speechOutput = Speeches.WAS_YOUR_TURN + stateManager.getLastReprompt();
return SpeechesGenerator.newAskResponse(speechOutput, false, stateManager.getLastReprompt(), false);
}
}

private boolean isIntentExpected(GameDataInstance gameDataInstance) {
return gameDataInstance.getStateManager().isGamesStarted();
}

private static SpeechletResponse handleHelpAsked() {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public SpeechletResponse handleIntent(Intent intent, GameDataInstance gameDataIn
StateManager stateManager = gameDataInstance.getStateManager();

String speechOutput = GameStarterUtil.incorrectParametersSpeech();
String repromptText = speechOutput;
String repromptText;

if (intent.getSlot(GRID_SIZE_SLOT) != null) {
String gridSizeParameter = intent.getSlot(GRID_SIZE_SLOT).getValue();
Expand All @@ -51,11 +51,15 @@ public SpeechletResponse handleIntent(Intent intent, GameDataInstance gameDataIn
speechOutput += GameStarterUtil.startGameSpeech(stateManager);
repromptText = Speeches.YOUR_TURN + InstructionsUtil.fireInstructions(stateManager);
} else {
speechOutput += ParametersUtil.issueWithParametersSpeech(stateManager);
String missingOrIncorrectParameterSpeech = ParametersUtil.missingOrIncorrectParameterSpeech(stateManager);
speechOutput += missingOrIncorrectParameterSpeech;
repromptText = missingOrIncorrectParameterSpeech;
}
stateManager.setLastQuestionAsked(repromptText);

return SpeechesGenerator.newAskResponse(speechOutput, false, speechOutput, false);
stateManager.setLastQuestionAsked(speechOutput); //TODO: The instructions are not always put in there, because of the multi use of startGameSpeech
stateManager.setLastReprompt(repromptText);

return SpeechesGenerator.newAskResponse(speechOutput, false, repromptText, false);
}

private boolean isIntentExpected(GameDataInstance gameDataInstance) {
Expand Down
13 changes: 3 additions & 10 deletions src/main/java/gameVoiceHandler/intents/handlers/HandleHelp.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,9 @@ public class HandleHelp implements HandlerInterface {
public SpeechletResponse handleIntent(Intent intent, GameDataInstance gameDataInstance) {
StateManager stateManager = gameDataInstance.getStateManager();

if (!stateManager.isGamesStarted()) {
String speechOutput = Speeches.IM_SORRY + Speeches.NOT_IMPLEMENTED;//Speeches.HELP_SPEECH_BEGINNING + Speeches.HELP_SPEECH_BEGINNING_REPROMPT;
String speechOutput = stateManager.getLastQuestionAsked();
String repromptText = stateManager.getLastReprompt();

//String repromptText = Speeches.HELP_SPEECH_BEGINNING_REPROMPT;

return SpeechesGenerator.newAskResponse(speechOutput, false, speechOutput, false);
} else {
//TODO: determine the current state and give appropriate help.
//TODO: and help wasn't asked but result in a call from another handler, give an error message. Maybe the whole error process should be handled in a different method or class
return null;
}
return SpeechesGenerator.newAskResponse(speechOutput, false, repromptText, false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public SpeechletResponse handleIntent(Intent intent, GameDataInstance gameDataIn

String repromptText = Speeches.ADVANCED_GAME_PARAMETERS_PROMPT;

stateManager.setLastQuestionAsked(repromptText);
stateManager.setLastQuestionAsked(speechOutput); //TODO: Check why this always contains the instructions even if we answered no
stateManager.setLastReprompt(repromptText);

return SpeechesGenerator.newAskResponse(speechOutput, false, repromptText, false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,13 @@ public SpeechletResponse handleIntent(Intent intent, GameDataInstance gameDataIn
speechOutput = GameStarterUtil.startGameSpeech(stateManager);
repromptText = Speeches.YOUR_TURN + InstructionsUtil.fireInstructions(stateManager);
} else {
ParametersUtil.issueWithParametersSpeech(stateManager);
speechOutput = ParametersUtil.missingOrIncorrectParameterSpeech(stateManager);
}
}
}

stateManager.setLastQuestionAsked(repromptText);
stateManager.setLastQuestionAsked(speechOutput);
stateManager.setLastReprompt(repromptText);

return SpeechesGenerator.newAskResponse(speechOutput, false, speechOutput, false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public SpeechletResponse handleIntent(Intent intent, GameDataInstance gameDataIn
String speechOutput = Speeches.QUICK_GAME_LAUNCH + GameStarterUtil.startGameSpeech(stateManager);
String repromptText = Speeches.YOUR_TURN + InstructionsUtil.fireInstructions(stateManager);

stateManager.setLastQuestionAsked(repromptText);
//NOTE: The last question asked is setup in GameStartedUtil
stateManager.setLastReprompt(repromptText);

return SpeechesGenerator.newAskResponse(speechOutput, false, repromptText, false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ public SpeechletResponse handleIntent(Intent intent, GameDataInstance gameDataIn
if (gameManager.gameIsOver()) {
return SpeechesGenerator.newTellResponse(speechOutput);
} else {
return SpeechesGenerator.newAskResponse(speechOutput, false, speechOutput, false);//TODO: Check the reprompt
return SpeechesGenerator.newAskResponse(speechOutput, false, stateManager.getLastReprompt(), false);
}
} else {
String speechOutput = Speeches.NOT_YOUR_TURN + stateManager.getLastQuestionAsked();
return SpeechesGenerator.newAskResponse(speechOutput, false, stateManager.getLastQuestionAsked(), false);
String speechOutput = Speeches.NOT_YOUR_TURN + stateManager.getLastReprompt();
return SpeechesGenerator.newAskResponse(speechOutput, false, stateManager.getLastReprompt(), false);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,16 @@ public static String fire(GameDataInstance gameDataInstance) {
} else {
Coordinates alexaFire = gameManager.nextAlexaHit();

repromptText = String.format(Speeches.MY_TURN, (char)(alexaFire.x + 'a'), alexaFire.y + 1);
String instructions = InstructionsUtil.answerInstructionsIfRequired(stateManager);
repromptText = instructions == null ? repromptText : repromptText + instructions;
String myTurnSpeech = String.format(Speeches.MY_TURN, (char) (alexaFire.x + 'a'), alexaFire.y + 1);
String instructionsIfRequired = InstructionsUtil.answerInstructionsIfRequired(stateManager);
String instructions = InstructionsUtil.answerInstructions();
repromptText = myTurnSpeech + instructions;
speechOutput += myTurnSpeech;

stateManager.setLastQuestionAsked(repromptText);
speechOutput += repromptText;
stateManager.setLastQuestionAsked(speechOutput + instructions);
stateManager.setLastReprompt(repromptText);

speechOutput += instructionsIfRequired;
}

stateManager.setTurnState(TurnState.ALEXA);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ public static String incorrectParametersSpeech() {
public static String startGameSpeech(StateManager stateManager) {
String gameLaunchSpeech = String.format(Speeches.GAME_LAUNCH, stateManager.getGridSize(), stateManager.getGridSize(), stateManager.getNumberOfShips());
String speechOutput = gameLaunchSpeech + Speeches.YOUR_TURN;
String instructions = InstructionsUtil.fireInstructionsIfRequired(stateManager);
speechOutput = instructions == null ? speechOutput : speechOutput + instructions;
String instructions = InstructionsUtil.fireInstructions(stateManager);
String instructionsIfRequired = InstructionsUtil.fireInstructionsIfRequired(stateManager);
stateManager.setLastQuestionAsked(speechOutput + instructions);
speechOutput = instructionsIfRequired == null ? speechOutput : speechOutput + instructionsIfRequired;

return speechOutput;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,25 @@ public class InstructionsUtil {
public static SpeechletResponse startInstructions(StateManager stateManager) {
boolean instructionsRequested = stateManager.isInstructionsRequested();

String speechOutput;
String reprompt;

if (instructionsRequested) {
speechOutput = Speeches.GENERAL_INSTRUCTIONS
+ Speeches.LETS_START
+ Speeches.HELP_SPEECH_BEGINNING
+ Speeches.HELP_SPEECH_BEGINNING_REPROMPT
+ Speeches.HELP_SPEECH_BEGINNING_INSTRUCTIONS;
String speechOutput = Speeches.GENERAL_INSTRUCTIONS
+ Speeches.LETS_START
+ Speeches.HELP_SPEECH_BEGINNING
+ Speeches.HELP_SPEECH_BEGINNING_REPROMPT
+ Speeches.HELP_SPEECH_BEGINNING_INSTRUCTIONS;
String reprompt = Speeches.HELP_SPEECH_BEGINNING_REPROMPT
+ Speeches.HELP_SPEECH_BEGINNING_INSTRUCTIONS;

stateManager.setLastQuestionAsked(speechOutput);
stateManager.setLastReprompt(reprompt);

if (!instructionsRequested) {
speechOutput = Speeches.HELP_SPEECH_BEGINNING
+ Speeches.HELP_SPEECH_BEGINNING_REPROMPT;
reprompt = Speeches.HELP_SPEECH_BEGINNING_REPROMPT
+ Speeches.HELP_SPEECH_BEGINNING_INSTRUCTIONS;
} else {
speechOutput = Speeches.HELP_SPEECH_BEGINNING + Speeches.HELP_SPEECH_BEGINNING_REPROMPT;
reprompt = Speeches.HELP_SPEECH_BEGINNING_REPROMPT + Speeches.HELP_SPEECH_BEGINNING_INSTRUCTIONS;
}




//stateManager.setLastQuestionAsked(reprompt); //TODO: Move the lasQuestionAsked to StateManager

return SpeechesGenerator.newAskResponse(speechOutput, false, reprompt, false);
}

Expand Down Expand Up @@ -67,13 +65,13 @@ public static String answerInstructionsIfRequired(StateManager stateManager) {
boolean instructionsRequired = stateManager.isInstructionsRequested() && stateManager.isAnswerInstructionsRequested();
if (instructionsRequired) {
stateManager.setAnswerInstructionsRequested(false);
return instructions + answerInstructions(stateManager);
return instructions + answerInstructions();
} else {
return instructions;
}
}

public static String answerInstructions(StateManager stateManager) {
public static String answerInstructions() {
return Speeches.ANSWER_EXAMPLE;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Created by corentinl on 3/8/16.
*/
public class ParametersUtil {
public static String issueWithParametersSpeech(StateManager stateManager) {
public static String missingOrIncorrectParameterSpeech(StateManager stateManager) {
if (stateManager.areParametersEntered()) {
return ParametersUtil.parametersIncorrectSpeech(stateManager);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
public class YesNoUtil {
public static SpeechletResponse handleYesNo(GameDataInstance gameDataInstance, boolean answer) {
StateManager stateManager = gameDataInstance.getStateManager();
GameManager gameManager = gameDataInstance.getGameManager();
VoiceState voiceState = stateManager.getVoiceState();

if (voiceState == VoiceState.PROMPT_FOR_INSTRUCTIONS) {
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/gameVoiceHandler/intents/speeches/Speeches.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
* Created by corentinl on 1/23/16.
*/
public class Speeches {
//APPLICATION NAME
public static final String APP_NAME = "Boat War";

//WELCOMING
public static final String WELCOME = "Welcome to Battleship! ";
public static final String WELCOME = "Welcome to " + APP_NAME + "! ";
public static final String PROMPT_FOR_INSTRUCTIONS = "Would you like to hear the instructions? ";

//FILTER REQUESTS
Expand Down Expand Up @@ -129,7 +132,7 @@ public class Speeches {
public static final String YOU_LOSE = "You loose! The machines will kill all of you! ";

//HELP
public static final String GENERAL_INSTRUCTIONS = "Battleship is a game when you and I, will each have a grid in which there will be ships. "
public static final String GENERAL_INSTRUCTIONS = APP_NAME + " is a game when you and I, will each have a grid in which there will be ships. "
+ "Those grids will have a size from 3 by 3, to 10 by 10. "
+ "For now, the ships will all have a size of two. "
+ "You have to memorize your grid, and I will memorize mine. ";
Expand Down
20 changes: 1 addition & 19 deletions src/main/java/gameVoiceHandler/speechAssets/IntentSchema.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,24 +72,6 @@
}
]
},
{
"intent": "oneFirePosition",
"slots": [
{
"name": "lineOrColumn",
"type": "AMAZON.NUMBER"
}
]
},
{
"intent": "oneFirePositionLetter",
"slots": [
{
"name": "lineLetter",
"type": "LETTERS"
}
]
},
{
"intent": "AMAZON.YesIntent"
},
Expand All @@ -103,7 +85,7 @@
"intent": "AMAZON.StopIntent"
},
{
"intent": "WhatsMyColorIntent"
"intent": "AMAZON.CancelIntent"
}
]
}
10 changes: 8 additions & 2 deletions src/main/java/gameVoiceHandler/speechAssets/SampleUtterances.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,21 @@ startQuickGameIntent quick game
startQuickGameIntent game quick
startQuickGameIntent launch a quick game
startQuickGameIntent launch quick game
startQuickGameIntent launch boat war and quick game
startQuickGameIntent launch boat war quick game
startQuickGameIntent boat war and quick game
startQuickGameIntent boat war quick game

startAdvancedGameIntent start an advanced game
startAdvancedGameIntent start advanced game
startAdvancedGameIntent advanced game
startAdvancedGameIntent game advanced
startAdvancedGameIntent launch an advanced game
startAdvancedGameIntent launch advanced game
startAdvancedGameIntent launch boat war and advanced game
startAdvancedGameIntent launch boat war advanced game
startAdvancedGameIntent boat war and advanced game
startAdvancedGameIntent boat war advanced game

startAdvancedGameWithParametersIntent grid size of {gridSize} and {numberOfShips} ships
startAdvancedGameWithParametersIntent grid {gridSize} and {numberOfShips} ships
Expand Down Expand Up @@ -87,5 +95,3 @@ fireAtLetterAndNumberIntent fire at line {lineLetter} column {columnNumber}
fireAtLetterAndNumberIntent line {lineLetter} column {columnNumber}
fireAtLetterAndNumberIntent fire at line {lineLetter} and column {columnNumber}
fireAtLetterAndNumberIntent line {lineLetter} and column {columnNumber}

oneFirePosition fire at {lineOrColumn}