Previously on Dr. Lambda's blog:
In a previous post I presented my newest pet project: Isabella. Isabella is a voice controlled personal assistant, like Siri, Alexa, and others. We have decided to investigate how difficult it is to make such a program. In the last post we explained our reasoning for adding feelings or moods to Isabella.
Now, the continuation...
Games
Now that Isabella have feelings, it makes sense to think about it a bit. What happens if she gets in a bad mood? How can you make her happy again? How do people make each other happy?
Obviously we cant give her a gift, or a hug. Although now that I'm thinking about it, it is not a bad business idea, making an Isabella gift shop, where you can buy virtual gifts for her, to improve her mood. Especially – let's be honest – she is just a fancy, useful tamagotchi.
Another way we humans improve our moods, is by playing games. This we can do with Isabella, and then give a boost to her mood. But which games can she play? The easy answer is: pretty much every game you can play while driving. The first one I thought of was "20 questions", and the easiest I could think of was: guess a number. So let's look at both in turn.
Guess a number
Guess a number is a very simple game, where one player thinks of a number between 0-100, and then the other player has to guess it, using as few guesses as possible.
The cool thing is that this game is exactly what you would expect a computer to like, based on popular preconceptions.
This game was really easy to implement (both ways), using our follow-up system. When she is thinking of the number, you just compare the input with the number and say higher, or lower. When you thinking of the number, she just uses binary search – like any good computer.
Akinator
20 questions is quite a bit more complex. But luckily, like so many times, somebody has already made a brilliant game called Akinator which is exactly what I want. Even more lucky: it has an API. Unfortunately, the API has no documentation. The closest was a couple of projects on github which tried to use it as well.
Unfortunately their code was not quite what I was looking for, so I, instead, made my own, very thin layer on top of the API. Maybe it will be useful for someone else, so here it is:
type StepInformation = { question: string, answers: { answer: string }[], step: string, progression: string, questionid: string, infogain: string } type AnswerResponse = { identification: { channel: number, session: string, signature: string }, step_information: StepInformation } type CharacterResponse = { elements: { element: { id: string, name: string, id_base: string, proba: string, description: string, valide_contrainte: string, ranking: string, minibase_addable: string, relative_id: string, pseudo: string, picture_path: string, absolute_picture_path: string } }[], NbObjetsPertinents: string }
class RawApinator { private session: string; private signature: string; private step = 0; constructor() { } hello() { return new Promise<AnswerResponse>((resolve, reject) => { $.ajax({ url: 'http://api-us3.akinator.com/ws/new_session?partner=1&player=maxipaxi', dataType: "jsonp", error: reject, success: (data: { completion: string, parameters: AnswerResponse }) => { this.session = data.parameters.identification.session; this.signature = data.parameters.identification.signature; this.step = 0; resolve(data.parameters); } }); }); } sendAnswer(answerId: number) { return new Promise<StepInformation>((resolve, reject) => { $.ajax({ url: 'http://api-us3.akinator.com/ws/answer?session=' + this.session + '&signature=' + this.signature + '&step=' + this.step + '&answer=' + answerId, dataType: "jsonp", error: reject, success: (data: { completion: string, parameters: StepInformation }) => { this.step++; resolve(data.parameters); } }); }); } getCharacters() { return new Promise<CharacterResponse>((resolve, reject) => { $.ajax({ url: 'http://api-us3.akinator.com/ws/list?session=' + this.session + '&signature=' + this.signature + '&step=' + this.step + '&size=2&max_pic_width=246&max_pic_height=294&pref_photos=OK-FR&mode_question=0', dataType: "jsonp", error: reject, success: (data: { completion: string, parameters: CharacterResponse }) => { this.step++; resolve(data.parameters); } }); }); } }
Here is a short video of us playing a game.
No comments:
Post a Comment