-
-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy path1.13-finished-code.vy
48 lines (36 loc) · 1.03 KB
/
1.13-finished-code.vy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# @version >=0.2.4 <0.3.0
DNA_DIGITS: constant(uint256) = 16
DNA_MODULUS: constant(uint256) = 10 ** DNA_DIGITS
HP_LIMIT: constant(uint256) = 1000
struct Pokemon:
name: String[32]
dna: uint256
HP: uint256
matches: uint256
wins: uint256
totalPokemonCount: public(uint256)
pokemonList: HashMap[uint256, Pokemon]
event NewPokemonCreated:
name: String[32]
dna: uint256
HP: uint256
@pure
@internal
def _generateRandomDNA(_name: String[32]) -> uint256:
random: uint256 = convert(keccak256(_name), uint256)
return random % DNA_MODULUS
@internal
def _createPokemon(_name: String[32]) -> Pokemon:
randomDNA: uint256 = self._generateRandomDNA(_name)
randomHP: uint256 = randomDNA % HP_LIMIT
newPokemon: Pokemon = Pokemon({
name: _name,
dna: randomDNA,
HP: randomHP,
matches: 0,
wins: 0
})
self.pokemonList[self.totalPokemonCount] = newPokemon
self.totalPokemonCount += 1
log NewPokemonCreated(_name, randomDNA, randomHP)
return newPokemon