comp.lang.ada
 help / color / mirror / Atom feed
From: Alex <willmann817@gmail.com>
Subject: Re: Depth First Search of a Char_Matrix?
Date: Mon, 29 Apr 2013 13:55:46 -0700 (PDT)
Date: 2013-04-29T13:55:46-07:00	[thread overview]
Message-ID: <5d751787-2574-475c-befc-553fcd02e6b6@googlegroups.com> (raw)
In-Reply-To: <61f44636-ad71-447f-a20e-473e613f63ff@googlegroups.com>

On Saturday, April 27, 2013 7:34:51 PM UTC-4, Shark8 wrote:
> When you print the array out you have a representation of nodes (and implicitly edges), just displayed in a tabular ASCII format.
> 
> 
> 
> Is a very real sense (1,1), (1,2),...,(5,5) are merely addresses/locations of a node, wherein 'B', 'W' and '.'/' ' denote that node's state the edges, then, ar nothing more than the relationship of what is adjacent in the horizontal/vertical.
> 
> 
> 
> -------------------------------------------
> 
> [Non-DFS method]
> 
> You could count the dead pieces as follows:
> 
> if there are no empty locations all are dead, otherwise
> 
> (1) make two lists of nodes A & B,
> 
> (2) add all the empty nodes to A,
> 
> (3) for each node of A, add its neighbors to B if they are occupied,
> 
> (4) clear A
> 
> (5) for each of those nodes in B, add only its neighbors containing a piece of the same color to A
> 
> (6) merge A into B
> 
> (7) repeat #4/#5/#6 until the sizes B is the same as it was in #4.
> 
> 
> 
> At this point the system is stable and you have all the live pieces in your list, anything not in your list is then dead. -- This would be a horrible way to do things on any large sized board because of the reiterations... but it's already given you the secret of how to do it with DFS.

This is what I have so far but I am going out of Bounds and I am not sure why??

   function Count_Alive(Board : Char_Matrix) return Integer is
	M : Char_Matrix := Board; 
	V : Bool_Matrix(2..Board'Length-1, 2..Board'Length-1) := (others => (others => False));	
	WhiteCount, BlackCount : Integer := 0;
		procedure DFS(X,Y:Integer; Char : Character) is
		current : Character:= Char;	
		begin
			Put_Line("X = " & X & " Y = " & Y);
			if V(X,Y) = True or M(X,Y) = '/' or M(X,Y) /= current  then
				null;
			else
				V(X,Y) := True;
				if current = 'W' then
					WhiteCount := WhiteCount + 1;
				end if;
				
				if current = 'B' then
					BlackCount := BlackCount + 1;
				end if;
			end if;
				
				DFS(X,Y-1,current);
				DFS(X+1,Y,current);
				DFS(X-1,Y,current);
				DFS(X,Y+1,current);
				
		end DFS;

	begin
		for R in 2..M'Length(1)-1 loop
			for C in 2..M'Length(2)-1 loop
				if M(R,C) = '.' then
					DFS(R,C-1,'W');
					DFS(R+1,C,'W');
					DFS(R-1,C,'W');
					DFS(R,C+1,'W');
					
					DFS(R,C-1,'B');
					DFS(R+1,C,'B');
					DFS(R-1,C,'B');
					DFS(R,C+1,'B');
				end if;
			end loop;
		end loop;
      return (1000*BlackCount)+WhiteCount;
   end Count_Alive;



  parent reply	other threads:[~2013-04-29 20:55 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-27 14:09 Depth First Search of a Char_Matrix? Alex
2013-04-27 15:35 ` Shark8
2013-04-27 17:25   ` Jeffrey Carter
2013-04-27 18:16     ` Shark8
2013-04-27 18:48       ` Dmitry A. Kazakov
2013-04-27 18:58         ` Shark8
2013-04-27 20:16           ` Dmitry A. Kazakov
2013-04-27 19:31       ` Simon Wright
2013-04-27 20:04         ` Shark8
2013-04-28  3:26       ` Jeffrey Carter
2013-04-27 16:27 ` Alex
2013-04-27 16:34   ` Shark8
2013-04-27 16:51     ` Alex
2013-04-27 16:55       ` Alex
2013-04-27 19:05       ` Shark8
2013-04-27 22:54         ` Alex
2013-04-27 22:56         ` Alex
2013-04-27 23:34           ` Shark8
2013-04-27 23:38             ` Alex
2013-04-29 20:55             ` Alex [this message]
2013-04-29 23:40               ` Jeffrey Carter
2013-04-30 10:49               ` AdaMagica
2013-04-28 10:50 ` AdaMagica
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox