Skip to content

Instantly share code, notes, and snippets.

@glihm
Last active April 11, 2023 14:31
Show Gist options
  • Save glihm/e83e6b56617660be475f56fb65ecfce1 to your computer and use it in GitHub Desktop.
Save glihm/e83e6b56617660be475f56fb65ecfce1 to your computer and use it in GitHub Desktop.
The battle of titans 2023

The battle of titans 2023

As a new dev in web3, here are some quick notes about 0xTitans 2023 challenge.

Setup for training:

Lot's of information are given in the official notion.

  1. Foundry installation Once foundry is installed, when running the test, the logs directory must be created to have a correct output running forge test. For this, cd to the root of the project, and run mkdir logs.

    Then all generated logs, including the full game gameLog.json, can be accessed.

  2. To run the gameLog.json file, the generated JSON must be escaped and pasted into the developer tools console of the web browser of the race viewer. To quickly generate in one step the escaped JSON and copy to clipboard, one can:

    • install jq and xclip, which are respectively a command-line JSON processor and command-line interface to X selections.
    • run the one liner: forge test && cat ./logs/gameLog.json | jq -Rsa | xclip -sel clip.
    • go to the console of the web browser, and start typing setGameData(, then paste, then );.

Elaborate, implement and test a strategy

The strategy is a solidity code where we must follow the rules. The rules define which action we can do, and how the costs change.

There are several examples of strategies in the zip downloaded from the official notion. There are located in src/cars/samples.

To implement your strategy and test it, you can:

  1. Copy the src/cars/ExampleCar.sol file into src/cars/MySuperCar.sol.
  2. Register your car into the test/Monaco.t.sol file. For this, you have to:
    • import the car.
    • Declare the car for the race.
// test/Monaco.t.sol
...
import { MySuperCar } from "../src/cars/MySuperCar.sol";
...
// PermaShield and Sauce are already declared in the samples.
ICar w1 = new PermaShield();
ICar w2 = new Sauce();
ICar w3 = new MySuperCar();
...
  1. Compile the code with forge test.
  2. Escape and copy paste the logs/gameLog.json content into the race viewer.

Enjoy! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment