BWAPI
UAlbertaBot_src/Projects/UAlbertaBot/Source/MapTools.h
Go to the documentation of this file.
00001 #pragma once
00002 
00003 #include "Common.h"
00004 #include <vector>
00005 #include "BWAPI.h"
00006 #include "DistanceMap.hpp"
00007 #include "UnitInfoState.h"
00008 #include "base/BuildingPlacer.h"
00009 
00010 // provides useful tools for analyzing the starcraft map
00011 // calculates connectivity and distances using flood fills
00012 class MapTools
00013 {
00014         // holds distance maps from enemy base and my base
00015         DistanceMap                     enemyBaseMap;
00016         DistanceMap                     myBaseMap;
00017 
00018         // whether or not we have calculated 
00019         bool                            calculatedEnemyDistance;
00020         bool                            calculatedMyDistance;
00021 
00022         // the map stored at TilePosition resolution 
00023         // values are 0/1 for walkable or not walkable
00024         std::vector<bool>       map;
00025 
00026         // map that stores whether a unit is on this position
00027         std::vector<bool>       units;
00028 
00029         // the fringe vector which is used as a sort of 'open list'
00030         std::vector<int>        fringe;
00031 
00032         // stores a 'region number'
00033         // two tiles are connected iff their region numbers are the same
00034         std::vector<int>        connected;
00035 
00036         // the size of the map
00037         int                                     rows,
00038                                                 cols;
00039 
00040         // the static instance for this singleton
00041         static                          MapTools * instance;
00042 
00043         // constructor for MapTools
00044         MapTools();
00045         ~MapTools();
00046 
00047         // return the index of the 1D array from (row,col)
00048         inline int getIndex(int row, int col);
00049 
00050         bool unexplored(DistanceMap & dmap, const int index) const;
00051         
00052         bool unconnected(const int index) const;
00053         
00054         // resets the distance and fringe vectors, call before each search
00055         void reset();
00056 
00057         // reads in the map data from bwapi and stores it in our map format
00058         void setBWAPIMapData();
00059         
00060         // reset the fringe
00061         void resetFringe();
00062         
00063 public:
00064 
00065         static MapTools *       MapTools::getInstance();
00066 
00067         BWAPI::TilePosition getNextExpansion();
00068 
00069         void update();
00070         void drawMyRegion();
00071         void computeConnectedRegions();
00072 
00073         // computes walk distance from Position P to all other points on the map
00074         void computeDistance(DistanceMap & dmap, const BWAPI::Position p);
00075 
00076         // does the dynamic programming search
00077         void search(DistanceMap & dmap, const int sR, const int sC);
00078         
00079         // computes connectivity for the map
00080         void fill(const int index, const int region);
00081 
00082         // get distance to various bases
00083         int     getEnemyBaseDistance(BWAPI::Position p);
00084         int     getMyBaseDistance(BWAPI::Position p);
00085         BWAPI::Position getEnemyBaseMoveTo(BWAPI::Position p);
00086 };
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines