mirror of
https://github.com/leon-ai/leon.git
synced 2024-11-27 16:16:48 +03:00
feat(skill/rochambeau): introduce paper scissors rock
This commit is contained in:
parent
fba80966c9
commit
573704706c
@ -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",
|
||||
|
@ -225,6 +225,7 @@ class Nlu {
|
||||
return null
|
||||
}
|
||||
|
||||
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) {
|
||||
@ -249,6 +250,9 @@ class Nlu {
|
||||
}
|
||||
|
||||
return processedData
|
||||
} catch (e) /* istanbul ignore next */ {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -5,7 +5,7 @@ import utils
|
||||
# Skill database
|
||||
db = utils.db()['db']
|
||||
|
||||
# Owner table
|
||||
# Game table
|
||||
game_table = db.table('game')
|
||||
|
||||
# Time stamp
|
||||
|
@ -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": {
|
||||
@ -62,8 +27,8 @@
|
||||
"type": "logic",
|
||||
"loop": {
|
||||
"expected_item": {
|
||||
"type": "entity",
|
||||
"name": "number"
|
||||
"type": "resolver",
|
||||
"name": "affirmation_denial"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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%."
|
||||
],
|
||||
"win": [
|
||||
"I won! Would you like a rematch?"
|
||||
"ask_for_rematch": [
|
||||
"Do you want a rematch?",
|
||||
"Should we go for another round?"
|
||||
],
|
||||
"lose": [
|
||||
"You're good at it! Can I get a rematch?",
|
||||
"Congrats! Should we go for a rematch?"
|
||||
"confirm_rematch": [
|
||||
"Be ready!",
|
||||
"I'm not gonna let you win."
|
||||
],
|
||||
"deny_rematch": [
|
||||
"As you wish.",
|
||||
"Let me know anytime you want to play."
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -5,27 +5,26 @@ import random
|
||||
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
|
||||
@ -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',
|
||||
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 })
|
||||
|
@ -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 })
|
||||
|
@ -1,13 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding:utf-8 -*-
|
||||
|
||||
import utils
|
||||
|
||||
def setup(params):
|
||||
"""This is a test"""
|
||||
|
||||
entities, slots = params['entities'], params['slots']
|
||||
|
||||
# TODO: use rounds_nb slot and save it in DB
|
||||
|
||||
return utils.output('end', 'ready')
|
Loading…
Reference in New Issue
Block a user