Exemplo n.º 1
0
void MyastarPlanner::addNeighborCellsToOpenList(set<coupleOfCells> & OPL, vector <unsigned int> neighborCells, unsigned int parent, float gCostParent, unsigned int goalCell, double max) //,float tBreak)
{
       set<coupleOfCells>::iterator it;
        //vector <coupleOfCells> neighborsCellsOrdered;
        for(uint i=0; i< neighborCells.size(); i++)
        {
          coupleOfCells CP;
          CP.index=neighborCells[i]; //insert the neighbor cell
          CP.parent=parent; //insert the parent cell
          //calculate the gCost
          CP.gCost=gCostParent+getMoveCost(parent,neighborCells[i]);

          //calculate the hCost: Euclidian distance from the neighbor cell to the goalCell
          CP.hCost=calculateHCost(neighborCells[i],goalCell);
          //calculate fcost
		  double w=(CP.hCost/max)*3+1;
		  //double w=1;
          CP.fCost=CP.gCost+w*CP.hCost;
         // neighborsCellsOrdered.push_back(CP);
         
         	it = getPositionInList(OPL, CP.index);
				if( it == openList.end() )
					OPL.insert(CP);
				else if (CP.fCost < it->fCost and CP.parent != it->parent){
					OPL.erase(it);
					OPL.insert(CP);
				}
        }
      }
Exemplo n.º 2
0
bool PlayerBot::canMove()
{
    return getMoveCost() <= getActionPoints();
}
Exemplo n.º 3
0
void PlayerBot::moved()
{
    pointLeft -= getMoveCost();
    pointLeft = pointLeft < 0 ? 0 : pointLeft;
}