Преобразование узла в Int [] - PullRequest
0 голосов
/ 27 ноября 2018

Я новичок в программировании на 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
...