Skip to content
This repository has been archived by the owner on Aug 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #2 from ShaneMaglangit/gene-quality
Browse files Browse the repository at this point in the history
Gene quality
  • Loading branch information
ShaneMaglangit authored Jul 30, 2021
2 parents 3e48adc + 63f99e4 commit 6056357
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ const hex = "0x280000000000010040412090830C0000000101942040440A00010190284082040
const axieGene = new AxieGene(hex, HexType.Bit512);
```

## Gene Quality

You may also get the quality of the genes directly through the AxieGene object.
```ts
axieGene.getGeneQuality();
```


This object automatically handles the parsing of the hex value for you. You may simply use the accessors of the class to
get the gene information that you want.
Expand Down
30 changes: 30 additions & 0 deletions src/axie-gene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -549,4 +549,34 @@ export class AxieGene {
}
return ret;
}

/**
* Calculates the purity or gene quality of the Axie's gene.
* @returns a number that represents the quality of the gene in percentage.
*/
getGeneQuality(): number {
let geneQuality = 0;
geneQuality += this.getPartQuality(this._genes.eyes);
geneQuality += this.getPartQuality(this._genes.ears);
geneQuality += this.getPartQuality(this._genes.mouth);
geneQuality += this.getPartQuality(this._genes.horn);
geneQuality += this.getPartQuality(this._genes.back);
geneQuality += this.getPartQuality(this._genes.tail);
return parseFloat(geneQuality.toFixed(2));
}

/**
* Calculate the purity or gene quality of the Axie's individual parts.
* @param part part genes the will be used for the calculation.
* @private
* @returns an integer that represents the quality of the individual part in percentage.
*/
private getPartQuality(part: Part): number {
const cls = this._genes.cls;
let partQuality = 0;
partQuality += part.d.cls === cls ? 76/6 : 0;
partQuality += part.r1.cls === cls ? 3 : 0;
partQuality += part.r2.cls === cls ? 1 : 0;
return partQuality;
}
}
13 changes: 12 additions & 1 deletion test/axie-gene.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,4 +301,15 @@ describe('AxieGene_Origin_512bit', () => {
it('parse tag', () => {
expect(axieGene.tag).toBe(Tag.Origin);
});
});
});

describe('AxieGene_Quality', () => {
const axieGeneP6 = new AxieGene('0x50000000021053031443110414a5280814250802146508c414451108146230c2');
it('gene quality pure 6', () => {
expect(axieGeneP6.getGeneQuality()).toBe(88);
});
const axieGeneP2 = new AxieGene('0x300000000b881322104308c20c2110c40c201908108208ca148120cc10430806');
it('gene quality pure 2', () => {
expect(axieGeneP2.getGeneQuality()).toBe(35.33);
});
})

0 comments on commit 6056357

Please sign in to comment.