Castagne is a fighting game between 2 players with random management of hitting points.
A player has 3 characteristics, strength, speed and robustness for which he has awarded points.
When the fight begins, the characteristics of the 2 players are added together determining the min and max. The random number is generated in this range. If the number is within player 1's point range, he wins, otherwise player 2 wins.
The match is played in 3 rounds, the winner is the one who wins at least 2 rounds.
The winner receives 100 XP points. Every 10 matches, players receive 10 XP points regardless of their result.
XP points can be used to modify characteristics.
Characteristic | player 1 | player 2 | Min | Max |
---|---|---|---|---|
Strengh | 250 | 350 | 0 | 250 + 350 = 600 |
Random for strengh
Random number | Player 1 | Player 2 |
---|---|---|
127 | Winner | |
251 | Winner |
-
Node v18.18.0 or higher
-
Rust v1.77.2 or higher
-
Anchor CLI 0.30.0 or higher
-
Solana CLI 1.18.9 or higher
git clone https://github.com/wi2/castagne
cd castagne
Anchor program
cd castagne
npm install
Web app
cd ../web
npm install
Select the environment you want to deploy to.
- mainnet
- devnet
- testnet
- localnet
Start the localnet
# If you want to start from scrach
solana-test-validator --reset
# If you want to continue with previous data
solana-test-validator
# To fund your account
solana airdrop 100
# Show your account
solana account <publicKey>
# or
solana account ~/.config/solana/<file>.json
# path castagne/castagne
anchor build
anchor keys list
If the program id is different from the one set inside lib.rs
replace the program id by the new one.
path castagne/castagne/programs/castagne-backend/src
file lib.rs
declare_id!("<new program id>");
path castagne/castagne
file anchor.toml
[programs.localnet]
castagne = "C7nwDHYxYX2BtKEubo2rc4LScApEekWUtCkNc8YWBSYw"
[programs.devnet]
castagne = "C7nwDHYxYX2BtKEubo2rc4LScApEekWUtCkNc8YWBSYw"
This build takes into account updating files with the program id
Then synchronize IDL and with web app
This script will copy castagne/target/idl
and castagne/target/types
directories to web/web/context
anchor build && anchor run sync
After having updated files, you have to build and deploy
# path castagne/castagne
anchor deploy
- Export your private key from your wallet and save it to a file (in a safe location❗️)
- Execute
decodeKeypair.ts
to decode and save your private key to a json file (in a safe location❗️)
# Where:
# ~/.config/solana/devnet-keypair-act1-raw is the private key exported from your wallet
# ~/.config/solana/devnet-keypair-act1.json is the private key decoded
# path castagne/web
npm run decode-keypair ~/.config/solana/devnet-keypair-act1-raw ~/.config/solana/devnet-keypair-act1.json
# path castagne/castagne
anchor deploy --provider.cluster devnet --provider.wallet ~/.config/solana/devnet-keypair-act1.json
Run unit test locally with the solana-test-validator
stopped
anchor test
Run unit tests locally with the solana-test-validator
running
anchor run test
- Create and update players
- Read players
- init-fight-cfg
- sync (sync IDL and types from program to web app)
# localnet
anchor run init-config
anchor run init-fight-config
anchor run create-player
anchor run read-player
anchor run sync
# devnet
anchor run init-fight-config \
--provider.wallet ~/.config/solana/devnet-keypair-act1.json \
--provider.cluster devnet
Script are set in the Anchor.toml file
[scripts]
test = "yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/castagne/*.ts"
init-config = "ts-node scripts/init_config.ts"
init-fight-config = "ts-node scripts/init_fight.ts"
create-player = "ts-node scripts/create_players.ts"
read-player = "ts-node scripts/read_players.ts"
sync = "cp -r target/idl/ ../web/web/context/idl && cp -r target/types/ ../web/web/context/types"
npm run dev
# or
npm run build && npm run start