
-----------------------------------
Panphobia
Fri Dec 21, 2012 10:25 pm

Help question
-----------------------------------
Since the next 2 dwites have been canceled i have just been doing all the questions, and I hope to do them all during the winter break, I have had one problem with this question http://dwite.org/questions/haunted_house.html , I will explain what i think is wrong, when a map like this [code]....... 
.##a##. 
.#***#. 
.##B##. 
.#*###. 
.#*d*#. 
#*#.... [/code] comes along, you have to stray from the shortest path in order to get the other candies, but my program counts the candies but not the path that they take, if they are not in the shortest path that is, here is my code, if you just hint me to the problem I will definetely be able to fix it [code]import java.util.*;
import java.io.*;

public class BFSDFSV4 {
    static int n1 = -1, candy3 = 0, cCount = 0;
    static int MIN;
    static int candy=0;
    public static void main(String[] args) throws IOException {
        Scanner q = new Scanner(new File("C:\\Users\\branko\\Desktop\\Java\\BFSDFSV4\\src\\bfsdfsv4\\DATA5.txt"));
        for (int a = 0; a < 5; a++) {
            cCount = 0;
            candy=0;
            candy3 = 0;
            int startX = -1, startY = -1;
            char maze[][];
            n1 = Integer.parseInt(q.nextLine());
            maze = new char[n1][n1];
            for (int i = 0; i < n1; i++) {
                String s = q.nextLine();
                for (int j = 0; j < n1; j++) {
                    if (s.charAt(j) == 'B') {
                        startX = i;
                        startY = j;
                    }
                    if (s.charAt(j) == '*') {
                        cCount++;
                    }
                    maze[i][j] = s.charAt(j);
                }
            }
            MIN=0;
           // traverse(startX, startY, maze, 0, 0);
            int lol = bfs(maze,startX,startY);
            System.out.println(candy +" "+lol);
        }
    }
    //need to tweak
    public static int bfs(char[][]maze,int xStart,int yStart){
        
        Queue queue = new LinkedList();
        int[] start = {xStart,yStart,0};
        queue.add(start);
        while(queue.peek()!=null){
            int[]array=queue.remove();
            int x=array[0];int y=array[1];int steps=array[2];
            if(x>n1-1||y>n1-1||xcCount){
                candy = cCount;
                return MIN;
            }
            if(maze[x][y]>='a'&&maze[x][y] n1 - 1 || y < 0 || y > n1 - 1) {
            return;
        }
        if (maze[x][y] == '#') {
            return;
        }
        if (maze[x][y] == '*') {
            totCandies++;
        }
        if (maze[x][y] >= 'a' && maze[x][y]  n1 - 1 || y > n1 - 1 || x < 0 || y < 0) {
                continue;
            }
            if (maze[x][y] == '#') {
                continue;
            }

            if (maze[x][y] == '*') {
                //MIN += array.steps;
                maze[x][y] = '.';
                return array;
            }
//            if (candy > cCount) {
//                candy = cCount;
//                return array;
//            }
//            if (maze[x][y] >= 'a' && maze[x][y] 