TorchCraftAI
A bot for machine learning research on StarCraft: Brood War
gathererassignments.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 "modules/gatherer/resourceworkers.h"
11 #include "state.h"
12 
13 namespace cherrypi {
14 
15 /**
16  * Assigns workers to resources for optimal gathering.
17  */
19  /// Used internally to track worker statefulness
20  struct WorkerState {
21  /// Number of frames since this worker has had a gathering update.
23 
24  /// Next frame we're allowed to reassign this worker to a new resource.
25  /// Serves to avoid excessive churning of confused workers.
27 
28  /// Tracks the gathering value of this worker's last resource.
29  /// Used for diagnostic purposes only.
30  double lastResourceScore = 0.0;
31  };
32 
33  /// Mapping of workers assigned to resources.
35 
36  /// Mapping of workers to their gathering state.
37  std::unordered_map<Unit*, WorkerState> workers;
38 
39  /// Include a worker in gathering.
40  void addUnit(Unit*);
41 
42  /// Remove a worker from gathering.
43  void removeUnit(Unit*);
44 
45  /// Update gathering assignments for this frame.
46  void step(State*);
47 };
48 
49 } // namespace cherrypi
Game state.
Definition: state.h:42
int cooldownUntil
Next frame we&#39;re allowed to reassign this worker to a new resource.
Definition: gathererassignments.h:26
void step(State *)
Update gathering assignments for this frame.
Definition: gathererassignments.cpp:118
Data structure for storing the state of our gathering assignments.
Definition: resourceworkers.h:24
double lastResourceScore
Tracks the gathering value of this worker&#39;s last resource.
Definition: gathererassignments.h:30
Assigns workers to resources for optimal gathering.
Definition: gathererassignments.h:18
std::unordered_map< Unit *, WorkerState > workers
Mapping of workers to their gathering state.
Definition: gathererassignments.h:37
Used internally to track worker statefulness.
Definition: gathererassignments.h:20
Represents a unit in the game.
Definition: unitsinfo.h:35
ResourceWorkers resourceWorkers
Mapping of workers assigned to resources.
Definition: gathererassignments.h:34
void addUnit(Unit *)
Include a worker in gathering.
Definition: gathererassignments.cpp:91
void removeUnit(Unit *)
Remove a worker from gathering.
Definition: gathererassignments.cpp:95
int framesSinceUpdate
Number of frames since this worker has had a gathering update.
Definition: gathererassignments.h:22
int constexpr kForever
Definition: basetypes.h:37
Main namespace for bot-related code.
Definition: areainfo.cpp:17