BWAPI
SPAR/AIModule/SparAIModule/PerceptualState/InfluenceMap/Visibility.h
Go to the documentation of this file.
00001 #pragma once
00002 #include "InfluenceMap.h"
00003 #include <BWAPI.h>
00004 #include <cassert>
00005 
00006 struct Visibility
00007 {
00008   bool visible;
00009   unsigned long lastVisited;
00010 
00011   Visibility() { reset(); }
00012 
00013   void reset()
00014   {
00015     visible = false;
00016     lastVisited = 0L;
00017   }
00018 
00019   void display(int x, int y, int w, int h, BWAPI::Player* player) const
00020   {
00021     // do nothing
00022     unused(x);
00023     unused(y);
00024     unused(w);
00025     unused(h);
00026     unused(player);
00027   }
00028 
00029   bool isNull() const { return !visible; }
00030 
00031   static void update(InfluenceMap<Visibility>& map)
00032   {
00033     assert(map.getPlayer() == BWAPI::Broodwar->self());
00034 
00035     assert(map.getWidth()  == BWAPI::Broodwar->mapWidth()
00036         && map.getHeight() == BWAPI::Broodwar->mapHeight());
00037 
00038     for (size_t y=0; y<map.getHeight(); ++y)
00039     {
00040       for (size_t x=0; x<map.getWidth(); ++x)
00041       {
00042         Visibility influence = map.getInfluence(x, y);
00043         influence.update(BWAPI::Broodwar->isVisible(x, y));
00044         map.setInfluence(x, y, influence);
00045       }
00046     }
00047   }
00048 
00049 private:
00050   void update(bool v)
00051   {
00052     lastVisited = (!v && !visible) ? lastVisited+1 : 0L;
00053     visible = v;
00054   }
00055 };
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines