BWAPI
Public Types | Public Member Functions | Private Attributes
EnhancedSide Class Reference

#include <EnhancedSide.h>

Collaboration diagram for EnhancedSide:
Collaboration graph
[legend]

List of all members.

Public Types

enum  Orientation { left, top, right, bottom }

Public Member Functions

 EnhancedSide (pair< BWAPI::Position, BWAPI::Position > endPoints, Orientation orientation)
 ~EnhancedSide (void)
pair< BWAPI::Position,
BWAPI::Position > 
getEndPoints (void)
vector< BWAPI::TilePosition > getTilePositions (void)
Orientation getOrientation (void)
bool isHorizontal (void)
int checkCoverage (EnhancedSide coveringSide, vector< EnhancedSide > *sidesNotCovered)
int checkGap (void)
void drawSide (BWAPI::Color color)
void drawTiles (BWAPI::Color color)

Private Attributes

Orientation orientation
pair< BWAPI::Position,
BWAPI::Position > 
endPoints
pair< BWAPI::TilePosition,
BWAPI::TilePosition > 
endTilePositions
vector< BWAPI::TilePosition > tilePositions
bool horizontal

Detailed Description

Definition at line 15 of file EnhancedSide.h.


Member Enumeration Documentation

Enumerator:
left 
top 
right 
bottom 

Definition at line 18 of file EnhancedSide.h.


Constructor & Destructor Documentation

EnhancedSide::EnhancedSide ( pair< BWAPI::Position, BWAPI::Position >  endPoints,
Orientation  orientation 
)

Definition at line 15 of file EnhancedSide.cpp.

References bottom, endPoints, endTilePositions, horizontal, orientation, right, tilePositions, and top.

Referenced by checkCoverage().

{
        bool xMatch, yMatch;
        bool down, right;
        BWAPI::TilePosition * startTile, * endTile;
        BWAPI::TilePosition currTile;

        down = right = false;

        xMatch = (endPoints.first.x() == endPoints.second.x());
        yMatch = (endPoints.first.y() == endPoints.second.y());

        /* ensure points share an x or y value */
        assert( xMatch || yMatch );

        /* set our endPoints */
        this->endPoints = endPoints;
        this->orientation = orientation;

        if (orientation == top || orientation == bottom) {
                horizontal = true;
        }
        else {
                horizontal = false;
        }

        /* get the end point tile positions */
        endTilePositions.first = BWAPI::TilePosition(endPoints.first);
        endTilePositions.second = BWAPI::TilePosition(endPoints.second);

        /* check to see if same tile, this is OK */
        if (endTilePositions.first == endTilePositions.second) {
                tilePositions.push_back(endTilePositions.first);
                /* nothing else to do */
                return;
        }

        /* establish the start tile position and move down or right */
        if (yMatch) { // move on x

                right = true;

                if (endTilePositions.first.x() < endTilePositions.second.x()) {
                        startTile = &endTilePositions.first;
                        endTile = &endTilePositions.second;
                }
                else {
                        startTile = &endTilePositions.second;
                        endTile = &endTilePositions.first;
                }
        }
        else { // move on y

                down = true;

                if (endTilePositions.first.y() < endTilePositions.second.y()) {
                        startTile = &endTilePositions.first;
                        endTile = &endTilePositions.second;
                }
                else {
                        startTile = &endTilePositions.second;
                        endTile = &endTilePositions.first;
                }
        }

        /* add tiles in order */
        tilePositions.push_back(*startTile);
        currTile = *startTile;

        while (currTile != *endTile) {

                if (right) {
                        currTile.x() += 1;
                }
                else {
                        currTile.y() += 1;
                }
                tilePositions.push_back(currTile);
        }
        /* endTile will already be added, don't add again! */

}

Here is the caller graph for this function:

Definition at line 98 of file EnhancedSide.cpp.

{
}

Member Function Documentation

int EnhancedSide::checkCoverage ( EnhancedSide  coveringSide,
vector< EnhancedSide > *  sidesNotCovered 
)

Definition at line 121 of file EnhancedSide.cpp.

References endPoints, EnhancedSide(), horizontal, and orientation.

Referenced by TacticalBuildingPlacer::chokepointBuildPatternSearch().

{

        int lengthNotCovered = 0;
        int xLeft, xRight, xCovLeft, xCovRight;
        int yTop, yBottom, yCovTop, yCovBottom;
        int diff;
        pair<BWAPI::Position, BWAPI::Position> newEndPoints;
        bool getSides;

        // must be parallel
        if (coveringSide.horizontal != horizontal) {
                return -1;
        }

        getSides = true;

        if (sidesNotCovered == NULL) {
                getSides = false;
        }

        xLeft = endPoints.first.x();
        xRight = endPoints.second.x();
        xCovLeft = coveringSide.endPoints.first.x();
        xCovRight = coveringSide.endPoints.second.x();

        yTop = endPoints.first.y();
        yBottom = endPoints.second.y();
        yCovTop = coveringSide.endPoints.first.y();
        yCovBottom = coveringSide.endPoints.second.x();

        // if horizontal compare x
        if (horizontal) {
                // check left end
                if (xCovLeft > xLeft) {
                        diff = xCovLeft - xLeft;
                        lengthNotCovered += diff;
                        if (getSides) {
                                newEndPoints.first.x() = xLeft;
                                newEndPoints.second.x() = xCovLeft;
                                // use y val and orientation of the side trying to cover
                                newEndPoints.first.y() = yTop;
                                newEndPoints.second.y() = yTop;
                                sidesNotCovered->push_back(EnhancedSide(newEndPoints, orientation));
                        }
                }

                // check right end
                if (xCovRight < xRight) {
                        diff = xRight - xCovRight;
                        lengthNotCovered += diff;
                        if (getSides) {
                                newEndPoints.first.x() = xCovRight;
                                newEndPoints.second.x() = xRight;
                                // use y val and orientation of the side trying to cover
                                newEndPoints.first.y() = yTop;
                                newEndPoints.second.y() = yTop;
                                sidesNotCovered->push_back(EnhancedSide(newEndPoints, orientation));
                        }
                }
        }

        // if vertical compare y
        else {
                // check top end
                if (yCovTop > yTop) {
                        diff = yCovTop - yTop;
                        lengthNotCovered += diff;
                        if (getSides) {
                                newEndPoints.first.y() = yTop;
                                newEndPoints.second.y() = yCovTop;
                                // use x val and orientation of the side trying to cover
                                newEndPoints.first.x() = xLeft;
                                newEndPoints.second.x() = xLeft;
                                sidesNotCovered->push_back(EnhancedSide(newEndPoints, orientation));
                        }
                }

                // check bottom end
                if (yCovBottom < yBottom) {
                        diff = yBottom - yCovBottom;
                        lengthNotCovered += diff;
                        if (getSides) {
                                newEndPoints.first.y() = yCovBottom;
                                newEndPoints.second.y() = yBottom;
                                // use x val and orientation of the side trying to cover
                                newEndPoints.first.x() = xLeft;
                                newEndPoints.second.x() = xLeft;
                                sidesNotCovered->push_back(EnhancedSide(newEndPoints, orientation));
                        }
                }
        }

        return lengthNotCovered;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int EnhancedSide::checkGap ( void  )

Definition at line 223 of file EnhancedSide.cpp.

References bottom, BWAPI::Broodwar, getTilePositions(), left, orientation, right, and top.

Referenced by TacticalBuildingPlacer::chokepointBuildPatternSearch().

{
        vector<BWAPI::TilePosition> tiles = this->getTilePositions();
        BWAPI::TilePosition currentTile;
        int tileLength = (int)tiles.size();
        int xDir, yDir;
        int currentNumTiles;
        int minNumTiles = 0;
        bool unbuildableTileNotFound;

        // get xDir and yDir based on orientation
        if (orientation == EnhancedSide::left) {
                xDir = -1;
                yDir = 0;
        }
        else if (orientation == EnhancedSide::top) {
                xDir = 0;
                yDir = -1;
        }
        else if (orientation == EnhancedSide::right) {
                xDir = +1;
                yDir = 0;
        }
        else if (orientation == EnhancedSide::bottom) {
                xDir = 0;
                yDir = +1;
        }

        for (int m = 0; m < tileLength; ++m) {
                currentTile = tiles[m];
                // reset
                unbuildableTileNotFound = true;
                currentNumTiles = 0;

                while (unbuildableTileNotFound) {
                        // increment
                        currentTile.x() += xDir;
                        currentTile.y() += yDir;

                        // check tile
                        if (BWAPI::Broodwar->isBuildable(currentTile, true)) {
                                // add to this rounds gap
                                currentNumTiles++;
                        }
                        else {
                                // found the wall
                                unbuildableTileNotFound = false;
                                break;
                        }
                }

                // check for minimum
                if (m == 0) {
                        minNumTiles = currentNumTiles;
                }
                else if (currentNumTiles < minNumTiles) {
                        minNumTiles = currentNumTiles;
                }
        }

        return minNumTiles;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void EnhancedSide::drawSide ( BWAPI::Color  color)

Definition at line 286 of file EnhancedSide.cpp.

References BWAPI::Broodwar, and endPoints.

{
        BWAPI::Broodwar->drawLineMap(endPoints.first.x(), endPoints.first.y(), 
                endPoints.second.x(), endPoints.second.y(), color); 
}
void EnhancedSide::drawTiles ( BWAPI::Color  color)

Definition at line 292 of file EnhancedSide.cpp.

References EnhancedUI::drawTilePosition(), and tilePositions.

{
        EnhancedUI * eui = new EnhancedUI();
        for (int m = 0; m < (int) tilePositions.size(); ++m) {
                eui->drawTilePosition(tilePositions[m], color);
        }
        delete(eui);
}

Here is the call graph for this function:

pair< BWAPI::Position, BWAPI::Position > EnhancedSide::getEndPoints ( void  )

Definition at line 102 of file EnhancedSide.cpp.

References endPoints.

{
        return endPoints;
}

Definition at line 110 of file EnhancedSide.cpp.

References orientation.

Referenced by TacticalBuildingPlacer::chokepointBuildPatternSearch().

{
        return orientation;
}

Here is the caller graph for this function:

vector< BWAPI::TilePosition > EnhancedSide::getTilePositions ( void  )

Definition at line 106 of file EnhancedSide.cpp.

References tilePositions.

Referenced by checkGap().

{
        return tilePositions;
}

Here is the caller graph for this function:

bool EnhancedSide::isHorizontal ( void  )

Definition at line 114 of file EnhancedSide.cpp.

References horizontal.

Referenced by TacticalBuildingPlacer::chokepointBuildPatternSearch().

{
        return horizontal;
}

Here is the caller graph for this function:


Member Data Documentation

pair<BWAPI::Position, BWAPI::Position> EnhancedSide::endPoints [private]

Definition at line 36 of file EnhancedSide.h.

Referenced by checkCoverage(), drawSide(), EnhancedSide(), and getEndPoints().

pair<BWAPI::TilePosition, BWAPI::TilePosition> EnhancedSide::endTilePositions [private]

Definition at line 37 of file EnhancedSide.h.

Referenced by EnhancedSide().

bool EnhancedSide::horizontal [private]

Definition at line 40 of file EnhancedSide.h.

Referenced by checkCoverage(), EnhancedSide(), and isHorizontal().

Definition at line 35 of file EnhancedSide.h.

Referenced by checkCoverage(), checkGap(), EnhancedSide(), and getOrientation().

vector<BWAPI::TilePosition> EnhancedSide::tilePositions [private]

Definition at line 38 of file EnhancedSide.h.

Referenced by drawTiles(), EnhancedSide(), and getTilePositions().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines