jinni 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jinni/creature.rb +15 -1
- data/lib/jinni/eigenclass.rb +7 -0
- data/lib/jinni/genepool.rb +1 -1
- data/lib/jinni/version.rb +1 -1
- metadata +1 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1519546cd3391ee816b4549b277f97927fe38bcf
|
4
|
+
data.tar.gz: 0d87d66bde2789bb322944cd475b32455c084130
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd99d43d5632c90f9d4ad08afb65e645bfb5b13fd9106d7c2fdc565e29cc9a126ef5636190b242c25de4c73038147d2ab5ac30a6f938dff53a698a113227c808
|
7
|
+
data.tar.gz: d9f480dc6a9e3985b2f5ef0eb75eabc50ee338997ded126a20f6e087762bcedfad1511766d308a14554e77ff2678e908fe60054b4be31c4b07ec816ddce27d5d
|
data/lib/jinni/creature.rb
CHANGED
@@ -20,7 +20,13 @@ module Jinni
|
|
20
20
|
# method to return a possibly mutated version of a given object
|
21
21
|
def mutate(rate = 0.01)
|
22
22
|
binary = self.to_binary
|
23
|
-
|
23
|
+
newBinaryArray = binary.chars.map do |bit|
|
24
|
+
if rand < rate
|
25
|
+
bit = (bit == "0" ? "1" : "0")
|
26
|
+
end
|
27
|
+
bit
|
28
|
+
end
|
29
|
+
newBinary = newBinaryArray.join
|
24
30
|
return self.class.new_from_binary newBinary
|
25
31
|
end
|
26
32
|
|
@@ -76,6 +82,14 @@ module Jinni
|
|
76
82
|
|
77
83
|
# used internally by ::new_from_binary, a la #initialize
|
78
84
|
def initialize_from_binary(binary)
|
85
|
+
# correct for broken method somewhere that sends array instead of string
|
86
|
+
binary = binary.join if binary.class == Array
|
87
|
+
|
88
|
+
raise "no binary string!!" unless binary.to_i(2) > 0
|
89
|
+
until binary.length >= self.class.genetic_bits
|
90
|
+
binary << binary
|
91
|
+
end
|
92
|
+
|
79
93
|
hash = hash_from_binary(binary)
|
80
94
|
initialize(hash)
|
81
95
|
end
|
data/lib/jinni/eigenclass.rb
CHANGED
@@ -29,14 +29,21 @@ module Jinni
|
|
29
29
|
obj
|
30
30
|
end
|
31
31
|
|
32
|
+
# genes class variable getter
|
32
33
|
def genes
|
33
34
|
class_variable_get "@@genes"
|
34
35
|
end
|
35
36
|
|
37
|
+
# genes class variable setter
|
36
38
|
def genes= genes
|
37
39
|
class_variable_set "@@genes", genes
|
38
40
|
end
|
39
41
|
|
42
|
+
# the required length of a binary string to generate a creature of this class
|
43
|
+
def genetic_bits
|
44
|
+
genes.values.map {|range| range.bits}.reduce(:+)
|
45
|
+
end
|
46
|
+
|
40
47
|
|
41
48
|
# use like attr_accessor
|
42
49
|
def attr_genetic( gene, min, max )
|
data/lib/jinni/genepool.rb
CHANGED
data/lib/jinni/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jinni
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Monks
|
@@ -68,8 +68,6 @@ files:
|
|
68
68
|
- bin/setup
|
69
69
|
- jinni.gemspec
|
70
70
|
- lib/jinni.rb
|
71
|
-
- lib/jinni/.eigenclass.rb.swp
|
72
|
-
- lib/jinni/.version.rb.swp
|
73
71
|
- lib/jinni/creature.rb
|
74
72
|
- lib/jinni/eigenclass.rb
|
75
73
|
- lib/jinni/genepool.rb
|