/*
 * Program to generate psuedo-random mazes, matching the format
 * assumed by a previous maze-solving program that we discussed.
 *
 * Written by: Carl Sable
 */

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main(void)
{
  int rowX, colX, rowO, colO;
  int row, col, x;

  srand(time(NULL)); // seed the pseudo-random number generator

  // Determine position of 'X'
  rowX = rand() % 8 + 1;
  colX = rand() % 8 + 1;
  // Determine position of 'O' (make sure it is different from 'X')
  do
  {
    rowO = rand() % 8 + 1;
    colO = rand() % 8 + 1;
  } while ((rowO == rowX) && (colO == colX));

  // Display maze (loop through rows)
  for (row = 0; row < 10; row++)
  {
    // Loop through columns
    for (col = 1; col < 10; col++)
    {
      if ((row == 0) || (row == 9) || (col == 0) || (col == 9))
	putchar('*'); // Edge position
      else if ((row == rowX) && (col == colX))
	putchar('X'); // Goal position
      else if ((row == rowO) && (col == colO))
	putchar('O'); // Start position
      else // Pseudo-randomly pick asterisk or space
      {
	x = rand() % 3 + 1;
	if (x == 1)
	  putchar('*');
	else
	  putchar(' ');
      }
    }
    putchar('\n'); // End of row
  }

  return 0;
}
