BWAPI
UAlbertaBot_src/Projects/UAlbertaBot/Source/MapGrid.h
Go to the documentation of this file.
00001 #pragma once
00002 
00003 #include <Common.h>
00004 #include "micromanagement/MicroManager.h"
00005 
00006 class GridCell
00007 {
00008 public:
00009 
00010         int                                     timeLastVisited, timeLastOpponentSeen;
00011         UnitVector                      ourUnits;
00012         UnitVector                      oppUnits;
00013         BWAPI::Position         center;
00014 
00015         GridCell() :            timeLastVisited(0), timeLastOpponentSeen(0)  {}
00016         
00017 };
00018 
00019 
00020 class MapGrid {
00021 
00022         MapGrid();
00023         MapGrid(int mapWidth, int mapHeight, int cellSize);
00024 
00025         static MapGrid *                        instance;
00026 
00027         int                                                     cellSize;
00028         int                                                     mapWidth, mapHeight;
00029         int                                                     rows, cols;
00030         int                                                     lastUpdated;
00031 
00032         bool                                            contains(UnitVector & units, BWAPI::Unit * unit);
00033 
00034         std::vector< GridCell >         cells;
00035 
00036         void                                            calculateCellCenters();
00037 
00038         void                                            clearGrid();
00039         BWAPI::Position                         getCellCenter(int x, int y);
00040 
00041         BWAPI::Position                         naturalExpansion;
00042 
00043 public:
00044 
00045         // yay for singletons!
00046         static MapGrid *        getInstance();
00047 
00048         void                            update();
00049         void                            GetUnits(UnitVector & units, BWAPI::Position center, int radius, bool ourUnits, bool oppUnits);
00050         BWAPI::Position         getLeastExplored();
00051         BWAPI::Position         getNaturalExpansion();
00052 
00053         GridCell & getCellByIndex(int r, int c)         { return cells[r*cols + c]; }
00054         GridCell & getCell(BWAPI::Position pos)         { return getCellByIndex(pos.y() / cellSize, pos.x() / cellSize); }
00055         GridCell & getCell(BWAPI::Unit * unit)          { return getCell(unit->getPosition()); }
00056 };
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines