我是Java编程的新手,目前正在pacman Ai控制器上工作。我们获得了使用方法List(Node) getPillNodes
的基本代码,该方法返回带药丸的所有节点索引。所以我想做的就是告诉pacman跟踪有药丸的节点,但是我唯一的想法是这样做:
int[] pills=game.getPillNodes();
int[] powerPills=game.getPowerPillIndices();
ArrayList<Integer> targets=new ArrayList<Integer>();
for(int i=0;i<pills.length;i++) //check which pills are available
if(game.checkPill(i))
targets.add(pills[i]); etc...
我将如何将List
转换为int []
,以便可以使用上面编写的代码。请问任何需要澄清的问题。如果错过任何事情,我深表歉意。在此先感谢!
这是节点类
int getX();
int getY();
boolean isPill();
boolean isPowerPill();
boolean isJunction();
int getNumNeighbors();
Node getNeighbor(int inDirection);
List<Node> getNeighbors();
int getPathDistance(Node to);
static int getReverse(int direction)
{
switch(direction)
{
case 0: return 2;
case 1: return 3;
case 2: return 0;
case 3: return 1;
}
return 4;
}
}
这是迷宫课:
String getName(); //返回迷宫的名称
Node getInitialAttackerPosition(); // Returns the starting position of the hero
Node getInitialDefendersPosition(); // Returns the starting position of the defenders (i.e., first node AFTER leaving the lair)
Node getNode(int x, int y); // Get Node from X,Y position
int getNumberPills(); // Total number of pills in the maze
int getNumberPowerPills(); // Total number of power pills in the maze
int getNumberOfNodes(); // Total number of nodes in the graph (i.e., those with pills, power pills and those that are empty)
List<Node> getPillNodes(); // Returns the indices to all the nodes that have pills
List<Node> getPowerPillNodes(); // Returns all the nodes that have power pills
List<Node> getJunctionNodes(); // Returns the indices to all the nodes that are junctions