Crate saptest

Source
Expand description

A testing framework for the game Super Auto Pets.

Game information is scraped and parsed from the Super Auto Pets Wiki before being stored in a SQLite database.

§Teams

Build a Team and simulate battles between them.

Then visualize the results in .dot format!

use saptest::{
   Pet, PetName, Food, FoodName,
   Team, TeamCombat, Position, create_battle_digraph
};

// Create a team.
let mut team = Team::new(
   &vec![Some(Pet::try_from(PetName::Ant).unwrap()); 5],
   5
).unwrap();
let mut enemy_team = team.clone();

// Set a seed for a team.
team.set_seed(Some(25));

// Give food to pets.
team.set_item(&Position::First, Food::try_from(FoodName::Garlic).ok());
enemy_team.set_item(&Position::First, Food::try_from(FoodName::Garlic).ok());

// And fight!
team.fight(&mut enemy_team).unwrap();

// Create a graph of the fight.
println!("{}", create_battle_digraph(&team, false));
digraph {
    rankdir=LR
    node [shape=box, style="rounded, filled", fontname="Arial"]
    edge [fontname="Arial"]
    0 [ label = "Ant_0 - The Fragile Truckers_copy" ]
    1 [ label = "Ant_0 - The Fragile Truckers", fillcolor = "yellow" ]
    2 [ label = "Ant_3 - The Fragile Truckers", fillcolor = "yellow" ]
    3 [ label = "Ant_4 - The Fragile Truckers_copy" ]
    0 -> 1 [ label = "(Attack, Damage (0, 2), Phase: 1)" ]
    1 -> 0 [ label = "(Attack, Damage (0, 2), Phase: 1)" ]
    1 -> 2 [ label = "(Faint, Add (1, 1), Phase: 1)" ]
    0 -> 3 [ label = "(Faint, Add (1, 1), Phase: 1)" ]
}

§Shops

Add shop functionality to a Team and roll, freeze, buy/sell pets and foods.

use saptest::{
    Entity, EntityName, Pet, PetName, Food, FoodName,
    Shop, ShopItem, TeamShopping,
    Team, TeamViewer, Position,
    db::pack::Pack
};

// All teams are constructed with a shop at tier 1.
let mut team = Team::new(
    &vec![Some(Pet::try_from(PetName::Ant).unwrap()); 4],
    5
).unwrap();

// All shop functionality is supported.
team.set_shop_seed(Some(1212))
    .set_shop_packs(&[Pack::Turtle])
    .open_shop().unwrap()
    .buy(
        &Position::First, // From first.
        &Entity::Pet, // Pet
        &Position::First // To first position, merging if possible.
    ).unwrap()
    .sell(&Position::First).unwrap()
    .move_pets(
        &Position::First, // From first pet
        &Position::Relative(-2), // To 2nd pet behind.
        true // And merge them if possible.
    ).unwrap()
    .freeze_shop(&Position::Last, &Entity::Pet).unwrap()
    .roll_shop().unwrap()
    .close_shop().unwrap();

// Shops can be built separately and can replace a team's shop.
let mut tier_5_shop = Shop::new(3, Some(42)).unwrap();
let weakness = ShopItem::new(
    Food::try_from(FoodName::Weak).unwrap()
);
tier_5_shop.add_item(weakness).unwrap();
team.replace_shop(tier_5_shop).unwrap();

§Pets

Build custom Pets and Effects.

use saptest::{
    Pet, PetName, PetCombat,
    Food, FoodName,
    Position, Effect, Statistics,
    effects::{
        trigger::TRIGGER_START_BATTLE,
        actions::GainType,
        state::Target,
        actions::Action
    }
};

// Create known pets.
let mut pet = Pet::try_from(PetName::Ant).unwrap();

// A custom pet and effect.
let custom_effect = Effect::new(
    TRIGGER_START_BATTLE, // Effect trigger
    Target::Friend, // Target
    Position::Adjacent, // Positions
    Action::Gain(GainType::DefaultItem(FoodName::Melon)), // Action
    Some(1), // Number of uses.
    false, // Is temporary.
);
let mut custom_pet = Pet::custom(
    "MelonBear",
    Statistics::new(50, 50).unwrap(),
    &[custom_effect],
);
// Fight two pets individually as well.
// Note: Effects don't activate here.
pet.attack(&mut custom_pet);

§Logging

Enable logging with a crate like simple_logger.

§Config

To configure the global SapDB’s startup, create a .saptest.toml file in the root of your project.

  • Specify page version for pets, foods, and tokens to query.
  • Toggle recurring updates on startup.
  • Set database filename.

Read more under the db module.

Modules§

db
SQLite SapDB database of game information.
effects
Effects in Super Auto Pets
error
Error types.
foods
Food effects and names.
pets
Pet names and logic.
shop
Shops logic for Super Auto Pet Teams.
teams
Team battle and effect logic.
toys
Super Auto Pets Toys.
visualization
Visualize Team battles/orders.

Structs§

Effect
An effect for an Entity in Super Auto Pets.
Food
A Super Auto Pets food.
Pet
A Super Auto Pet.
SAPQuery
Query constructor for SapDB::execute_query.
SapDB
A Super Auto Pets database.
Shop
A Super Auto Pets shop.
ShopItem
A Shop item.
Statistics
Statistics for a Pet or an Action.
Team
A Super Auto Pets team.
Toy
A Super Auto Pets toy.

Enums§

Entity
A Super Auto Pets entity.
EntityName
Entity names.
FoodName
Names for Foods
ItemCondition
Conditions to select Pets or ShopItem by.
PetName
Names for Pets.
Position
Positions to select pets by.
ToyName

Traits§

PetCombat
Implements combat mechanics for a single Pet.
ShopItemViewer
View attributes of a single ShopItem.
ShopViewer
Enables viewing ShopItems and their state.
TeamCombat
Enables combat between two Teams.
TeamEffects
Enable applying Effects to multiple Teams.
TeamShopping
Implements Super Auto Pets Shop behavior.
TeamViewer
Methods for viewing Teams.

Functions§

create_battle_df
Creates a dataframe string representing each step in a battle as a tab-separated row.
create_battle_digraph
Generate Team’s battle history as a directed graph.