comp.lang.ada
 help / color / mirror / Atom feed
From: Alex <willmann817@gmail.com>
Subject: Re: Depth First Search of a Char_Matrix?
Date: Sat, 27 Apr 2013 09:51:44 -0700 (PDT)
Date: 2013-04-27T09:51:44-07:00	[thread overview]
Message-ID: <4c3eca49-8ee6-4518-9968-879c08b828f6@googlegroups.com> (raw)
In-Reply-To: <99d9a17c-ed8d-4c28-90d0-6543b511cb87@googlegroups.com>

On Saturday, April 27, 2013 12:34:55 PM UTC-4, Shark8 wrote:
> On Saturday, April 27, 2013 10:27:23 AM UTC-6, Alex wrote:
> 
> > On Saturday, April 27, 2013 10:09:10 AM UTC-4, Alex wrote:
> 
> > 
> 
> > > Below is Char_Matrix representation of the board game "Go".  A 'W' represents a white piece, a 'B' represents a black piece, and a '.' represents a empty space.  Each black or white piece can either be alive or dead.  A piece is Alive is if it horizontally or vertically next to a '.' OR if it is horizontally or vertically next to another piece that is alive. You can think of aliveness as being contagious.  How can I use depth first search to count the number of alive black pieces and alive white pieces?  
> 
> > 
> 
> > > 
> 
> > 
> 
> > > 
> 
> > 
> 
> > > 
> 
> > 
> 
> > > WW.BB
> 
> > 
> 
> > > 
> 
> > 
> 
> > > .WWWW
> 
> > 
> 
> > > 
> 
> > 
> 
> > > WWBBB
> 
> > 
> 
> > > 
> 
> > 
> 
> > > BBBWW
> 
> > 
> 
> > > 
> 
> > 
> 
> > > WWBW.
> 
> > 
> 
> > > 
> 
> > 
> 
> > > 
> 
> > 
> 
> > > 
> 
> > 
> 
> > > 
> 
> > 
> 
> > > 
> 
> > 
> 
> > > In this example there are 11 alive white piece and 2 alive black pieces.
> 
> > 
> 
> > > 
> 
> > 
> 
> > > 
> 
> > 
> 
> > > 
> 
> > 
> 
> > > Can anyone provide any insight into this problem?
> 
> > 
> 
> > 
> 
> > 
> 
> > Shark you are correct,  I forgot to include the fact that only like colors are contagious.  Thank you very much for your assistance.  Without providing the code how would I change it to reflect this piece of missing logic?
> 
> 
> 
> Simple:
> 
> 1 )  Add a local variable indicating the color to Is_Alive, that will be accessable to its nested functions.
> 
> 2 )  After checking for null on (x,y) assign that to the variable before calling recursion.
> 
> 
> 
> You could also make that variable a constant and use a conditional expression [in Ada 2012] to set the initial value -- something like:
> 
> Color : Constant Piece_Color:= (if board(x,y) /= null then board(x,y).color else white); -- DEFAULT to white on NULL, otherwise set to the initial piece's color.

Thanks! So I am given the function signature, not really a function body that looks like this

   function Count_Alive(Board : Char_Matrix) return Integer is
 	M : Char_Matrix := Board;  
	begin
      return -999;
   end Count_Alive;


So I understand much of your logic, but I am given a matrix of characters defined as such:

type Char_Matrix is array(Positive range <>, Positive range <>) of Character;

So could you give me like an algorithm in words on what I need to do instead of giving me the answer in code?

  reply	other threads:[~2013-04-27 16:51 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 [this message]
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
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