// Breadth-first search public State attemptMove(State state, short stateSide, int position) { State tam = state.cloneState(); //attempt move up if (eligibleHumanMove(tam.getMaze(), tam.getHuman().getX(), tam.getHuman().getY(), tam.getHuman().getX() - 1, tam.getHuman().getY())) { //wall check int newX = tam.getHuman().getX() - 1; tam.setHuman(new Human(newX, tam.getHuman().getY())); tam = keyCheck(tam, tam.getHuman()); tam = tam.getHuman().testOfMummy(tam); if (tam.getStep() != -1) { //check if get killed if (fillMaze(tam, stateSide, position)) { // Exit check int xx = tam.getHuman().getX(); int yy = tam.getHuman().getY(); if ((xx == MainProcess.getxExit()) && (yy == MainProcess.getyExit())) { return(tam); } } } } tam = state.cloneState(); //attempt move down if (eligibleHumanMove(tam.getMaze(), tam.getHuman().getX(), tam.getHuman().getY(), tam.getHuman().getX() + 1, tam.getHuman().getY())) { //wall check int newX = tam.getHuman().getX() + 1; tam.setHuman(new Human(newX, tam.getHuman().getY())); tam = keyCheck(tam, tam.getHuman()); tam = tam.getHuman().testOfMummy(tam); if (tam.getStep() != -1) { //check if get killed if (fillMaze(tam, stateSide, position)) { //Exit check int xx = tam.getHuman().getX(); int yy = tam.getHuman().getY(); if ((xx == MainProcess.getxExit()) && (yy == MainProcess.getyExit())) { return(tam); } } } } tam = state.cloneState(); //attempt move left if (eligibleHumanMove(tam.getMaze(), tam.getHuman().getX(), tam.getHuman().getY(), tam.getHuman().getX(), tam.getHuman().getY() - 1)) { //wall check int newY = tam.getHuman().getY() - 1; tam.setHuman(new Human(tam.getHuman().getX(), newY)); tam = keyCheck(tam, tam.getHuman()); tam = tam.getHuman().testOfMummy(tam); if (tam.getStep() != -1) { //check if get killed if (fillMaze(tam, stateSide, position)) { //Exit check int xx = tam.getHuman().getX(); int yy = tam.getHuman().getY(); if ((xx == MainProcess.getxExit()) && (yy == MainProcess.getyExit())) { return(tam); } } } } tam = state.cloneState(); //attempt move right if (eligibleHumanMove(tam.getMaze(), tam.getHuman().getX(), tam.getHuman().getY(), tam.getHuman().getX(), tam.getHuman().getY() + 1)) { //wall check int newY = tam.getHuman().getY() + 1; tam.setHuman(new Human(tam.getHuman().getX(), newY)); tam = keyCheck(tam, tam.getHuman()); tam = tam.getHuman().testOfMummy(tam); if (tam.getStep() != -1) { //check if get killed if (fillMaze(tam, stateSide, position)) { //Exit check int xx = tam.getHuman().getX(); int yy = tam.getHuman().getY(); if ((xx == MainProcess.getxExit()) && (yy == MainProcess.getyExit())) { return(tam); } } } } tam = state.cloneState(); //attempt stay if (eligibleHumanMove(tam.getMaze(), tam.getHuman().getX(), tam.getHuman().getY(), tam.getHuman().getX(), tam.getHuman().getY())) { //wall check tam.getHuman().setX(tam.getHuman().getX()); //No Keycheck required tam = tam.getHuman().testOfMummy(tam); if (tam.getStep() != -1) { //check if get killed if (fillMaze(tam, stateSide, position)) { //Exit check is not required } } } return(null); }