grimoire 0.1.6 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9e488dfe4964214969754e066c275034a4663d67
4
- data.tar.gz: 015e51d0f9a05e51a00b5f0b41c4de77764c77f6
3
+ metadata.gz: 6edd571b20c68657154ccebb7e415844163e2021
4
+ data.tar.gz: c840f072f9a7ea4e7542e1a2243ed9b7b6b6b580
5
5
  SHA512:
6
- metadata.gz: d4756adf5a06f61ed26b4732e7f8848b1a063f47372577578038be52ff8532e31d2c0f8e789612d9131d23aad8c27528fad05753d751b4bef6f821f8670253ce
7
- data.tar.gz: 387138f63f6e94ee25c359be79359266721441b3f0779452fc20f871f525f1e2df03954a43702cf9473de8c10899c2249aa6ca547a2df7cad887d632dced909e
6
+ metadata.gz: 9588422c6b487a94fb009f75021499a918e7ffcf5fc247c1c1b4299b8a845170e0c2396b056a978dd04ef5018e434b1f1de71ed658adc0bfd99514e87278fa68
7
+ data.tar.gz: 6e73d8db9e4b7a82339cc4a7beb1673158cee6db83f76da3d904efe7a5939720f081aa9f9df638b6350bd264fa4e9d2f503942ba82044e5b7900a67b6cb6c35d
@@ -1,3 +1,11 @@
1
+ # v0.2.0
2
+ * Use direct `#to_json` to prevent conversion errors on older ruby
3
+ * Add `UnitScoreKeeper#preferred_score` to provide some score meaning
4
+ * Pass scoring preference through to queue init
5
+ * Provide current index to score keeper when requesting score
6
+
7
+ _ BREAKING CHANGES_: `UnitScoreKeeper#score_for` must now accept two parameters
8
+
1
9
  # v0.1.6
2
10
  * Add debug output if UI is available for output
3
11
  * Update exception errors to provide more detail/context
@@ -54,12 +54,21 @@ module Grimoire
54
54
  end
55
55
  end
56
56
 
57
+ # @return [Bogo::PriorityQueue]
58
+ def create_queue
59
+ if(score_keeper)
60
+ Bogo::PriorityQueue.new(score_keeper.preferred_score)
61
+ else
62
+ Bogo::PriorityQueue.new
63
+ end
64
+ end
65
+
57
66
  # @return [Smash<{Unit#name:Bogo::PriorityQueue}>]
58
67
  def queues
59
68
  memoize(:queues) do
60
69
  Smash[
61
70
  world.units.map do |name, items|
62
- queue = Bogo::PriorityQueue.new
71
+ queue = create_queue
63
72
  populate_queue(queue, items)
64
73
  [name, queue]
65
74
  end
@@ -88,7 +97,7 @@ module Grimoire
88
97
  # @return [Numeric] score
89
98
  def score_unit(unit, score)
90
99
  if(score_keeper)
91
- score_keeper.score_for(unit) || score
100
+ score_keeper.score_for(unit, score) || score
92
101
  else
93
102
  score
94
103
  end
@@ -100,7 +109,7 @@ module Grimoire
100
109
  # @return [self]
101
110
  def reset_queue(name)
102
111
  queue = populate_queue(
103
- Bogo::PriorityQueue.new,
112
+ create_queue,
104
113
  world.units[name]
105
114
  )
106
115
  queues[name] = queue
@@ -3,11 +3,20 @@ require 'grimoire'
3
3
  module Grimoire
4
4
  class UnitScoreKeeper < Utility
5
5
 
6
+ # Define meaning of score by what should be preferred. This is
7
+ # used by the solver to apply correct sorting to the queues.
8
+ #
9
+ # @return [Symbol] :lowscore or :highscore
10
+ def preferred_score
11
+ :lowscore
12
+ end
13
+
6
14
  # Provide score for given unit
7
15
  #
8
16
  # @param unit [Unit]
17
+ # @param idx [Integer] current order index
9
18
  # @return [Numeric]
10
- def score_for(unit)
19
+ def score_for(unit, idx)
11
20
  raise NotImplementedError.new 'No scoring has been defined'
12
21
  end
13
22
 
@@ -18,7 +18,7 @@ module Grimoire
18
18
 
19
19
  # @return [String] JSON serialized
20
20
  def to_json(*args)
21
- MultiJson.dump(data, *args)
21
+ data.to_json(*args)
22
22
  end
23
23
 
24
24
  # Write debug message
@@ -1,4 +1,4 @@
1
1
  module Grimoire
2
2
  # Current library version
3
- VERSION = Gem::Version.new('0.1.6')
3
+ VERSION = Gem::Version.new('0.2.0')
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grimoire
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Roberts
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-19 00:00:00.000000000 Z
11
+ date: 2015-03-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bogo