Skip to content

Commit

Permalink
feat(skill/rochambeau): introduce paper scissors rock
Browse files Browse the repository at this point in the history
  • Loading branch information
louistiti committed Jun 19, 2022
1 parent fba8096 commit 5737047
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 123 deletions.
5 changes: 0 additions & 5 deletions core/skills-endpoints.json
Expand Up @@ -20,11 +20,6 @@
"route": "/api/action/games/rochambeau/start",
"params": []
},
{
"method": "GET",
"route": "/api/action/games/rochambeau/setup",
"params": []
},
{
"method": "GET",
"route": "/api/action/games/rochambeau/play",
Expand Down
44 changes: 24 additions & 20 deletions server/src/core/nlu.js
Expand Up @@ -225,30 +225,34 @@ class Nlu {
return null
}

const processedData = await this.brain.execute(this.nluResultObj, { mute: opts.mute })
// Reprocess with the original utterance that triggered the context at first
if (processedData.core?.restart === true) {
const { originalUtterance } = this.conv.activeContext
try {
const processedData = await this.brain.execute(this.nluResultObj, { mute: opts.mute })
// Reprocess with the original utterance that triggered the context at first
if (processedData.core?.restart === true) {
const { originalUtterance } = this.conv.activeContext

this.conv.cleanActiveContext()
await this.process(originalUtterance, opts)
return null
}
this.conv.cleanActiveContext()
await this.process(originalUtterance, opts)
return null
}

// In case there is no next action to prepare anymore
if (!processedData.action.next_action) {
this.conv.cleanActiveContext()
return null
}
// In case there is no next action to prepare anymore
if (!processedData.action.next_action) {
this.conv.cleanActiveContext()
return null
}

// Break the action loop and prepare for the next action if necessary
if (processedData.core?.isInActionLoop === false) {
this.conv.activeContext.isInActionLoop = !!processedData.action.loop
this.conv.activeContext.actionName = processedData.action.next_action
this.conv.activeContext.intent = `${processedData.classification.skill}.${processedData.action.next_action}`
}
// Break the action loop and prepare for the next action if necessary
if (processedData.core?.isInActionLoop === false) {
this.conv.activeContext.isInActionLoop = !!processedData.action.loop
this.conv.activeContext.actionName = processedData.action.next_action
this.conv.activeContext.intent = `${processedData.classification.skill}.${processedData.action.next_action}`
}

return processedData
return processedData
} catch (e) /* istanbul ignore next */ {
return null
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion skills/games/guess_the_number/src/lib/db.py
Expand Up @@ -5,7 +5,7 @@
# Skill database
db = utils.db()['db']

# Owner table
# Game table
game_table = db.table('game')

# Time stamp
Expand Down
74 changes: 24 additions & 50 deletions skills/games/rochambeau/nlu/en.json
Expand Up @@ -8,44 +8,9 @@
"Can we play paper rock scissors?",
"I want to play rochambeau"
],
"slots": [
{
"name": "rounds_nb",
"item": {
"type": "entity",
"name": "number"
},
"questions": [
"How many rounds would you like to play?",
"How many rounds should I set?",
"Sure, how many rounds should I prepare?"
]
},
{
"name": "testo_email",
"item": {
"type": "entity",
"name": "email"
},
"questions": [
"Testo?"
]
},
{
"name": "testo_nb",
"item": {
"type": "entity",
"name": "number"
},
"questions": [
"Testo2?"
]
}
"answers": [
"Alright, let's get started!"
],
"next_action": "setup"
},
"setup": {
"type": "logic",
"next_action": "play"
},
"play": {
Expand All @@ -62,8 +27,8 @@
"type": "logic",
"loop": {
"expected_item": {
"type": "entity",
"name": "number"
"type": "resolver",
"name": "affirmation_denial"
}
}
}
Expand All @@ -73,27 +38,36 @@
},
"answers": {
"ready": [
"Alright, let's get started!"
"Let's get started!"
],
"leon_emoji": [
"%leon_emoji%"
],
"equal": [
"No point."
"No point.",
"It's a tie."
],
"point_for_leon": [
"I got you. The %handsign_1% beats the %handsign_2%.",
"Yeaaah! The %handsign_1% beats the %handsign_2%.",
"Gotcha! The %handsign_1% beats the %handsign_2%."
"Yeaaah, I won! The %handsign_1% beats the %handsign_2%.",
"Gotcha! I got the point because the %handsign_1% beats the %handsign_2%."
],
"point_for_player": [
"You got me. The %handsign_1% beats the %handsign_2%.",
"Aargh no. The %handsign_1% beats the %handsign_2%.",
"Well played! The %handsign_1% beats the %handsign_2%."
"Aargh no, you got the point. The %handsign_1% beats the %handsign_2%.",
"Well played! You got the point because the %handsign_1% beats the %handsign_2%."
],
"ask_for_rematch": [
"Do you want a rematch?",
"Should we go for another round?"
],
"win": [
"I won! Would you like a rematch?"
"confirm_rematch": [
"Be ready!",
"I'm not gonna let you win."
],
"lose": [
"You're good at it! Can I get a rematch?",
"Congrats! Should we go for a rematch?"
"deny_rematch": [
"As you wish.",
"Let me know anytime you want to play."
]
}
}
49 changes: 26 additions & 23 deletions skills/games/rochambeau/src/actions/play.py
Expand Up @@ -5,27 +5,26 @@
import utils

def play(params):
"""This is a test"""
"""Define the winner"""

handsigns = {
'ROCK': {
'superior_to': 'SCISSORS',
'inferior_to': 'PAPER'
'inferior_to': 'PAPER',
'emoji': '✊'
},
'PAPER': {
'superior_to': 'ROCK',
'inferior_to': 'SCISSORS'
'inferior_to': 'SCISSORS',
'emoji': '✋'
},
'SCISSORS': {
'superior_to': 'PAPER',
'inferior_to': 'ROCK'
'inferior_to': 'ROCK',
'emoji': '✌'
}
}
entities, slots = params['entities'], params['slots']
# TODO: make resolution more simple. E.g. slots['rounds_nb']['strValue']. Same for entities
rounds_nb = str(slots['rounds_nb']['resolution']['value'])
testo_email = str(slots['testo_email']['resolution']['value'])
testo_nb = str(slots['testo_nb']['resolution']['value'])
entities = params['entities']
player = {
'handsign': None,
'points': 0
Expand All @@ -40,29 +39,33 @@ def play(params):
if entity['entity'] == 'handsign':
player['handsign'] = entity['option']

utils.output('inter', 'Just a test: ' + rounds_nb + ' + ' + testo_email + ' + ' + testo_nb)

# Exit the loop if no handsign has been found
if player['handsign'] == None:
return utils.output('end', None, None, { 'isInActionLoop': False })
utils.output('inter', None, None, { 'isInActionLoop': False })

leon_emoji = handsigns[leon['handsign']]['emoji']
player_emoji = handsigns[player['handsign']]['emoji']

utils.output('inter', { 'key': 'leon_emoji', 'data': { 'leon_emoji': leon_emoji } })

if leon['handsign'] == player['handsign']:
return utils.output('end', 'equal')
utils.output('inter', 'equal')

# Point for Leon
if handsigns[leon['handsign']]['superior_to'] == player['handsign']:
# TODO: increment +1 for Leon
return utils.output('end', { 'key': 'point_for_leon',
elif handsigns[leon['handsign']]['superior_to'] == player['handsign']:
utils.output('inter', { 'key': 'point_for_leon',
'data': {
'handsign_1': leon['handsign'].lower(),
'handsign_2': player['handsign'].lower()
}
})

# TODO: increment +1 for player
return utils.output('end', { 'key': 'point_for_player',
'data': {
'handsign_1': player['handsign'].lower(),
'handsign_2': leon['handsign'].lower()
}
})
else:
utils.output('inter', { 'key': 'point_for_player',
'data': {
'handsign_1': player['handsign'].lower(),
'handsign_2': leon['handsign'].lower()
}
})

return utils.output('end', 'ask_for_rematch', { 'isInActionLoop': False })
20 changes: 9 additions & 11 deletions skills/games/rochambeau/src/actions/rematch.py
Expand Up @@ -4,21 +4,19 @@
import utils

def rematch(params):
"""This is a test"""
"""Take decision whether to do a rematch"""

entities, slots = params['entities'], params['slots']
decision = 0
resolvers = params['resolvers']
decision = False

# Find entities
# TODO: replace with confirmation resolver
for item in params['entities']:
if item['entity'] == 'number':
decision = item['resolution']['value']
for resolver in resolvers:
if resolver['name'] == 'affirmation_denial':
decision = resolver['value']

if decision == 1:
return utils.output('end', 'Let\'s goooo', {
if decision == True:
return utils.output('end', 'confirm_rematch', {
'isInActionLoop': False,
'restart': True
})

return utils.output('end', 'As you wish', { 'isInActionLoop': False })
return utils.output('end', 'deny_rematch', { 'isInActionLoop': False })
13 changes: 0 additions & 13 deletions skills/games/rochambeau/src/actions/setup.py

This file was deleted.

0 comments on commit 5737047

Please sign in to comment.