/hoplite

An attempt at making a basic AI for the Hoplite Android game.

Primary LanguagePython

Hoplite Icon Hoplite

An attempt at making a basic AI for the Hoplite Android game.

Preamble

Hoplite is a popular turn-based strategy Android game developed by Magma Fortress, originally created in 2013. Try it (there is a free and a premium version), you will love it!

This modules provides an interface for automatically playing the game on an Android simulator or even live on a device. Screen is captured and analyzed for the program to get a logical representation of the game. Then, like most chess engines, possible moves are explored and evaluated by pondering some relevant features. The best one is picked, and played.

Here is a demonstration of it working on a emulator.

This is a first draft, meaning many components are missing or poorly implemented. See the roadmap for details.

Hoplite Android Icon

Getting Started

Prerequisites

You will need Python 3 and Android Studio for adb.

adb allows for remotely controlling the Android device (either a real phone plugged into the computer via USB with 'USB debugging' enabled, or an emulated phone created with AVD).

Installation

  1. Clone the repository

     git clone https://github.com/ychalier/hoplite.git
    
  2. Install the dependencies

     cd hoplite/
     pip install -r requirements.txt
    

Usage

  1. Either start the emulated phone in AVD or plug in your phone, and open the Hoplite app.

  2. Find out adb device serial using:

     adb devices
    
  3. Start the script with:

     python main.py -serial <adb_device_serial> play 
    

Use python main.py --help for more details.

Roadmap

There is a lot to do, so feel free to contribute!

  • Implement basic interaction with the game
  • Implement a basic game engine
  • Implement a basic decision making system
  • Make the MonkeyRunner interface more reliable
  • ~~Replace the MonkeyRunner with python-pure-adb
  • Enhance the game re-implementation:
    • Develop a game explorer to build a database of state sequences for further analysis
    • Complete and implement the game rules
      • Prayers
      • Energy restoration
      • Knockback, collisions
      • Killing spree (Surge and Regeneration prayers)
      • Demons movements
        • Footman movement
        • Archer and Wizard movement
        • Demolitionist movement and throw
      • Cooldowns
        • Bash cooldown
        • Wizard cooldown
        • Demolitionist cooldown
      • Demons status
        • Stunned
        • Sleeping
        • Shield
    • Allow for menus recognition (title screen and altars) and answering
    • Implement memory for GameState to allow prayers handling
  • Fasten Observer by using fine-tuned template recognition model
  • Enhance the AI part:
    • Fine-tune player's incentives between killing all enemies, go to the next level, and pray at the altar
    • Implement a proper training of the game state evaluation
    • Implement a proper exploration of variations starting from a position, like chess engines
  • Explore support for device with resolution different from 1080*1920
  • Many more things that I am not thinking of right now...

Contributing

Open pull requests or issues if you have any proposition to make. Check the roadmap for ideas (there are many), and the documentation for how to implement them. I put some screenshots here (2MB) helping development, and the templates (1MB) used for the classifiers.

If you implement some features, please make sure your code is clean enough (for this matter I use the Pylint linter) and documented enough (add docstrings with short descriptions, types of arguments and returned values). I use pdoc to generate the documentation.