Code Monkey home page Code Monkey logo

akiwrapper's Introduction

travis central

Akiwrapper

Akiwrapper is a fully-documented and easy-to-use Java API wrapper for Akinator.

Installation

Maven

Put this: into your pom.xml (replace LATEST_VERSION with central:

<dependency>
	<groupId>com.github.markozajc</groupId>
	<artifactId>akiwrapper</artifactId>
	<version>LATEST_VERSION</version>
</dependency>

You can find an example POM here.

Usage

It's really easy to get started with Akiwrapper. First off, we'll need to create a new Akinator API session:

Akiwrapper aw = new AkiwrapperBuilder().build();

Now, it's time to retrieve Akinator's first question:

Question q = aw.getCurrentQuestion();

Let's answer it with "YES":

aw.answerCurrentQuestion(Answer.YES);

This will also return the next question


After repeating this process for some time (with different answers, of course), the probability of Akinator's guesses will rise to the point where it's almost certain (usually 85% is enough). You can check if there are any guesses with that probability & retrieve them with

for (Guess guess : aw.getGuessesAboveProbability(0.85 /* you can specify your threshold between 0 and 1 */)) {
	// Do something with those guesses
}

There is a high chance Akinator will get at least one guess one but let's imagine the user has rejected all guesses. In this case, Akinator will run out of questions after a certain amount of answered questions. We need to watch out for this:

if (aw.answerCurrentQuestion(someAnswer) == null || aw.getCurrentQuestion() == null) {
	// Watch out! Akinator has ran out of questions! 
	// In this case,
	// - Akiwrapper#answerCurrentQuestion() will not throw an exception but rather return null no matter what
	// - Akiwrapper#getCurrentQuestion() will also keep returning null
}

If this happens, the best way to handle it is to let user see all guesses (no matter their probability) with iterating over aw.getGuesses() and asking user if this is their character on each. If they reject them all, make them feel good by telling them that they have finally defeated Akinator.


That's it! If you need more help, be sure to check an example here for an out-of-the-box working example.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.