/*
  astar.cc
  your name here

  CSCI 4964/6963 Assignment 4
  out Friday March 19, due Monday April 5

*/

#include <stdio.h>

const int MaxNodes = 100;

int nnodes;			// number of nodes (0 to nnodes-1)
bool adj[MaxNodes][MaxNodes];	// adjacency matrix (true = connected)
float x[MaxNodes], y[MaxNodes];	// x and y coordinates of each node

//
// performs the A* algorithm on the visibility graph to find a path
// from the start node to the goal node if one exists.
//
// also prints out information as per the assignment
//
int astar(int start, int goal)
{
  // your function here
}


//
// reads the adjacency matrix from the specified filename into the
// global arraf adj[][]
//
void readAdj(char fname[])
{
  FILE *fp = fopen(fname, "r");

  if (fp == 0) {
    fprintf(stderr, "Couldn't open the file \"%s\" tob read the adjacency matrix\n",fname);
    exit(1);
  }

  fscanf(fp, "nodes: %d", &nnodes);
  for (int j=0; j<nnodes; j++) 
    for (int k=0; k<nnodes; k++) {
      int t;
      if (fscanf(fp, "%d", &t) != 1) {
	fprintf(stderr, "End of file reached while reading adjacency matrix ");
	fprintf(stderr, "from file \"%s\".\n", fname);
	fprintf(stderr, "(perhaps you have switched the filenames?)\n");
	exit(1);
      }
      if (t==1)
	adj[j][k] = true;
      else
	adj[j][k] = false;
    }
  fclose(fp);
}

//
// reads the node locations from the specified filename into the
// global arrays x[] and y[]
//
void readLoc(char fname[])
{
  FILE *fp = fopen(fname, "r");

  if (fp == 0) {
    fprintf(stderr, "Couldn't open the file \"%s\" to read the node locations\n",fname);
    exit(1);
  }

  fscanf(fp, "nodes: %d", &nnodes);
  for (int k=0; k<nnodes; k++) {
    fscanf(fp, "%f %f", &x[k], &y[k]);
  }
  fclose(fp);
}

int main(int argc, char *argv[])
{
  if (argc < 3) {
    fprintf(stderr, "Usage: %s <adjacency matrix filename> <node location filename>\n",
	    argv[0]);
    exit(1);
  }

  // read the visibility graph from the files
  readAdj(argv[1]);
  readLoc(argv[2]);

  // perform A* on the graph and print out information as per assignment
  astar(0, nnodes-1);
}

