All pastes #278490 Raw Edit

BoardGame

public text v1 · immutable
·published 2006-12-14 03:10 UTC
rendered paste body
//Zachary Fitzsimmons

import 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;

    

    while(scan.hasNext())

    {

      map[y][x] = scan.next().charAt(0) == 'X' ? true : false; //X  is black and also true

      

      if(x == 6)

      {

        y++;

        x %= 6;

      }

    }

    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(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);

    }

    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;

  }

}