comp.lang.ada
 help / color / mirror / Atom feed
From: Shark8 <onewingedshark@gmail.com>
Subject: Re: Depth First Search of a Char_Matrix?
Date: Sat, 27 Apr 2013 09:34:55 -0700 (PDT)
Date: 2013-04-27T09:34:55-07:00	[thread overview]
Message-ID: <99d9a17c-ed8d-4c28-90d0-6543b511cb87@googlegroups.com> (raw)
In-Reply-To: <d866a8f5-6dca-4f6c-9523-fbcaf9bea679@googlegroups.com>

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.



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