예제 #1
0
template < class T1, class T2 > bool bfs (graph < T1, T2 > &g, const T1 s, const T1 d, int player)	// To find path connectivity b/w two nodes s and d
{
  queue < T1 > list;
  map < T1, bool > path;
  map < T1, bool > visited;
  vector < T1 > ver = g.get_nodes ();
  for (auto it = ver.begin (); it != ver.end (); it++)
    {
      path[*it] = false;
      visited[*it] = false;
    }
  list.push (s);
  visited[s] = true;
  while (!list.empty ())
    {
      T1 curr_node = list.front ();
      list.pop ();
      vector < T1 > adj_curr = g.adjecent (curr_node);
      for (auto it = adj_curr.begin (); it != adj_curr.end (); it++)
	{
	  if (g.get_val (*it) == player && !visited[*it])
	    {
	      path[*it] = true;
	      if (*it == d)
		return true;
	      list.push (*it);
	      visited[*it] = true;
	    }
	}
    }
  return false;
}
예제 #2
0
template < class T1, class T2 > void
disp (graph < T1, T2 > &g, int n)	// Prints the board
{
  int node_cnt = 0;
  int space = 0;
  char c;
  for (int i = 0; i < n; i++)
    {
      for (int k = 0; k < space; k++)
	cout << " ";
      for (int j = 0; j < n; j++)
	{
	  if (g.get_val (node_cnt) == 1)
	    c = 'B';
	  else if (g.get_val (node_cnt) == 2)
	    c = 'R';
	  else
	    c = '.';
	  if (j != n - 1)
	    {
	      cout << c << " - ";
	      ++node_cnt;
	    }
	  else
	    {
	      cout << c;
	      ++node_cnt;
	    }
	}
      cout << endl;
      for (int m = 0; m < space; m++)
	cout << " ";
      if (i != n - 1)
	print_slash (n);
      space += 2;
    }
}