reinforce 0.1.1 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d6f784fce6717c12f407633dbb56dba404570e9e45da8ba600f6262fa9002e23
4
- data.tar.gz: ffe9f04192a29a941cc34e6bd77e1588100596c0fa8157c2627ceacd2a8df35b
3
+ metadata.gz: 14e8dc56b32be98cfaba3626de5ea12a9b348d87f0abfb497b461cda4fcd7335
4
+ data.tar.gz: 6725510284291c233f75151d6aaf595d256963d1fed51d92bbad2321fcb4fb77
5
5
  SHA512:
6
- metadata.gz: 05e6126e4f9a9877bb925f386374abd8b64761ec993e80092d54eb5f5cdc4edb725eeda3f507bce260d5cf15b2872b0511b0cfd675516b6560bc05541a643c8b
7
- data.tar.gz: 6d32147351c0c512bb9bdaaa0b28e1b1734b4fd5839209ba58934fe7a441a65ccfac8d482052950b26e4f07274bc44e4d612226bf782a8914bf5c078ad4705ed
6
+ metadata.gz: 4190ab50bd5a4a5eb8a510a1c684e6b4b2042cf540fce2a56d062860e4fbfea22ca11fb03e613b057c451541c28c495808ff975b549fb383dd002616e0875826
7
+ data.tar.gz: 4b1e69ee08871043131251f845e860ea0669e3a46ca06a6649a2b15a183c1ed007390ee45957709469271ad28be3ba640569fbbe3bdba448ef225710921f7801
data/.rubocop.yml CHANGED
@@ -17,7 +17,7 @@ Metrics/ClassLength:
17
17
  Enabled: false
18
18
 
19
19
  Metrics/MethodLength:
20
- Max: 15
20
+ Max: 20
21
21
 
22
22
  Metrics/ParameterLists:
23
23
  Max: 10
@@ -97,6 +97,8 @@ module Reinforce
97
97
  cursor = next_build_for(cursor)
98
98
  end
99
99
 
100
+ Reinforce.logger.error("no data for pbgid #{pbgid} build #{build}")
101
+
100
102
  nil
101
103
  end
102
104
 
@@ -121,6 +123,8 @@ module Reinforce
121
123
  cursor = next_build_for(cursor)
122
124
  end
123
125
 
126
+ Reinforce.logger.error("no data for path #{path} build #{build}")
127
+
124
128
  nil
125
129
  end
126
130
 
@@ -6,7 +6,8 @@ module Reinforce
6
6
  PRODUCTION_COMMANDS = %w[BuildSquad BuildGlobalUpgrade].freeze
7
7
  BATTLEGROUP_COMMANDS = %w[SelectBattlegroup SelectBattlegroupAbility UseBattlegroupAbility].freeze
8
8
  CANCEL_COMMANDS = %w[CancelConstruction CancelProduction].freeze
9
- ALL_COMMANDS = BUILDING_COMMANDS + PRODUCTION_COMMANDS + BATTLEGROUP_COMMANDS + CANCEL_COMMANDS
9
+ AI_COMMANDS = %w[AITakeover].freeze
10
+ ALL_COMMANDS = BUILDING_COMMANDS + PRODUCTION_COMMANDS + BATTLEGROUP_COMMANDS + CANCEL_COMMANDS + AI_COMMANDS
10
11
 
11
12
  def initialize(player, build_number)
12
13
  @player = player.to_h
@@ -14,10 +15,11 @@ module Reinforce
14
15
  @buildings = []
15
16
  @productions = {}
16
17
  @battlegroup = []
18
+ @takeover = []
17
19
  end
18
20
 
19
21
  def build(with_cancellations: false)
20
- commands.each { |c| classify_command(c) }
22
+ commands.each { |c| break if classify_command(c) == false }
21
23
  result = consolidate
22
24
  result = rectify_suspects(result)
23
25
  result = result.reject(&:cancelled?) unless with_cancellations
@@ -40,16 +42,22 @@ module Reinforce
40
42
  classify_battlegroup_command(command)
41
43
  elsif CANCEL_COMMANDS.include?(command.action_type)
42
44
  process_cancellation(command)
45
+ elsif AI_COMMANDS.include?(command.action_type)
46
+ process_takeover(command)
43
47
  end
44
48
  end
45
49
 
46
50
  def classify_building_command(command)
47
- @buildings << command if command.details.autobuild?
51
+ @buildings << command if command.details&.autobuild?
52
+
53
+ true
48
54
  end
49
55
 
50
56
  def classify_production_command(command)
51
57
  @productions[command.source] ||= []
52
58
  @productions[command.source] << command
59
+
60
+ true
53
61
  end
54
62
 
55
63
  def classify_battlegroup_command(command)
@@ -58,6 +66,8 @@ module Reinforce
58
66
  else
59
67
  @battlegroup << command
60
68
  end
69
+
70
+ true
61
71
  end
62
72
 
63
73
  def process_cancellation(command)
@@ -66,10 +76,20 @@ module Reinforce
66
76
  else
67
77
  @productions[command.source][command.index - 1].cancel
68
78
  end
79
+
80
+ true
81
+ end
82
+
83
+ def process_takeover(command)
84
+ return true unless @player[:human]
85
+
86
+ @takeover << command
87
+
88
+ false
69
89
  end
70
90
 
71
91
  def consolidate
72
- build = @buildings + @battlegroup + @productions.values.flatten
92
+ build = @buildings + @battlegroup + @takeover + @productions.values.flatten
73
93
  build.sort_by(&:tick)
74
94
  end
75
95
 
@@ -78,12 +98,12 @@ module Reinforce
78
98
  commands.each_with_index do |command, idx|
79
99
  next unless command.suspect?
80
100
 
81
- building_details = Attributes::Collection.instance.get_by_path(command.details.builds, build: @build_number)
101
+ building_details = Attributes::Collection.instance.get_by_path(command.details&.builds, build: @build_number)
82
102
  remaining = commands[(idx + 1)..]
83
103
  relevant = remaining.take_while { |c| c.pbgid != command.pbgid }
84
104
 
85
105
  used = relevant.any? do |c|
86
- building_details.produces?(c.details.path)
106
+ building_details&.produces?(c.details.path)
87
107
  end
88
108
 
89
109
  command.mark_legit if used
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Reinforce
4
- VERSION = '0.1.1'
4
+ VERSION = '0.2.1'
5
5
  end
data/lib/reinforce.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'logger'
4
+
3
5
  require_relative 'reinforce/attributes/base'
4
6
 
5
7
  require_relative 'reinforce/attributes/ability'
@@ -19,6 +21,12 @@ module Reinforce
19
21
  File.expand_path('../', File.dirname(__FILE__))
20
22
  end
21
23
 
24
+ def self.logger
25
+ @logger ||= Logger.new($stdout).tap do |logger|
26
+ logger.progname = name
27
+ end
28
+ end
29
+
22
30
  # Takes a Vault Player and generates a build order
23
31
  def self.build_for(player, build_number, with_cancellations: false)
24
32
  Factory.new(player, build_number).build(with_cancellations:)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reinforce
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ryantaylor
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-09-11 00:00:00.000000000 Z
11
+ date: 2024-09-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: vault_coh
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '6'
19
+ version: '6.2'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '6'
26
+ version: '6.2'
27
27
  description: A tool for extracting accurate build orders from Company of Heroes 3
28
28
  replay files.
29
29
  email: