Coder Social home page Coder Social logo

hjk-z / sapai-helper-old Goto Github PK

View Code? Open in Web Editor NEW

This project forked from codereclaimers/neat-python

0.0 0.0 0.0 5.83 MB

Python implementation of the NEAT neuroevolution algorithm, modified for Super Auto Pets AI

License: MIT License

Python 100.00%

sapai-helper-old's Introduction

sapai

license test-status coverage

sapai is a Super Auto Pets engine built with reinforcement learning training and other related AI models in mind. You may see more of my published work in machine learning on ResearchGate or ACS.

You may see and use sapai examples easily through Google Colab

doc/static/workflow.png

To start installing and using sapai, it's highly recommended to start from an Anaconda distribution of Python, which can be downloaded for free here.

Then download the library from Github. A zip file can be downloaded using the green download code button. Alternatively, this repository can be obtained using the following command from the command-line.

git clone https://github.com/manny405/sapai.git

After navigating to the sapai directory, installation is completed with the following command.

python setup.py install

Unit tests are located in the tests directory. Tests can be run with the following command

python -m unittest discover -s tests

The following code exampes will be run through the Python shell. To start a Python shell session, open up your preferred command-line program, such as Terminal or Powershell, then type and enter python.

>>> from sapai.pets import Pet
>>> pet = Pet("ant")
>>> print(pet)
### Printing pet is given in the form of < PetName Attack-Health Status Level-Exp >
< pet-ant 2-1 none 1-0 >
>>> pet._attack += 3
>>> pet.gain_experience()
>>> print(pet)
< pet-ant 5-1 none 1-1 >
>>> print(pet.ability)
### Organization of pet abilities provided by super-auto-pets-db project
{'description': 'Faint: Give a random friend +2/+1',
 'trigger': 'Faint',
 'triggeredBy': {'kind': 'Self'},
 'effect': {'kind': 'ModifyStats',
  'attackAmount': 2,
  'healthAmount': 1,
  'target': {'kind': 'RandomFriend', 'n': 1},
  'untilEndOfBattle': False}}
 >>> from sapai.pets import Pet
 >>> from sapai.teams import Team
 >>> team0 = Team(["ant","ox","tiger"])
 >>> team1 = Team(["sheep","tiger"])
 >>> print(team0)
 0: < Slot pet-ant 2-1 none 1-0 >
   1: < Slot pet-ox 1-4 none 1-0 >
   2: < Slot pet-tiger 4-3 none 1-0 >
   3: < Slot EMPTY >
   4: < Slot EMPTY >
>>> print(team1)
0: < Slot pet-sheep 2-2 none 1-0 >
   1: < Slot pet-tiger 4-3 none 1-0 >
   2: < Slot EMPTY >
   3: < Slot EMPTY >
   4: < Slot EMPTY >
>>> team0.move(1,4)
>>> print(team0)
0: < Slot pet-ant 2-1 none 1-0 >
   1: < Slot EMPTY >
   2: < Slot pet-tiger 4-3 none 1-0 >
   3: < Slot EMPTY >
   4: < Slot pet-ox 1-4 none 1-0 >
>>> team0.move_forward()
>>> print(team0)
0: < Slot pet-ant 2-1 none 1-0 >
   1: < Slot pet-tiger 4-3 none 1-0 >
   2: < Slot pet-ox 1-4 none 1-0 >
   3: < Slot EMPTY >
   4: < Slot EMPTY >
### Using the teams created in the last section
>>> from sapai.battle import Battle
>>> battle = Battle(team0,team1)
>>> winner = battle.battle()
>>> print(winner)
2
### Possible fight outputs:
### 0 = Team0 Wins
### 1 = Team1 Wins
### 2 = Draw

The implementation of battle is efficient. Using IPython magic, this can be tested using the following IPython method:

from sapai.pets import Pet
from sapai.teams import Team
from sapai.battle import Battle
team0 = Team(["ant","ox","tiger"])
team1 = Team(["sheep","tiger"])

def timing_test():
    b = Battle(team0,team1)
    winner = b.battle()

%timeit timing_test()
### On 2019 Macbook Pro:
###   8.12 ms ± 450 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)
###   More than 100 battle per second on a single core

### On Xeon Platinum 8124M @ 3.00GHz
###  6.06 ms ± 49.1 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)
###  More than 150 battle per second on a single core

### On 2021 MPB with M1 Pro Processor:
###  4.32 ms ± 20.8 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)
###  More than 230 battle per second on a single core

All battle history is stored for every phase, effect, and attack that occured during the battle. This battle history can be graphed and visualized. The full graph for the battle is shown below.

>>> from sapai.graph import graph_battle
>>> graph_battle(battle, file_name="Example")
doc/static/battle_graph_full.png

Ongoing

  1. See the issues page for ongoing discussions. The code-base is completely ready for the development of AI engines around SAP.

sapai-helper-old's People

Contributors

codereclaimers avatar drallensmith avatar bennr01 avatar hjk-x avatar alezonta avatar vaknin avatar gabriele-0201 avatar exowanderer avatar catap avatar quantifiedcode-bot avatar mathiasose avatar obadul024 avatar philippsc avatar shangtongzhang avatar mstechly avatar ai-nick avatar

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.