All pastes #278955 Raw Edit

BoardGame

public java v1 · immutable
·published 2006-12-14 15:46 UTC
rendered paste body
//Zachary Fitzsimmonsimport java.io.*;import java.util.*;public class BoardGame{  public static void main(String[] args) throws IOException  {    Scanner scan = new Scanner(new File("board.dat"));    boolean[][] map = new boolean[6][6];    Stack<Location> sloc = new Stack<Location>();    Queue<Location> qloc = new LinkedList<Location>();    Stack<Queue<Location>> s_qloc = new Stack<Queue<Location>>();    Integer x = 0, y = 0;        String temp;    Integer i, j;    for(y = 0; y < 6; y++)    {      temp = scan.nextLine();      System.out.println(temp);      for(x = 0; x < 6; x++)      {        map[y][x] = temp.charAt(x) == 'x' ? true : false; //X  is black and also true      }    }    for(i = 0; i < map.length; i++)    {      for(j = 0; j < map[i].length; j++)      {        System.out.print(map[i][j]);      }    }    findPaths(map, sloc, qloc, s_qloc, 0, 0);        System.out.println(s_qloc);    while(!s_qloc.empty())    {      qloc = s_qloc.pop();      while(!qloc.isEmpty())      {        System.out.println(qloc.remove());      }    }  }  public static void findPaths(boolean[][] map, Stack<Location> sloc, Queue<Location> qloc,                               Stack<Queue<Location>> s_qloc, Integer x, Integer y)  {    if(x <  5 && y < 5)    {      if(map[y][x] && map[y+1][x])      {        qloc.add(new Location(x, ++y));        findPaths(map, sloc, qloc, s_qloc, x, y);      }      if(map[y][x] && map[y][x+1])      {        qloc.add(new Location(++x, y));        findPaths(map, sloc, qloc, s_qloc, x, y);      }    }    else    {      if(x == 5 && y == 5)      {        s_qloc.push(qloc);      }    }  }  public <E> Queue<E> copy(Queue<E> q)  {    Queue<E> qCopy = new LinkedList<E>();    E o = q.peek();    E e = q.remove();    while(e != null)    {      qCopy.add(e);      q.add(e);      if(q.peek() == o)        e = null;      else        e = q.remove();    }    return qCopy;  }}