jinni 0.3.3 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cd4398aec5ab4731e936b92312e4ad0ce6836712
4
- data.tar.gz: b9ee409a49994c860f65b6374a87e62aadb378b6
3
+ metadata.gz: 1519546cd3391ee816b4549b277f97927fe38bcf
4
+ data.tar.gz: 0d87d66bde2789bb322944cd475b32455c084130
5
5
  SHA512:
6
- metadata.gz: 55bbe63e329ea8ba921cf0746793f40498285b5cbaf6ec5d6ed1be1f659cd59d483623eaa96efd3b1d2ec2cb3a89ed2b53ed02b825294d91760d979c0c04f89f
7
- data.tar.gz: d9947762668127a6eb556341a924f2acf59200438367a8adedb7b64b23a5f2611c8f11720076c23f9713508309d4efe66d30e82388cdd1cd1e5446787876de2b
6
+ metadata.gz: fd99d43d5632c90f9d4ad08afb65e645bfb5b13fd9106d7c2fdc565e29cc9a126ef5636190b242c25de4c73038147d2ab5ac30a6f938dff53a698a113227c808
7
+ data.tar.gz: d9f480dc6a9e3985b2f5ef0eb75eabc50ee338997ded126a20f6e087762bcedfad1511766d308a14554e77ff2678e908fe60054b4be31c4b07ec816ddce27d5d
@@ -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
- newBinary = binary.chars.map { |bit| bit == "0" ? "1" : "0" if rand < rate }
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
@@ -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 )
@@ -30,7 +30,7 @@ class Jinni::Genepool < Array
30
30
 
31
31
  pool.each_slice(2) do |pair|
32
32
  child = pair[0] << pair[1]
33
- # child = child.mutate if mutationRate > 0
33
+ (child = child.mutate) if mutationRate > 0
34
34
  generation << child
35
35
  end
36
36
 
data/lib/jinni/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Jinni
2
- VERSION = "0.3.3"
2
+ VERSION = "0.3.4"
3
3
  end
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.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