kittyverse 0.4.3 → 1.0.1

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.
@@ -0,0 +1,176 @@
1
+
2
+
3
+ class Genome
4
+
5
+ def initialize( arg )
6
+ if arg.is_a? Integer ## use Integer (Fixnum+Bignum??) - why? why not?
7
+ num = arg
8
+ kai = Kai.encode( num )
9
+ else
10
+ if arg.downcase.start_with?( '0x' ) ## assume hexstring( base16 )
11
+ kai = Kai.encode( arg.to_i(16) )
12
+ else # else assume string in kai/base32 format
13
+ kai = arg
14
+ kai = kai.gsub( ' ', '' ) ## allow spaces (strip/remove)
15
+ end
16
+ end
17
+ ## puts "Genome.initialize #{kai}"
18
+
19
+ @kai = kai ## note: store/save kai without any spaces ("compact" format)
20
+ @genes = build_genes( kai ) ## array of (sliced) genes (block of four genes)
21
+ end
22
+
23
+
24
+ def kai() Kai.fmt( @kai ); end # return formatted in blocks of 4
25
+ def bytes() Kai.bytes( @kai ); end
26
+
27
+ def num() Kai.decode( @kai ); end
28
+ alias_method :to_i, :num
29
+
30
+ def electrologica() Electrologica.fmt( Electrologica.encode( num ) ); end # return formatted in electrologica base32 format
31
+ alias_method :codes, :electrologica
32
+
33
+ def binary
34
+ @kai.chars.each_slice(4).map do |slice|
35
+ buf = ""
36
+ buf << Kai::BINARY[slice[0]]
37
+ buf << "-"
38
+ buf << Kai::BINARY[slice[1]]
39
+ buf << "-"
40
+ buf << Kai::BINARY[slice[2]]
41
+ buf << "-"
42
+ buf << Kai::BINARY[slice[3]]
43
+ buf
44
+ end.join( " " )
45
+ end
46
+ alias_method :bin, :binary
47
+
48
+
49
+ def build_genes( kai )
50
+ kai = kai.reverse ## note: reserve for easy left-to-right access
51
+ genes = [] ## array of (sliced) genes (block of four genes)
52
+ ## fix/todo: use as_json for "official" api order
53
+ ## note: use insert order from "official" api
54
+
55
+ ## genes << Gene::Slice.new( :body, kai[0],
56
+ ## kai[1],
57
+ ## kai[2],
58
+ ## kai[3] )
59
+ ## genes << Gene::Slice.new( :pattern, kai[4+0],
60
+ ## kai[4+1],
61
+ ## kai[4+2],
62
+ ## kai[4+3]] )
63
+
64
+ keys.each_with_index do |key,i|
65
+ genes << Gene::Slice.new( key, kai[4*i+0],
66
+ kai[4*i+1],
67
+ kai[4*i+2],
68
+ kai[4*i+3])
69
+ end
70
+ genes
71
+ end
72
+
73
+
74
+ def body() @genes[0]; end ## Fur (FU)
75
+ def pattern() @genes[1]; end ## Pattern (PA)
76
+ def coloreyes() @genes[2]; end ## Eyes Color (EC)
77
+ def eyes() @genes[3]; end ## Eyes Shape (ES)
78
+ def colorprimary() @genes[4]; end ## Base Color (BC)
79
+ def colorsecondary() @genes[5]; end ## Highlight Color (HC)
80
+ def colortertiary() @genes[6]; end ## Accent Color (AC)
81
+ def wild() @genes[7]; end ## Wild Element (WE)
82
+ def mouth() @genes[8]; end ## Mouth (MO)
83
+ def environment() @genes[9]; end ## Environment (EN)
84
+ def secret() @genes[10]; end ## Secret (SE)
85
+ def prestige() @genes[11]; end ## Purrstige (PU)
86
+
87
+ alias_method :color1, :colorprimary
88
+ alias_method :color2, :colorsecondary
89
+ alias_method :color3, :colortertiary
90
+ ## todo: add more alias(es) - why? why not?
91
+
92
+ ## add (convenience) alias for two-letter (trait type) codes too
93
+ alias_method :fu, :body
94
+ alias_method :pa, :pattern
95
+ alias_method :ec, :coloreyes
96
+ alias_method :es, :eyes
97
+ alias_method :bc, :colorprimary
98
+ alias_method :hc, :colorsecondary
99
+ alias_method :ac, :colortertiary
100
+ alias_method :we, :wild
101
+ alias_method :mo, :mouth
102
+ alias_method :en, :environment
103
+ alias_method :se, :secret
104
+ alias_method :pu, :prestige
105
+
106
+
107
+ def each() @genes.each { |slice| yield(slice) }; end
108
+ def each_with_index() @genes.each_with_index { |slice,i| yield(slice,i) }; end
109
+ alias_method :each_slice, :each
110
+ alias_method :each_slice_with_index, :each_with_index
111
+
112
+ def each_gene
113
+ @genes.each do |slice|
114
+ yield(slice.p)
115
+ yield(slice.r1)
116
+ yield(slice.r2)
117
+ yield(slice.r3)
118
+ end
119
+ end
120
+ def each_gene_with_index
121
+ @genes.each_with_index do |slice,i|
122
+ yield(slice.p, 4*i+0)
123
+ yield(slice.r1, 4*i+1)
124
+ yield(slice.r2, 4*i+2)
125
+ yield(slice.r3, 4*i+3)
126
+ end
127
+ end
128
+
129
+ def keys ## rename to trait_type_keys - why? why not?
130
+ [:body, ### todo/fix: use TRAITS.keys or something - why? why not?
131
+ :pattern,
132
+ :coloreyes,
133
+ :eyes,
134
+ :colorprimary,
135
+ :colorsecondary,
136
+ :colortertiary,
137
+ :wild,
138
+ :mouth,
139
+ :environment,
140
+ :secret,
141
+ :prestige]
142
+ end
143
+
144
+ def index( key )
145
+ if key.size == 2 && key =~ /^[A-Za-z]{2}$/ ## check for codes e.g. FU, PA, ... (or fu, pa,...)
146
+ key = key.upcase.to_sym
147
+ @@codes_by_index ||= %w(FU PA EC ES BC HC AC WE MO EN SE PU)
148
+ .each_with_index.reduce({}) do |h,(code,i)|
149
+ h[code.to_sym]=i; h
150
+ end
151
+ @@codes_by_index[ key ]
152
+ else
153
+ key = key.downcase.to_sym
154
+ key = ALT_TRAIT_TYPE_KEYS[ key ] if ALT_TRAIT_TYPE_KEYS[ key ]
155
+
156
+ @@keys_by_index ||= keys.each_with_index.reduce({}) do |h,(key,i)|
157
+ h[key]=i; h
158
+ end
159
+ @@keys_by_index[ key ]
160
+ end
161
+ end
162
+
163
+
164
+ def [](key)
165
+ if key.is_a? Integer ## assume 0,1,2,3,.. index
166
+ q , r = key.divmod(4) ## q=quotient, r=rest/modulus
167
+ ## e.g. 3.divmod(4) => [0,3]
168
+ ## 4.divmod(4) => [1,0]
169
+ ## 5.divmod(4) => [1,1] etc.
170
+ @genes[q][r]
171
+ else ## assume trait type key / symbol
172
+ @genes[index(key)]
173
+ end
174
+ end
175
+ end # class Genome
176
+
@@ -1,120 +1,118 @@
1
- # encoding: utf-8
2
-
3
- ##################################
4
- # Tier 0 (Base) (1-g)
5
- # Tier 1 (Mewtation I) (h-p)
6
- # Tier 2 (Mewtation II) (q-t)
7
- # Tier 3 (Mewtation III) (u,v)
8
- # Tier 4 (Mewtation IIII) (w) # note: use IIII instead of IV
9
- #
10
-
11
- MUTATION_TIER = { ## todo/fix: use an algo to calculate - why? why not?
12
- '1' => 0,
13
- '2' => 0,
14
- '3' => 0,
15
- '4' => 0,
16
- '5' => 0,
17
- '6' => 0,
18
- '7' => 0,
19
- '8' => 0,
20
- '9' => 0,
21
- 'a' => 0,
22
- 'b' => 0,
23
- 'c' => 0,
24
- 'd' => 0,
25
- 'e' => 0,
26
- 'f' => 0,
27
- 'g' => 0,
28
- 'h' => 1,
29
- 'i' => 1,
30
- 'j' => 1,
31
- 'k' => 1,
32
- 'm' => 1,
33
- 'n' => 1,
34
- 'o' => 1,
35
- 'p' => 1,
36
- 'q' => 2,
37
- 'r' => 2,
38
- 's' => 2,
39
- 't' => 2,
40
- 'u' => 3,
41
- 'v' => 3,
42
- 'w' => 4,
43
- 'x' => nil
44
- }
45
-
46
- ## (quick 'n' dirty) kai to mutation/mewtation tier level in roman numerals (I,II,III,IIII) - as strings (and nil)
47
- MUTATION_TIER_ROMAN = {
48
- '1' => '',
49
- '2' => '',
50
- '3' => '',
51
- '4' => '',
52
- '5' => '',
53
- '6' => '',
54
- '7' => '',
55
- '8' => '',
56
- '9' => '',
57
- 'a' => '',
58
- 'b' => '',
59
- 'c' => '',
60
- 'd' => '',
61
- 'e' => '',
62
- 'f' => '',
63
- 'g' => '',
64
- 'h' => 'I',
65
- 'i' => 'I',
66
- 'j' => 'I',
67
- 'k' => 'I',
68
- 'm' => 'I',
69
- 'n' => 'I',
70
- 'o' => 'I',
71
- 'p' => 'I',
72
- 'q' => 'II',
73
- 'r' => 'II',
74
- 's' => 'II',
75
- 't' => 'II',
76
- 'u' => 'III',
77
- 'v' => 'III',
78
- 'w' => 'IIII',
79
- 'x' => '' ## Use nil and NOT empty string "" - why? why not?
80
- }
81
-
82
- MUTATION_PAIR = {
83
- '1' => '', ## todo: use nil for "" - why? why not?
84
- '2' => '',
85
- '3' => '',
86
- '4' => '',
87
- '5' => '',
88
- '6' => '',
89
- '7' => '',
90
- '8' => '',
91
- '9' => '',
92
- 'a' => '',
93
- 'b' => '',
94
- 'c' => '',
95
- 'd' => '',
96
- 'e' => '',
97
- 'f' => '',
98
- 'g' => '',
99
- 'h' => '1+2',
100
- 'i' => '3+4',
101
- 'j' => '5+6',
102
- 'k' => '7+8',
103
- 'm' => '9+a',
104
- 'n' => 'b+c',
105
- 'o' => 'd+e',
106
- 'p' => 'f+g',
107
- 'q' => 'h+i',
108
- 'r' => 'j+k',
109
- 's' => 'm+n',
110
- 't' => 'o+p',
111
- 'u' => 'q+r',
112
- 'v' => 's+t',
113
- 'w' => 'u+v',
114
- 'x' => ''
115
- }
116
-
117
- ## add alias(es)
118
- MEWTATION_TIER = MUTATION_TIER
119
- MEWTATION_TIER_ROMAN = MUTATION_TIER_ROMAN
120
- MEWTATION_PAIR = MUTATION_PAIR
1
+ ##################################
2
+ # Tier 0 (Base) (1-g)
3
+ # Tier 1 (Mewtation I) (h-p)
4
+ # Tier 2 (Mewtation II) (q-t)
5
+ # Tier 3 (Mewtation III) (u,v)
6
+ # Tier 4 (Mewtation IIII) (w) # note: use IIII instead of IV
7
+ #
8
+
9
+ MUTATION_TIER = { ## todo/fix: use an algo to calculate - why? why not?
10
+ '1' => 0,
11
+ '2' => 0,
12
+ '3' => 0,
13
+ '4' => 0,
14
+ '5' => 0,
15
+ '6' => 0,
16
+ '7' => 0,
17
+ '8' => 0,
18
+ '9' => 0,
19
+ 'a' => 0,
20
+ 'b' => 0,
21
+ 'c' => 0,
22
+ 'd' => 0,
23
+ 'e' => 0,
24
+ 'f' => 0,
25
+ 'g' => 0,
26
+ 'h' => 1,
27
+ 'i' => 1,
28
+ 'j' => 1,
29
+ 'k' => 1,
30
+ 'm' => 1,
31
+ 'n' => 1,
32
+ 'o' => 1,
33
+ 'p' => 1,
34
+ 'q' => 2,
35
+ 'r' => 2,
36
+ 's' => 2,
37
+ 't' => 2,
38
+ 'u' => 3,
39
+ 'v' => 3,
40
+ 'w' => 4,
41
+ 'x' => nil
42
+ }
43
+
44
+ ## (quick 'n' dirty) kai to mutation/mewtation tier level in roman numerals (I,II,III,IIII) - as strings (and nil)
45
+ MUTATION_TIER_ROMAN = {
46
+ '1' => '',
47
+ '2' => '',
48
+ '3' => '',
49
+ '4' => '',
50
+ '5' => '',
51
+ '6' => '',
52
+ '7' => '',
53
+ '8' => '',
54
+ '9' => '',
55
+ 'a' => '',
56
+ 'b' => '',
57
+ 'c' => '',
58
+ 'd' => '',
59
+ 'e' => '',
60
+ 'f' => '',
61
+ 'g' => '',
62
+ 'h' => 'I',
63
+ 'i' => 'I',
64
+ 'j' => 'I',
65
+ 'k' => 'I',
66
+ 'm' => 'I',
67
+ 'n' => 'I',
68
+ 'o' => 'I',
69
+ 'p' => 'I',
70
+ 'q' => 'II',
71
+ 'r' => 'II',
72
+ 's' => 'II',
73
+ 't' => 'II',
74
+ 'u' => 'III',
75
+ 'v' => 'III',
76
+ 'w' => 'IIII',
77
+ 'x' => '' ## Use nil and NOT empty string "" - why? why not?
78
+ }
79
+
80
+ MUTATION_PAIR = {
81
+ '1' => '', ## todo: use nil for "" - why? why not?
82
+ '2' => '',
83
+ '3' => '',
84
+ '4' => '',
85
+ '5' => '',
86
+ '6' => '',
87
+ '7' => '',
88
+ '8' => '',
89
+ '9' => '',
90
+ 'a' => '',
91
+ 'b' => '',
92
+ 'c' => '',
93
+ 'd' => '',
94
+ 'e' => '',
95
+ 'f' => '',
96
+ 'g' => '',
97
+ 'h' => '1+2',
98
+ 'i' => '3+4',
99
+ 'j' => '5+6',
100
+ 'k' => '7+8',
101
+ 'm' => '9+a',
102
+ 'n' => 'b+c',
103
+ 'o' => 'd+e',
104
+ 'p' => 'f+g',
105
+ 'q' => 'h+i',
106
+ 'r' => 'j+k',
107
+ 's' => 'm+n',
108
+ 't' => 'o+p',
109
+ 'u' => 'q+r',
110
+ 'v' => 's+t',
111
+ 'w' => 'u+v',
112
+ 'x' => ''
113
+ }
114
+
115
+ ## add alias(es)
116
+ MEWTATION_TIER = MUTATION_TIER
117
+ MEWTATION_TIER_ROMAN = MUTATION_TIER_ROMAN
118
+ MEWTATION_PAIR = MUTATION_PAIR
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
 
4
2
 
5
3
  class Recipe
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
 
4
2
  class Trait
5
3
 
@@ -1,23 +1,20 @@
1
- # encoding: utf-8
2
-
3
-
4
- class Kittyverse
5
-
6
- MAJOR = 0
7
- MINOR = 4
8
- PATCH = 3
9
- VERSION = [MAJOR,MINOR,PATCH].join('.')
10
-
11
- def self.version
12
- VERSION
13
- end
14
-
15
- def self.banner
16
- "kittyverse/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
17
- end
18
-
19
- def self.root
20
- "#{File.expand_path( File.dirname(File.dirname(File.dirname(__FILE__))) )}"
21
- end
22
-
23
- end # module Kittyverse
1
+ class Kittyverse
2
+
3
+ MAJOR = 1
4
+ MINOR = 0
5
+ PATCH = 1
6
+ VERSION = [MAJOR,MINOR,PATCH].join('.')
7
+
8
+ def self.version
9
+ VERSION
10
+ end
11
+
12
+ def self.banner
13
+ "kittyverse/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}] in (#{root})"
14
+ end
15
+
16
+ def self.root
17
+ File.expand_path( File.dirname(File.dirname(File.dirname(__FILE__))) )
18
+ end
19
+
20
+ end # module Kittyverse