0

I am trying to create a puzzle solving algorithm with an A* search. everything should be right but I got a problem when I try to use one of the new "MoveUp MoveDown MoveLeft MoveRight" classes that I implemented i get an error that (the declared package "rushhour" does not match the expected package)

MoveDown

package rushhour;

import search.Action;
import search.State;

public class MoveDown implements Action{

    int carNum;
    int nPositions;

    public MoveDown(int carNum, int nPositions){
        this.carNum = carNum;
        this.nPositions = nPositions;
    }

    public int getCost() {
        return 1;
    }

    public String toString(){
        return "move down";
    }

}

then the class I use it in looks like this

package rushhour;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.lang.model.element.Element;

import search.Action;
import search.State;


public class GameState implements search.State {

    boolean[][] occupiedPositions;
    List<Car> cars; // target car is always the first one    
    int nrRows;
    int nrCols;
...
...
...
public boolean isLegal(Action action) {


        if(action instanceof MoveDown){

            Car car = cars.get(((MoveDown) action).carNum); 
            int nextPos = car.getRow() + car.getLength() + ((MoveDown) action).nPositions;

1 Answers1

2

Is is expected that your folder hierarchy matches your package hierarchy, (and vice-versa).

If you classpath is /src/main/java/ your files should look like this:

/src/main/java/rushour/GameState.java
/src/main/java/rushour/MoveDown.java
/src/main/java/search/Action.java
/src/main/java/search/State.java
AllirionX
  • 1,073
  • 6
  • 13
  • I would say it the other way around, that the folder hierarchy must match the package hierarchy. Guess that's just a matter of perspective. :-) – Andreas Nov 06 '19 at 22:32
  • @Andreas True! I updated my answer with this critical information. – AllirionX Nov 06 '19 at 22:34