All Projects → markozajc → Akiwrapper

markozajc / Akiwrapper

Licence: GPL-3.0 license
A Java REST API wrapper for Akinator

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Akiwrapper

Coronavirus
Java API Wrapper for tracking coronavirus (COVID-19, SARS-CoV-2) via https://git.io/Jvoep
Stars: ✭ 16 (-42.86%)
Mutual labels:  java-api-wrapper

Akiwrapper Maven central emblem

Akiwrapper is a Java API wrapper for Akinator, the popular online 20Q-type game.

Installation

Maven

Add the following dependency to your pom.xml:

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

Gradle

Add the following dependency to your build.gradle:

implementation group: 'com.github.markozajc', name: 'akiwrapper', version: '1.5.2'

Usage

To access the Akinator API, you'll need an Akiwrapper object. One can be created like so:

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

If you, for example, wish to use a different language that the default English, or if you wish Akinator to guess something other than characters, you may use the following setup:

Akiwrapper aw = new AkiwrapperBuilder()
	.setLanguage(Language.GERMAN)
	.setGuessType(GuessType.PLACE)
	.build();

(keep in mind that not all language-guesstype combinations are supported, though all languages support CHARACTER)

You'll likely want to set up a question-answer loop afterwards. Fetch questions with

Question question = aw.getQuestion();

Display the question to the user, collect their answer, and feed it to Akinator with

aw.answer(Answer.YES);

If the player wishes to undo their previous answer, you can let Akinator know with

aw.undoAnswer();

Akinator will propose a list of guesses after each answer, coupled with their determined probabilities. You can get all guesses above a certain probability with

aw.getGuessesAboveProbability(0.85f); // 85% seems to be the sweet spot, though you're free to use anything you want

Let the player review each guess, but keep track of the declined ones, as Akinator will send you the same guesses over and over if he feels like it.

At some point Akinator will run out of questions to ask. This is indicated by aw.getCurrentQuestion() equalling null. If and when this happens, fetch and propose all remaining guesses (this time without a probability filter) with

aw.getGuesses()

and propose each one to the player. This also marks the absolute end of the game.

Unless you provide your own UnirestInstance to AkiwrapperBuilder, you should make sure to shut down the singleton instance that Akiwrapper uses by default after you're done with Akiwrapper:

UnirestUtils.shutdownInstance();

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

Available on:

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].