seshbot-packing 0.9.1 → 0.9.2

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
  SHA256:
3
- metadata.gz: 5a3ee88fef7cdb7044eb06951aaee1a388dc499a33226d553ecf1d4af3865df2
4
- data.tar.gz: 7ceb6a0a5ad57b515e881352907e42c3bec29330c1055a8947e9662f03ad0ebc
3
+ metadata.gz: f77cf089e5f02caf10d7af67e7d75260d3529c560b2cfee232ba3b72f5f36e94
4
+ data.tar.gz: ec54cf2361668f1c92789f9337f0feb8f744a1208192e74368d46773eddf1f4f
5
5
  SHA512:
6
- metadata.gz: d7d04a459fbfc6dc06b7b028b535f5a1ab8e87579eb59f3aebc6803d82587abd7582c94074217e6935e189ba56d185138841aca429c3e774ff872c6e82e4a93c
7
- data.tar.gz: 030363e4fe38d1f095766f836b86960639e8f3a23cbdde611c3d305cb259315816adc0a488cde7134f778958d3022f19056a0f850244324e0a844bc855195ba9
6
+ metadata.gz: 1e5539df5a295507c496115dfda6f972310c24ed88dfc97a2712f55e8c852e2f4f64bde98168e4d626f7a7f5484cfdf472705c0f4fec6139f06e90620bbc8ad4
7
+ data.tar.gz: c482b9e179a56795a7ff2559d72f708ab27a684dae5e11f9d9fca423ea543752f80dd0e377cccbdb6241e6605b7ec20c75412bb5f4984e6d67caf7935e0fe28e
@@ -8,21 +8,40 @@ module Seshbot
8
8
  # we want the recipe that is 'best' (packaging into as few items as possible, or unpacaging into as many as possible)
9
9
  best_recipe = nil
10
10
  best_recipe_output_quantity = nil
11
+ best_recipe_inputs_quantity = nil
11
12
  recipes.each do |recipe_name, recipe|
13
+ recipe_inputs = recipe['inputs'].nil? ? [recipe] : recipe['inputs']
14
+
12
15
  recipe_factor = _calculate_recipe_factor(recipe, items)
13
16
  recipe_output_quantity = recipe_factor * recipe['output_quantity']
17
+ recipe_inputs_quantity = recipe_factor * recipe_inputs.map { |r| r['input_quantity'] }.sum
14
18
 
15
19
  # is this recipe the 'best'? (if packaging, best is the one that creates fewest quantity)
16
20
  is_best = if best_recipe_output_quantity.nil?
17
21
  true
18
22
  else
19
- unpacking ?
23
+ #
24
+ # the below code uses output as the main feature, but if they are equal uses the number of inputs
25
+ #
26
+
27
+ output_equal = recipe_output_quantity == best_recipe_output_quantity
28
+
29
+ # when packing, fewer outputs are better
30
+ output_better = unpacking ?
20
31
  recipe_output_quantity > best_recipe_output_quantity :
21
32
  recipe_output_quantity < best_recipe_output_quantity
33
+
34
+ # when packing, more inputs are better
35
+ inputs_better = unpacking ?
36
+ recipe_inputs_quantity < best_recipe_inputs_quantity :
37
+ recipe_inputs_quantity > best_recipe_inputs_quantity
38
+
39
+ output_equal ? inputs_better : output_better
22
40
  end
23
41
 
24
42
  if is_best
25
43
  best_recipe_output_quantity = recipe_output_quantity
44
+ best_recipe_inputs_quantity = recipe_inputs_quantity
26
45
  best_recipe = recipe
27
46
  end
28
47
  end
@@ -1,5 +1,5 @@
1
1
  module Seshbot
2
2
  module Packing
3
- VERSION = '0.9.1'
3
+ VERSION = '0.9.2'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: seshbot-packing
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shaun
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-04-07 00:00:00.000000000 Z
11
+ date: 2021-04-08 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: