TorchCraftAI
A bot for machine learning research on StarCraft: Brood War
squadcombat.h
1 /*
2  * Copyright (c) 2017-present, Facebook, Inc.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7 
8 #pragma once
9 
10 #include "models/micromodel.h"
11 #include "module.h"
12 #include "squadcombat/agent.h"
13 #include "squadcombat/behavior.h"
14 #include "upc.h"
15 
16 namespace cherrypi {
17 
18 struct EnemyState {
19  int damages = 0;
20  int lastRepairing = 0;
21 };
22 
23 /**
24  * Module which controls ("micromanages") units into and out of combat.
25  *
26  * SquadCombat reads diffuse Delete ("Fight") or Flee UPCs from the Blackboard
27  * and
28  * reposts them as sharp UPCs for commands like Delete or Move.
29  *
30  * SquadCombatModule is a thin orchestrator for micromanagement. Most of the
31  * micromanagement logic lives in the supporting classes of
32  * src/modules/squadcombat/
33  *
34  * * SquadTask: Controls squads (groups of unit with the same UPC)
35  * * Agent: Controls individual units using Behaviors
36  */
37 class SquadCombatModule : public Module {
38  public:
39  virtual void step(State* s) override;
40  /// Adds a MicroModel to the end of the list of models which will be updated
41  /// and solicited for UPCs
42  void enqueueModel(std::shared_ptr<MicroModel> model, std::string name);
43 
44  std::shared_ptr<MicroModel> getModel(std::string);
45  virtual void onGameEnd(State* state) override;
46  virtual void onGameStart(State* state) override;
47 
48  protected:
50 
51  /// Micromanagement state of our units.
52  std::unordered_map<Unit const*, Agent> agents_;
53 
54  /// Micromanagement state of enemy units.
55  std::unordered_map<Unit const*, EnemyState> enemyStates_;
56 
57  /// Models for SquadCombat to solicit for unit UPCs
58  std::unordered_map<std::string, std::shared_ptr<MicroModel>> models_;
59 
60  /// Takes incoming UPCs (usually from the Tactics module) and forms
61  /// clusters of units that fight collaboratively.
62  bool formNewSquad(std::shared_ptr<UPCTuple> sourceUpc, int sourceUpcId);
63 
64  void updateTask(std::shared_ptr<Task>);
65 
66  /// Produces new fight Behaviors for an Agent.
67  /// Intended for override by subclasses which insert baseline or ML-powered
68  /// behaviors.
69  virtual BehaviorList makeDeleteBehaviors();
70 
71  /// Produces new flee Behaviors for an Agent.
72  /// Intended for override by subclasses which insert baseline or ML-powered
73  /// behaviors.
74  virtual BehaviorList makeFleeBehaviors();
75 };
76 
77 } // namespace cherrypi
Game state.
Definition: state.h:42
Module which controls ("micromanages") units into and out of combat.
Definition: squadcombat.h:37
Definition: squadcombat.h:18
std::unordered_map< Unit const *, EnemyState > enemyStates_
Micromanagement state of enemy units.
Definition: squadcombat.h:55
int lastRepairing
Definition: squadcombat.h:20
std::unordered_map< std::string, std::shared_ptr< MicroModel > > models_
Models for SquadCombat to solicit for unit UPCs.
Definition: squadcombat.h:58
std::vector< std::shared_ptr< Behavior > > BehaviorList
Gives a series of Behaviors the option of issuing a UPC for the unit.
Definition: behavior.h:89
int damages
Definition: squadcombat.h:19
std::unordered_map< Unit const *, Agent > agents_
Micromanagement state of our units.
Definition: squadcombat.h:52
Main namespace for bot-related code.
Definition: areainfo.cpp:17
State * state
Definition: squadcombat.h:49
Interface for bot modules.
Definition: module.h:30