sc2ai 0.6.5 → 0.7.0

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.
@@ -520,11 +520,11 @@ module Sc2
520
520
  point_search_offsets = (-7..7).to_a.product((-7..7).to_a)
521
521
  point_search_offsets.select! do |x, y|
522
522
  dist = Math.hypot(x, y)
523
- dist > 4 && dist <= 8
523
+ dist > 4.0 && dist <= 8.0
524
524
  end
525
525
 
526
526
  # Split resources by Z axis
527
- resources = bot.neutral.minerals.reject_type(Api::UnitTypeId::MINERALFIELD450) + bot.neutral.geysers
527
+ resources = bot.neutral.minerals - mineral_walls + bot.neutral.geysers
528
528
  resource_group_z = resources.group_by do |resource|
529
529
  resource.pos.z.round # 32 units of Y, most maps will have use 3. round to nearest.
530
530
  end
@@ -591,11 +591,86 @@ module Sc2
591
591
  # Choose best fitting point
592
592
  best_point = possible_points.keys[possible_points.values.find_index(possible_points.values.min)]
593
593
  @expansions[best_point.to_p2d] = UnitGroup.new(clustered_resources)
594
+
595
+ # Check if this might be a mirrored base.
596
+ best_mirror_point = nil
597
+ geysers = clustered_resources.select { |res| Sc2::UnitGroup::TYPE_GEYSER.include?(res.unit_type) }
598
+ if geysers.size == 2
599
+ if geysers[0].pos.y == geysers[1].pos.y || geysers[0].pos.x == geysers[1].pos.x
600
+ # Mirrored vertical, potentially
601
+ best_mirror_point = [
602
+ best_point[0],
603
+ best_point[1] - (best_point[1] - (geysers[0].pos.y + geysers[1].pos.y) / 2.0) * 2.0
604
+ ]
605
+ if best_mirror_point != best_point && possible_points.has_key?(best_mirror_point)
606
+ @expansions[best_mirror_point.to_p2d] = UnitGroup.new(clustered_resources)
607
+ else
608
+ # Wasn't mirrored the one way. How about the other?...
609
+ # Mirrored horizontal, potentially
610
+ best_mirror_point = [
611
+ best_point[0] - (best_point[0] - (geysers[0].pos.x + geysers[1].pos.x) / 2.0) * 2.0,
612
+ best_point[1]
613
+ ]
614
+ if best_mirror_point != best_point && possible_points.has_key?(best_mirror_point)
615
+ @expansions[best_mirror_point.to_p2d] = UnitGroup.new(clustered_resources)
616
+ end
617
+
618
+ end
619
+ end
620
+ end
594
621
  end
595
622
  end
596
623
  @expansions
597
624
  end
598
625
 
626
+ # @private
627
+ # Mineral walls. Defined once upon start of game, mostly based on layout.
628
+ # @return [Sc2::UnitGroup]
629
+ private def mineral_walls
630
+ return @mineral_walls unless @mineral_walls.nil?
631
+
632
+ # Find mineral walls.
633
+ @mineral_walls = []
634
+ minerals_by_pos = {}
635
+ bot.neutral.minerals.reject_type(Api::UnitTypeId::MINERALFIELD450)
636
+ .each do |mineral|
637
+ minerals_by_pos[mineral.pos.to_axy] = mineral
638
+ end
639
+ minerals_by_pos.each do |xy, mineral|
640
+ x, y = xy
641
+ # Test X
642
+ if (side1 = minerals_by_pos[[x - 2, y]]) && (side2 = minerals_by_pos[[x + 2, y]])
643
+ @mineral_walls << side1
644
+ @mineral_walls << mineral
645
+ @mineral_walls << side2
646
+ end
647
+
648
+ # # Test Y
649
+ if (side1 = minerals_by_pos[[x, y - 1]]) && (side2 = minerals_by_pos[[x, y + 1]])
650
+ @mineral_walls << side1
651
+ @mineral_walls << mineral
652
+ @mineral_walls << side2
653
+ end
654
+
655
+ # Test \
656
+ if (side1 = minerals_by_pos[[x - 2, y + 1]]) && (side2 = minerals_by_pos[[x + 2, y - 1]])
657
+ @mineral_walls << side1
658
+ @mineral_walls << mineral
659
+ @mineral_walls << side2
660
+ end
661
+
662
+ # Test /
663
+ if (side1 = minerals_by_pos[[x - 2, y - 1]]) && (side2 = minerals_by_pos[[x + 2, y + 1]])
664
+ @mineral_walls << side1
665
+ @mineral_walls << mineral
666
+ @mineral_walls << side2
667
+ end
668
+ end
669
+ @mineral_walls.uniq!
670
+
671
+ @mineral_walls = UnitGroup.new(@mineral_walls) + bot.neutral.minerals.select_type(Api::UnitTypeId::MINERALFIELD450)
672
+ end
673
+
599
674
  # Returns a list of 2d points for expansion build locations
600
675
  # Does not contain mineral info, but the value can be checked against geo.expansions
601
676
  #
data/lib/sc2ai/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Sc2
2
2
  # gem version
3
3
  # @return [String]
4
- VERSION = "0.6.5"
4
+ VERSION = "0.7.0"
5
5
  end
@@ -10,5 +10,5 @@ Sc2::Match.new(
10
10
  $bot,
11
11
  Sc2::Player::Computer.new(race: Api::Race::RANDOM, difficulty: Api::Difficulty::VERY_EASY)
12
12
  ],
13
- map: "ThunderbirdAIE" # Or any of the downloaded map names
13
+ map: "PylonAIE" # Or any of the downloaded map names
14
14
  ).run