From 7f5e30ac82f2a2d7579e361229a4044348915867 Mon Sep 17 00:00:00 2001 From: louistiti Date: Mon, 9 May 2022 21:47:35 +0800 Subject: [PATCH] feat(skill/rochambeau): init --- core/skills-endpoints.json | 25 ++++-- skills/games/guess_the_number/nlu/en.json | 33 +------- .../guess_the_number/src/actions/setup.py | 5 +- skills/games/rochambeau/README.md | 0 skills/games/rochambeau/memory/.gitkeep | 0 skills/games/rochambeau/nlu/en.json | 76 +++++++++++++++++++ skills/games/rochambeau/skill.json | 11 +++ skills/games/rochambeau/src/actions/play.py | 52 +++++++++++++ .../games/rochambeau/src/actions/rematch.py | 24 ++++++ skills/games/rochambeau/src/actions/setup.py | 13 ++++ .../games/rochambeau/src/config.sample.json | 6 ++ skills/games/rochambeau/src/lib/.gitkeep | 0 skills/games/rochambeau/test/.gitkeep | 0 13 files changed, 206 insertions(+), 39 deletions(-) create mode 100644 skills/games/rochambeau/README.md create mode 100644 skills/games/rochambeau/memory/.gitkeep create mode 100644 skills/games/rochambeau/nlu/en.json create mode 100644 skills/games/rochambeau/skill.json create mode 100644 skills/games/rochambeau/src/actions/play.py create mode 100644 skills/games/rochambeau/src/actions/rematch.py create mode 100644 skills/games/rochambeau/src/actions/setup.py create mode 100644 skills/games/rochambeau/src/config.sample.json create mode 100644 skills/games/rochambeau/src/lib/.gitkeep create mode 100644 skills/games/rochambeau/test/.gitkeep diff --git a/core/skills-endpoints.json b/core/skills-endpoints.json index 9766771b..97a247d6 100644 --- a/core/skills-endpoints.json +++ b/core/skills-endpoints.json @@ -1,10 +1,5 @@ { "endpoints": [ - { - "method": "GET", - "route": "/api/action/games/guess_the_number/start", - "params": [] - }, { "method": "GET", "route": "/api/action/games/guess_the_number/setup", @@ -20,6 +15,26 @@ "route": "/api/action/games/guess_the_number/replay", "params": [] }, + { + "method": "GET", + "route": "/api/action/games/rochambeau/start", + "params": [] + }, + { + "method": "GET", + "route": "/api/action/games/rochambeau/setup", + "params": [] + }, + { + "method": "GET", + "route": "/api/action/games/rochambeau/play", + "params": [] + }, + { + "method": "GET", + "route": "/api/action/games/rochambeau/rematch", + "params": [] + }, { "method": "GET", "route": "/api/action/leon/birthday/leon_birthday", diff --git a/skills/games/guess_the_number/nlu/en.json b/skills/games/guess_the_number/nlu/en.json index 803d546a..b8991e01 100644 --- a/skills/games/guess_the_number/nlu/en.json +++ b/skills/games/guess_the_number/nlu/en.json @@ -1,40 +1,13 @@ { "actions": { - "start": { - "type": "dialog", + "setup": { + "type": "logic", "utterance_samples": [ "Let's play guess the number", "I wanna play guess the number", "Can we play guess the number?", "I want to play a game like guess the number" ], - "slots": [ - { - "name": "players_nb", - "item": { - "type": "entity", - "name": "number" - }, - "questions": [ - "How many players should I set?", - "Sure, how many players should I prepare?" - ] - }, - { - "name": "email_test", - "item": { - "type": "entity", - "name": "email" - }, - "questions": [ - "How about the email?" - ] - } - ], - "next_action": "setup" - }, - "setup": { - "type": "logic", "next_action": "guess" }, "guess": { @@ -63,7 +36,7 @@ }, "answers": { "ready": [ - "Alright, I have set %players_nb% players with the %email_test% email. Go ahead and guess the number between 0 and 100!" + "Alright, I'm ready! Go ahead and guess the number between 0 and 100!" ], "bigger": [ "The number is bigger.", diff --git a/skills/games/guess_the_number/src/actions/setup.py b/skills/games/guess_the_number/src/actions/setup.py index a7b0b10a..48819aa8 100644 --- a/skills/games/guess_the_number/src/actions/setup.py +++ b/skills/games/guess_the_number/src/actions/setup.py @@ -14,7 +14,4 @@ def setup(params): # TODO: save these values in DB # TODO: add output_context - return utils.output('end', 'ready', utils.translate('ready', { - 'players_nb': slots['players_nb']['value']['sourceText'], - 'email_test': slots['email_test']['value']['sourceText'] - })) + return utils.output('end', 'ready', utils.translate('ready')) diff --git a/skills/games/rochambeau/README.md b/skills/games/rochambeau/README.md new file mode 100644 index 00000000..e69de29b diff --git a/skills/games/rochambeau/memory/.gitkeep b/skills/games/rochambeau/memory/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/skills/games/rochambeau/nlu/en.json b/skills/games/rochambeau/nlu/en.json new file mode 100644 index 00000000..0a90f241 --- /dev/null +++ b/skills/games/rochambeau/nlu/en.json @@ -0,0 +1,76 @@ +{ + "actions": { + "start": { + "type": "dialog", + "utterance_samples": [ + "Let's play rochambeau", + "I wanna play rock paper scissors", + "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?" + ] + } + ], + "next_action": "setup" + }, + "setup": { + "type": "logic", + "next_action": "play" + }, + "play": { + "type": "logic", + "loop": { + "expected_items": [ + { + "type": "entity", + "name": "handsign" + } + ] + }, + "next_action": "rematch" + }, + "rematch": { + "type": "logic", + "loop": { + "expected_items": [ + { + "type": "resolver", + "name": "number" + } + ] + } + } + }, + "entities": { + "handsign": "entities/handsigns.json" + }, + "answers": { + "ready": [ + "Alright, let's get started!" + ], + "equal": [ + "No point." + ], + "point": [ + "The %handsign_1% beats the %handsign_2%." + ], + "win": [ + "I won! Would you like a rematch?" + ], + "lose": [ + "You're good at it! Can I get a rematch?", + "Congrats! Should we go for a rematch?" + ] + } +} diff --git a/skills/games/rochambeau/skill.json b/skills/games/rochambeau/skill.json new file mode 100644 index 00000000..d747f275 --- /dev/null +++ b/skills/games/rochambeau/skill.json @@ -0,0 +1,11 @@ +{ + "name": "Rochambeau", + "bridge": "python", + "version": "1.0.0", + "description": "Rock paper scissors game.", + "author": { + "name": "Louis Grenard", + "email": "louis.grenard@gmail.com", + "url": "https://github.com/louistiti" + } +} diff --git a/skills/games/rochambeau/src/actions/play.py b/skills/games/rochambeau/src/actions/play.py new file mode 100644 index 00000000..f1160680 --- /dev/null +++ b/skills/games/rochambeau/src/actions/play.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python +# -*- coding:utf-8 -*- + +import random +import utils + +def play(params): + """This is a test""" + + handsigns = { + 'ROCK': { + 'superior_to': 'scissors', + 'inferior_to': 'paper' + }, + 'PAPER': { + 'superior_to': 'rock', + 'inferior_to': 'scissors' + }, + 'SCISSORS': { + 'superior_to': 'paper', + 'inferior_to': 'rock' + } + } + entities = params['entities'] + rounds_nb = 3 # TODO: pickup from memory + player_handsign = None + leon_handsign = random.choice(list(handsigns)) + + # Find entities + for item in params['entities']: + if item['entity'] == 'handsign': + player_handsign = item['resolution']['value'] + + # Return no speech if no number has been found + if player_handsign == None: + return utils.output('end', None, None, { 'isInActionLoop': False }) + + if leon_handsign == player_handsign: + return utils.output('end', 'equal', utils.translate('equal')) + + # Point for Leon + if handsigns[leon_handsign]['superior_to'] == player_handsign: + # TODO: increment +1 for Leon + # TODO: remove print + print('...') + + # TODO: increment +1 for player + + return utils.output('end', 'equal', utils.translate('point', { + 'handsign_1': leon_handsign.lower(), + 'handsign_2': player_handsign.lower() + })) diff --git a/skills/games/rochambeau/src/actions/rematch.py b/skills/games/rochambeau/src/actions/rematch.py new file mode 100644 index 00000000..c56b0ae4 --- /dev/null +++ b/skills/games/rochambeau/src/actions/rematch.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python +# -*- coding:utf-8 -*- + +import utils + +def rematch(params): + """This is a test""" + + entities, slots = params['entities'], params['slots'] + decision = 0 + + # Find entities + # TODO: replace with confirmation resolver + for item in params['entities']: + if item['entity'] == 'number': + decision = item['resolution']['value'] + + if decision == 1: + return utils.output('end', 'replay', 'Let\'s goooo', { + 'isInActionLoop': False, + 'restart': True + }) + + return utils.output('end', 'quit', 'As you wish', { 'isInActionLoop': False }) diff --git a/skills/games/rochambeau/src/actions/setup.py b/skills/games/rochambeau/src/actions/setup.py new file mode 100644 index 00000000..7bcd1218 --- /dev/null +++ b/skills/games/rochambeau/src/actions/setup.py @@ -0,0 +1,13 @@ +#!/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', utils.translate('ready')) diff --git a/skills/games/rochambeau/src/config.sample.json b/skills/games/rochambeau/src/config.sample.json new file mode 100644 index 00000000..9e43d47e --- /dev/null +++ b/skills/games/rochambeau/src/config.sample.json @@ -0,0 +1,6 @@ +{ + "configurations": { + "options": {}, + "credentials": {} + } +} diff --git a/skills/games/rochambeau/src/lib/.gitkeep b/skills/games/rochambeau/src/lib/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/skills/games/rochambeau/test/.gitkeep b/skills/games/rochambeau/test/.gitkeep new file mode 100644 index 00000000..e69de29b