TorchCraftAI
A bot for machine learning research on StarCraft: Brood War
dummytactics.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 "module.h"
11 #include "state.h"
12 #include "task.h"
13 #include "tilesinfo.h"
14 #include "utils.h"
15 
16 #include <random>
17 
18 DECLARE_uint64(tactics_fight_or_flee_interval);
19 
20 namespace cherrypi {
21 
22 /**
23  * A simple Tactics module that issues a globally-distributed Delete UPC
24  */
25 class DummyTacticsModule : public Module {
26  std::shared_ptr<UPCTuple> upc = std::make_shared<UPCTuple>();
27 
28  public:
29  virtual void step(State* state) override {
30  if (state->unitsInfo().myUnits().empty() ||
31  state->unitsInfo().enemyUnits().empty()) {
32  return;
33  }
34 
35  upc->command[Command::Delete] = 1.0;
36  upc->unit.clear();
37  for (auto& unit : state->unitsInfo().myUnits()) {
38  upc->unit[unit] = 1.0;
39  }
40 
41  upc->position = UPCTuple::UnitMap();
42  for (auto& unit : state->unitsInfo().enemyUnits()) {
43  upc->position.get_unchecked<UPCTuple::UnitMap>()[unit] = 1.0;
44  }
45 
46  state->board()->postUPC(std::move(upc), kRootUpcId, this);
47  }
48 };
49 
50 } // namespace cherrypi
Game state.
Definition: state.h:42
virtual void step(State *state) override
Definition: dummytactics.h:29
A simple Tactics module that issues a globally-distributed Delete UPC.
Definition: dummytactics.h:25
UnitsInfo & unitsInfo()
Definition: state.h:116
UpcId constexpr kRootUpcId
Definition: basetypes.h:24
UpcId postUPC(std::shared_ptr< UPCTuple > &&upc, UpcId sourceId, Module *origin, std::shared_ptr< UpcPostData > data=nullptr)
Post a UPC tuple.
Definition: blackboard.cpp:88
const Units & myUnits()
All our (live) units.
Definition: unitsinfo.h:336
std::unordered_map< Unit *, float > UnitMap
Definition: upc.h:46
Blackboard * board() const
Definition: state.h:99
const Units & enemyUnits()
All enemy units that are not dead (includes gone units).
Definition: unitsinfo.h:350
Main namespace for bot-related code.
Definition: areainfo.cpp:17
Interface for bot modules.
Definition: module.h:30