TorchCraftAI
A bot for machine learning research on StarCraft: Brood War
buildingplacer.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 "buildtype.h"
11 #include "cherrypi.h"
12 #include "module.h"
13 
14 #include "models/buildingplacer.h"
15 
16 namespace cherrypi {
17 
18 /**
19  * Determines positions for buildings.
20  *
21  * For buildings that require a worker to build them, BuilderModule requires the
22  * UPC to specify a Dirac position. This module's job is to determine suitable
23  * positions based on an existing distribution over positions and various
24  * heuristics (via builderhelpers).
25  *
26  * Optionally, BuildingPlacerModel can be used for building placement. The model
27  * location is specified via the -bp_model command-line flag; if a valid model
28  * is found at the specified location, it will be loaded and used. If GPU
29  * support is available, the model will be run on the GPU.
30  *
31  * ProxyTasks are used to track execution of the downstream production task. If
32  * the production task will fail (e.g. because the location became unbuildable),
33  * retries will be attempted until the ProxyTask is cancelled (e.g. from an
34  * upstream module).
35  *
36  * This module will also reserve build tiles as unbuildable via TilesInfo.
37  */
38 class BuildingPlacerModule : public Module {
39  public:
40  virtual ~BuildingPlacerModule() = default;
41 
42  virtual void step(State* s) override;
43  virtual void onGameStart(State* state) override;
44 
45  private:
46  std::shared_ptr<UPCTuple> upcWithPositionForBuilding(
47  State* state,
48  UPCTuple const& upc,
49  BuildType const* type);
50 
51  std::shared_ptr<BuildingPlacerModel> model_;
52  std::shared_ptr<BuildingPlacerSample::StaticData> staticData_;
53  bool firstStep_ = true;
54  std::unordered_set<Position> baseLocations_;
55 };
56 
57 } // namespace cherrypi
Game state.
Definition: state.h:42
virtual void step(State *s) override
Definition: buildingplacer.cpp:109
Represents and holds information about buildable types (units, upgrades, techs).
Definition: buildtype.h:36
virtual ~BuildingPlacerModule()=default
Determines positions for buildings.
Definition: buildingplacer.h:38
(Unit, Position, Command) tuple.
Definition: upc.h:43
virtual void onGameStart(State *state) override
Definition: buildingplacer.cpp:223
Main namespace for bot-related code.
Definition: areainfo.cpp:17
Interface for bot modules.
Definition: module.h:30