-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenes.go
82 lines (58 loc) · 1.75 KB
/
genes.go
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package main
import (
"fmt"
"golang.org/x/crypto/sha3"
)
func (k *koji) getGenome() string {
// generate & serialize elements
// t := fmt.Sprintf("%s", time.Now())
out := make([]byte, 512)
hashit := []byte("Father: RockSteady" + k.name)
sha3.ShakeSum256(out, hashit)
globalGenes = fmt.Sprintf("%x", out[:])
k.genome.strand = globalGenes
k.writeGenes(globalGenes, geneFile)
return globalGenes
}
func (k *koji) writeGenes(genes, filename string) {
createDirIfItDontExist(geneDir)
geneCode := []string{}
for i := 0; i < len(genes); i = i + 32 {
if (i + 32) > len(genes) {
return
}
line := fmt.Sprintf("\n%s %s %s %s",
genes[i:i+8],
genes[i+8:i+16],
genes[i+16:i+24],
genes[i+24:i+32])
geneCode = append(geneCode, line)
}
writeStrings(filename, geneCode)
}
func (k *koji) conjugateGenes() {
// press B to breed, but koji must be a certain age to be able
// where to place mother and father genes?
// mother.md father.md could work for now
// load mother genes
// load father genes
motherGenes := readFile(motherFile)
fatherGenes := readFile(fatherFile)
// combine them somehow?
// - maybe hash them both to create a new genome?
// - maybe combine parts of them?
// . but then, how do we determine which parts from mom and which parts
// . from father should be inherited?
// - maybe have inherited genes, but also have parts that are hashed
out := make([]byte, 512)
hashit := []byte(motherGenes + fatherGenes)
sha3.ShakeSum256(out, hashit)
childGenes := fmt.Sprintf("%x", out[:])
// return new genome
k.writeGenes(childGenes, childFile)
// should the genome have some type of lineage header?
// maybe thats overcomplicating it.
// maybe something like
// mother: <name at time of breeding>
// father: ''
}