SMACJo Jaquinta
Created June 7, 2017

WhereWolf

Embrace Your Inner Werewolf: learn some werewolf factget the moon phase, hear the howls, get the hunting report, hear your werewolf jam

35
WhereWolf

Things used in this project

Hardware components

Amazon Echo
Amazon Alexa Amazon Echo
×1

Software apps and online services

Alexa Skills Kit
Amazon Alexa Alexa Skills Kit

Story

Read more

Schematics

WhereWolf Schematics

We use a technique to deliver different introductory phrases for each piece of information. It is meant to change how we deliver the same information.

Code

Handler for main application state

Java
TsaTsaTzu's skills are all based on a comprehensive cross platform library. (For details see the SubWar project.) This insulates your application logic from the specifics of each platform. Below you can see the main logic that drives Wherewolf.
Another point to note is that all text has been extracted. This is to make it easy to localize the skill for different languages. The "response" command takes a key value, which points to a phrase in a language table, as well as a number of arguments. These arguments are inserted into the string at marked places. The language table may contain a single message, for help or errors. Or it may contain multiple messages, of which one is picked randomly. This allows for a varied response without affecting the code logic.
An AudioMessageBean object may be passed instead, which encapsulates the key and arguments. What's particularly interesting is that the arguments may, themselves, be AudioMessageBeans. This allows a double level of indirection. With this both the arguments may be random lookups, and the phrase may be a random lookup. This allows for complex variance and keeps the user engaged.
As you can see from the below example, the code is very simple. But if you play the game, the responses are quite varied.
public class BaseStateHandler extends StateHandler
{
    private MoonLogic mMoon = new MoonLogic(Calendar.getInstance());
    
    @Override
    public void addReprompts(BaseUserState state)
    {
        // NOP
    }

    @Override
    public void handleWelcome(BaseUserState state)
    {
        mMoon.updateCal(Calendar.getInstance());
        int phase = mMoon.getPhaseIndex();
       
        List<AudioMessageBean> responses = new ArrayList<>();
        AudioMessageBean howl = new AudioMessageBean(WerewolfModelConst.TEXT_HOWL);
        responses.add(howl);
        responses.add(new AudioMessageBean(WerewolfModelConst.TEXT_MOON_PHASE, "{{"+WerewolfModelConst.TEXT_PHASE+"#"+phase+"}}"));
        responses.add(new AudioMessageBean(WerewolfModelConst.TEXT_SPACER));
        responses.add(new AudioMessageBean(WerewolfModelConst.TEXT_GOOD_HUNTING, new AudioMessageBean(WerewolfModelConst.TEXT_THREAT)));
        responses.add(new AudioMessageBean(WerewolfModelConst.TEXT_SPACER));
        responses.add(new AudioMessageBean(WerewolfModelConst.TEXT_TRIVIA));
        responses.add(new AudioMessageBean(WerewolfModelConst.TEXT_SPACER));
        responses.add(new AudioMessageBean(WerewolfModelConst.TEXT_SONG_OF_THE_DAY, new AudioMessageBean(WerewolfModelConst.TEXT_SONGS)));
        state.respond(responses);
        state.endSession();
    }

    public static void handleHelp(WerewolfState state)
    {
        state.respond(WerewolfModelConst.TEXT_HELP);
        state.endSession();
    }

    public void handleDefault(WerewolfState state, IntentReqBean intent)
    {
        state.respond(WerewolfModelConst.TEXT_WTF);
        state.endSession();
    }
}

Credits

SMAC

SMAC

0 projects • 0 followers
Jo Jaquinta

Jo Jaquinta

1 project • 3 followers
Entrepreneurial Alexa developer. Amongst other things.

Comments