> For the complete documentation index, see [llms.txt](https://impulse-dao.gitbook.io/impulse-dao/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://impulse-dao.gitbook.io/impulse-dao/games-for-developers/arena/vara-arena/creating-an-algorithm.md).

# Creating an algorithm

It's essential to create a unique battling strategy for your gladiator.

### Using gtest before uploading code onchain&#x20;

1. git clone <https://github.com/ImpulseDAO/Vara-Arena.git>
2. run `cargo build --release` in vara-arena/contracts directory
   1. find .wasm examples from character / mage / berserk templates in vara-arena/target/wasm32-unknown-unknown/release/
3. run `cargo test` (for all tests) in /contracts/arena directory or only character algorithm test -\
   `cargo test --package arena --test tests -- game --exact --nocapture`   &#x20;
4. make changes to existing templates or create you custom code within lib.rs
5. customise /arena/tests/tests.rs to upload your custom code&#x20;

### Creating an algorithm

Create a strategy using `gstd` ([gear standard library](https://docs.gear.rs/gstd/)), compile, and upload your .wasm strategy file as a smart-contract onchain.

Find strategy examples in the Arena repository:

* [Berserk](https://github.com/tmcgroul/AArena/tree/master/contracts/berserk/src)
* [Quick attacker](https://github.com/tmcgroul/AArena/tree/master/contracts/character)
* [Mage](https://github.com/ImpulseDAO/Vara-Arena/tree/master/contracts/mage)

**Please note that each player (wallet) can own only one gladiator.**&#x20;

### In-game actions

Algorithms fight on 1D map by exchanging message onchain.&#x20;

```
AttackKind { 
Quick, 
Normal, 
Hard, 
}

Spell {
    FireWall,
    EarthSkin,
    WaterRestoration,
    Fireball,
    WaterBurst,
    FireHaste,
    EarthSmites,
    ChillingTouch,
}

BattleAction {
    Attack { kind: AttackKind },
    MoveRight,
    MoveLeft,
    Rest,
    Parry,
    Guardbreak,
    CastSpell { spell: Spell },
}
```

### Battle Map

The initial distance between characters is ten cells.

Total arena map range = 0..15 cells, ie 16. \
Plater 1 starts at 6, and Player 2 starts at 10.

### TODO :: Use GPT Agent&#x20;

### Upload strategy as code

Pre-requirements: [#using-gtest-before-uploading-code-onchain](#using-gtest-before-uploading-code-onchain "mention")

1. Go to [Arena dApp](https://impulsedao.github.io/AArena/#)&#x20;
2. Connect Substrate wallet, and click [Create New Gladiator](https://impulsedao.github.io/AArena/#/mint-character)
3. Click on the Default strategy dropdown field and click Upload code

![](https://2137704913-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGlx7OS0CbxFdf0AxltHI%2Fuploads%2FjDEuWYXQsb2CIW38HOLZ%2FScreenshot%202023-08-09%20at%2015.07.41.png?alt=media\&token=c83bf4b8-6cd7-4090-a588-d8b15be1a57d)

4. Use your `Code id` for creating a character

![](https://2137704913-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGlx7OS0CbxFdf0AxltHI%2Fuploads%2F4NTxe1m7b36s5AgLBc7h%2FScreenshot%202023-08-09%20at%2015.09.25.png?alt=media\&token=4158c38f-87d5-4fd1-abbb-e657dee6e094)

5. Choose your initial character attributes and proceed by clicking `Mint character`

**Please note that each player (wallet) can own only one gladiator.**&#x20;
