Skip to content
This repository was archived by the owner on Dec 11, 2018. It is now read-only.

Commit 9ec678d

Browse files
committed
progress
1 parent 0daaff0 commit 9ec678d

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

genome_new.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,25 @@ func (g *Genome) ConnenctionGenes() []*ConnectionGene {
173173
return g.connectionGenes
174174
}
175175

176-
func (g *Genome) PushNode() {
177-
g.nodeGene = append(g.nodeGene, n)
176+
// PushNode creates and appends a new node gene to this genome.
177+
func (g *Genome) Push(nodeType NodeType, activation ActivationFunc) *NodeGene {
178+
nodeId := len(g.nodeGenes) // its new index is its ID
179+
node := NewNodeGene(nodeId, nodeType, activation)
180+
g.nodeGene = append(g.nodeGene, node)
181+
return node
182+
}
183+
184+
// Connect
185+
func (g *Genome) Connect(srcId, dstId int) error {
186+
if outOfBounds(srcId) || outOfBounds(dstId) {
187+
return errors.New("")
188+
}
189+
}
190+
191+
// helper function that checks if the argument node ID is within the range.
192+
func (g *Genome) outOfBounds(nodeId int) bool {
193+
if 0 > nodeId || len(g.nodeGenes) <= nodeId {
194+
return false
195+
}
196+
return true
178197
}

0 commit comments

Comments
 (0)