TorchCraftAI
A bot for machine learning research on StarCraft: Brood War
defoggerfeatures.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  * Legacy defogger featurizer.
8  */
9 
10 #pragma once
11 
12 #include "cherrypi.h"
13 #include <array>
14 #include <torch/torch.h>
15 
16 namespace cherrypi {
17 
18 /**
19  * Copypasted from defoggerFeaturizer on the defogger branch.
20  */
22  public:
23  std::array<int, 234> typemapper;
24  std::array<int, 234> itypemapper;
25  size_t feature_size;
26  size_t resX, resY;
27  int32_t strideX, strideY;
28  bool fullVision;
29 
31  size_t resX,
32  size_t resY,
33  int32_t strideX,
34  int32_t strideY,
35  bool fullVision = false)
36  : resX(resX),
37  resY(resY),
38  strideX(strideX),
39  strideY(strideY),
40  fullVision(fullVision) {
41  this->feature_size = 118;
42  typemapper.fill(117);
43  size_t i = 0;
44  for (auto t : tc::BW::UnitType::_values()) {
45  typemapper.at(t._to_integral()) = i;
46  itypemapper.at(i) = t._to_integral();
47  i++;
48  }
49  }
50 
51  torch::Tensor featurize(
52  tc::Frame* frame,
53  int mapX,
54  int mapY,
55  int playerId,
56  at::Device device);
57  void featurize_unit(torch::Tensor& feats, tc::Unit& u, int, int);
58  void inc_feature(torch::Tensor& feature, int32_t c, int32_t x, int32_t y)
59  const;
60  static tc::Frame combine(const std::deque<tc::Frame>& frames, int playerId);
61 };
62 
63 } // namespace cherrypi
size_t resY
Definition: defoggerfeatures.h:26
int32_t strideX
Definition: defoggerfeatures.h:27
Definition: frame.h:306
int32_t strideY
Definition: defoggerfeatures.h:27
std::array< int, 234 > typemapper
Definition: defoggerfeatures.h:23
size_t resX
Definition: defoggerfeatures.h:26
DefoggerFeaturizer(size_t resX, size_t resY, int32_t strideX, int32_t strideY, bool fullVision=false)
Definition: defoggerfeatures.h:30
Definition: frame.h:81
std::array< int, 234 > itypemapper
Definition: defoggerfeatures.h:24
torch::Tensor featurize(tc::Frame *frame, int mapX, int mapY, int playerId, at::Device device)
Definition: defoggerfeatures.cpp:85
Copypasted from defoggerFeaturizer on the defogger branch.
Definition: defoggerfeatures.h:21
static tc::Frame combine(const std::deque< tc::Frame > &frames, int playerId)
Definition: defoggerfeatures.cpp:12
size_t feature_size
Definition: defoggerfeatures.h:25
Main namespace for bot-related code.
Definition: areainfo.cpp:17
bool fullVision
Definition: defoggerfeatures.h:28
void featurize_unit(torch::Tensor &feats, tc::Unit &u, int, int)
Definition: defoggerfeatures.cpp:114
void inc_feature(torch::Tensor &feature, int32_t c, int32_t x, int32_t y) const
Definition: defoggerfeatures.cpp:126