本文整理匯總了Java中pacman.game.Constants.DM類的典型用法代碼示例。如果您正苦於以下問題:Java DM類的具體用法?Java DM怎麽用?Java DM使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
DM類屬於pacman.game.Constants包,在下文中一共展示了DM類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getClosestNodeIndexFromNodeIndex
import pacman.game.Constants.DM; //導入依賴的package包/類
/**
* Gets the closest node index from node index.
*
* @param fromNodeIndex the from node index
* @param targetNodeIndices the target node indices
* @param distanceMeasure the distance measure
* @return the closest node index from node index
*/
public int getClosestNodeIndexFromNodeIndex(int fromNodeIndex,int[] targetNodeIndices,DM distanceMeasure)
{
double minDistance=Integer.MAX_VALUE;
int target=-1;
for(int i=0;i<targetNodeIndices.length;i++)
{
double distance=0;
distance=getDistance(targetNodeIndices[i],fromNodeIndex,distanceMeasure);
if(distance<minDistance)
{
minDistance=distance;
target=targetNodeIndices[i];
}
}
return target;
}
示例2: getFarthestNodeIndexFromNodeIndex
import pacman.game.Constants.DM; //導入依賴的package包/類
/**
* Gets the farthest node index from node index.
*
* @param fromNodeIndex the from node index
* @param targetNodeIndices the target node indices
* @param distanceMeasure the distance measure
* @return the farthest node index from node index
*/
public int getFarthestNodeIndexFromNodeIndex(int fromNodeIndex,int[] targetNodeIndices,DM distanceMeasure)
{
double maxDistance=Integer.MIN_VALUE;
int target=-1;
for(int i=0;i<targetNodeIndices.length;i++)
{
double distance=0;
distance=getDistance(targetNodeIndices[i],fromNodeIndex,distanceMeasure);
if(distance>maxDistance)
{
maxDistance=distance;
target=targetNodeIndices[i];
}
}
return target;
}
示例3: getNextMoveTowardsTarget
import pacman.game.Constants.DM; //導入依賴的package包/類
/**
* Gets the next move towards target.
*
* @param fromNodeIndex the from node index
* @param toNodeIndex the to node index
* @param distanceMeasure the distance measure
* @return the next move towards target
*/
public MOVE getNextMoveTowardsTarget(int fromNodeIndex,int toNodeIndex,DM distanceMeasure)
{
MOVE move=null;
double minDistance=Integer.MAX_VALUE;
for(Entry<MOVE,Integer> entry : currentMaze.graph[fromNodeIndex].neighbourhood.entrySet())
{
double distance=getDistance(entry.getValue(),toNodeIndex,distanceMeasure);
if(distance<minDistance)
{
minDistance=distance;
move=entry.getKey();
}
}
return move;
}
示例4: getNextMoveAwayFromTarget
import pacman.game.Constants.DM; //導入依賴的package包/類
/**
* Gets the next move away from target.
*
* @param fromNodeIndex the from node index
* @param toNodeIndex the to node index
* @param distanceMeasure the distance measure
* @return the next move away from target
*/
public MOVE getNextMoveAwayFromTarget(int fromNodeIndex,int toNodeIndex,DM distanceMeasure)
{
MOVE move=null;
double maxDistance=Integer.MIN_VALUE;
for(Entry<MOVE,Integer> entry : currentMaze.graph[fromNodeIndex].neighbourhood.entrySet())
{
double distance=getDistance(entry.getValue(),toNodeIndex,distanceMeasure);
if(distance>maxDistance)
{
maxDistance=distance;
move=entry.getKey();
}
}
return move;
}
示例5: getApproximateNextMoveTowardsTarget
import pacman.game.Constants.DM; //導入依賴的package包/類
/**
* Gets the approximate next move towards target not considering directions opposing the last move made.
*
* @param fromNodeIndex The node index from which to move (i.e., current position)
* @param toNodeIndex The target node index
* @param lastMoveMade The last move made
* @param distanceMeasure The distance measure required (Manhattan, Euclidean or Straight line)
* @return The approximate next move towards target (chosen greedily)
*/
public MOVE getApproximateNextMoveTowardsTarget(int fromNodeIndex,int toNodeIndex,MOVE lastMoveMade, DM distanceMeasure)
{
MOVE move=null;
double minDistance=Integer.MAX_VALUE;
for(Entry<MOVE,Integer> entry : currentMaze.graph[fromNodeIndex].allNeighbourhoods.get(lastMoveMade).entrySet())
{
double distance=getDistance(entry.getValue(),toNodeIndex,distanceMeasure);
if(distance<minDistance)
{
minDistance=distance;
move=entry.getKey();
}
}
return move;
}
示例6: getApproximateNextMoveAwayFromTarget
import pacman.game.Constants.DM; //導入依賴的package包/類
/**
* Gets the approximate next move away from a target not considering directions opposing the last move made.
*
* @param fromNodeIndex The node index from which to move (i.e., current position)
* @param toNodeIndex The target node index
* @param lastMoveMade The last move made
* @param distanceMeasure The distance measure required (Manhattan, Euclidean or Straight line)
* @return The approximate next move towards target (chosen greedily)
*/
public MOVE getApproximateNextMoveAwayFromTarget(int fromNodeIndex,int toNodeIndex,MOVE lastMoveMade, DM distanceMeasure)
{
MOVE move=null;
double maxDistance=Integer.MIN_VALUE;
for(Entry<MOVE,Integer> entry : currentMaze.graph[fromNodeIndex].allNeighbourhoods.get(lastMoveMade).entrySet())
{
double distance=getDistance(entry.getValue(),toNodeIndex,distanceMeasure);
if(distance>maxDistance)
{
maxDistance=distance;
move=entry.getKey();
}
}
return move;
}
示例7: atacar
import pacman.game.Constants.DM; //導入依賴的package包/類
/**
*Mirar si se puede llegar al fantasma comible mas cercano
*Antes de que pueda llegar ningun fantasma no comible a el
*Si tal, ir a comerselo, si no, llamada a farmear
*/
public MOVE atacar(){
boolean atk = true;
Ghost g = getClosestEdibleGhost(getPacmanCurrentNodeIndex());
if (g == null)
return MOVE.NEUTRAL;
int closestg = g.currentNodeIndex;
double distpmg = getDistance(getPacmanCurrentNodeIndex(), closestg, DM.PATH);
for (Ghost ghost : this.ghosts.values())
{
if (!ghost.isEdible() && !ghost.isInLair())
{
if(getDistance(closestg, ghost.currentNodeIndex, DM.PATH) < distpmg)
atk = false;
}
}
if(atk)
return getNextMoveTowardsTarget(getPacmanCurrentNodeIndex(), closestg, DM.PATH);
else{
return MOVE.NEUTRAL;
}
}
示例8: atacarCheta
import pacman.game.Constants.DM; //導入依賴的package包/類
/**
*Mirar si se puede llegar al fantasma comible mas cercano
*Antes de que pueda llegar ningun fantasma no comible a el
*Si tal, ir a comerselo, si no, llamada a farmear
*/
public MOVE atacarCheta(){
boolean atk = true;
Ghost g = getClosestEdibleGhost(getPacmanCurrentNodeIndex());
if (g == null)
return farmear();
int closestg = g.currentNodeIndex;
double distpmg = getDistance(getPacmanCurrentNodeIndex(), closestg, DM.PATH);
for (Ghost ghost : this.ghosts.values())
{
if (!ghost.isEdible() && !ghost.isInLair())
{
if(getDistance(closestg, ghost.currentNodeIndex, DM.PATH) < distpmg)
atk = false;
}
}
if(atk)
return getNextMoveTowardsTarget(getPacmanCurrentNodeIndex(), closestg, DM.PATH);
else{
return farmear();
}
}
示例9: eat
import pacman.game.Constants.DM; //導入依賴的package包/類
private MOVE eat(Game game) {
System.out.println("EATING!");
int[] pills=game.getPillIndices();
int pill = 0;
int best = 0;
int currentNode=game.getPacmanCurrentNodeIndex();
MOVE move = game.getPacmanLastMoveMade();
for(int p : pills){
if(game.isPillStillAvailable(p)){
int pillDistance = game.getShortestPathDistance(currentNode, p);
int ghostDistance = distanceToGhost(game, p);
int value = ghostDistance - (pillDistance * 2);
if (value > best){
best = value;
pill = p;
}
}
}
return game.getApproximateNextMoveTowardsTarget(currentNode, pill, move, DM.MANHATTAN);
}
示例10: getClosestPillOrPowerPill
import pacman.game.Constants.DM; //導入依賴的package包/類
public int getClosestPillOrPowerPill(int currentPos) {
int[] activePills=this.getActivePillsIndices();
int[] activePowerPills=this.getActivePowerPillsIndices();
int[] targetNodeIndices = new int[activePills.length + activePowerPills.length];
System.arraycopy(activePills, 0, targetNodeIndices, 0, activePills.length);
System.arraycopy(activePowerPills, 0, targetNodeIndices, activePills.length, activePowerPills.length);
return this.getClosestNodeIndexFromNodeIndex(currentPos, targetNodeIndices, DM.PATH);
}
示例11: getDistance
import pacman.game.Constants.DM; //導入依賴的package包/類
/**
* Gets the distance.
*
* @param fromNodeIndex the from node index
* @param toNodeIndex the to node index
* @param distanceMeasure the distance measure
* @return the distance
*/
public double getDistance(int fromNodeIndex,int toNodeIndex,DM distanceMeasure)
{
switch(distanceMeasure)
{
case PATH: return getShortestPathDistance(fromNodeIndex,toNodeIndex);
case EUCLID: return getEuclideanDistance(fromNodeIndex,toNodeIndex);
case MANHATTAN: return getManhattanDistance(fromNodeIndex,toNodeIndex);
}
return -1;
}
示例12: getDirectionTowardsClosestEdibleGhost
import pacman.game.Constants.DM; //導入依賴的package包/類
/**
* Returns the direction towards the closest edible ghost (NEUTRAL if no edible ghosts avaiable)
*/
public MOVE getDirectionTowardsClosestEdibleGhost(int pacmanNode){
MOVE ret = MOVE.NEUTRAL;
Ghost g = getClosestEdibleGhost(pacmanNode);
if (g != null)
ret = getNextMoveTowardsTarget(pacmanNode, g.currentNodeIndex, DM.PATH);
return ret;
}
示例13: getDirectionAwayFromClosestNonEdibleGhost
import pacman.game.Constants.DM; //導入依賴的package包/類
/**
* Returns the movement opposed to the direction of the closest non edible ghost
*/
public MOVE getDirectionAwayFromClosestNonEdibleGhost(int pacmanNode){
MOVE ret = MOVE.NEUTRAL;
Ghost g = getClosestNonEdibleGhost(pacmanNode);
if (g != null)
ret = getNextMoveAwayFromTarget(pacmanNode, g.currentNodeIndex, DM.PATH);
return ret;
}
示例14: getDirectionTowardsClosestPowerPill
import pacman.game.Constants.DM; //導入依賴的package包/類
/**
* Returns the movement towards the closest PowerPill
*/
public MOVE getDirectionTowardsClosestPowerPill(int pacmanNode){
MOVE ret = MOVE.NEUTRAL;
int cpp = getClosestPowerPill(pacmanNode);
if (cpp != -1)
ret = getNextMoveTowardsTarget(pacmanNode, cpp, DM.PATH);
return ret;
}
示例15: getDirectionTowardsClosestPill
import pacman.game.Constants.DM; //導入依賴的package包/類
/**
* Returns the movement towards the closest Pill
*/
public MOVE getDirectionTowardsClosestPill(int pacmanNode){
MOVE ret = MOVE.NEUTRAL;
int cpp = getClosestPill(pacmanNode);
if (cpp != -1)
ret = getNextMoveTowardsTarget(pacmanNode, cpp, DM.PATH);
return ret;
}