Genomix · Smart Contract Library · v1.0
GenomixLib
Compact 256-bit on-chain creature DNA · EVM-optimised · MIT License

Bit Layout

Constants

Constant Mask Value Bits Width

API Reference

Usage Example

Solidity
// In your creature spawning contract:
using genomix for uint256;

mapping(uint256 => uint256) public creatureGenome;

function spawnCreature(uint256 planetId, bytes32 vrfEntropy) external {
    // Fetch planet physics from your engine
    Planet memory p = planets[planetId];

    // Derive genome deterministically from physics
    uint256 genome = genomix.deriveFromPlanet(
        p.carbon, p.silicon, p.oxygen,
        p.gravity, p.temperature, p.radiation,
        p.tidal, p.methane,
        vrfEntropy
    );

    creatureGenome[nextId] = genome;
    emit CreatureSpawned(nextId++, genome);
}

function breed(uint256 parentId, bytes32 vrfSeed) external {
    // Deduct OBAMEOW tokens here
    obameow.burn(msg.sender, MUTATION_COST);

    uint256 child = genomix.mutate(
        creatureGenome[parentId],
        mutationIntensity,
        vrfSeed
    );

    creatureGenome[nextId] = child;
}

function checkFitness(uint256 creatureId, uint256 planetId)
    external view returns (uint16 score)
{
    Planet memory p = planets[planetId];
    return genomix.fitnesScore(
        creatureGenome[creatureId],
        p.oxygen, p.gravity, p.temperature, p.radiation
    );
}

function offChainDecode(uint256 creatureId)
    external view returns (genomix.DecodedGenome memory)
{
    return genomix.decode(creatureGenome[creatureId]);
}

Interactive Decoder

Decode a Genome

Hamming Distance Demo

Evolutionary Distance

XOR of two genomes — red bits = mutations between generations