determine if adversary pawns are captivated

This is a discussion on determine if adversary pawns are captivated within the C Programming forums, part of the General Programming Boards category; Hey everyone. I am trying to write a simple application that resembles the game "Computer Co", but I am stuck ...

  1. #1
    Registered User
    Join Date
    Aug 2009
    Posts
    39

    determine if adversary pawns are captivated

    Hey everyone. I am trying to write a simple application that resembles the game "Computer Co", but I am stuck with this problem: If the board is represented by a dimensional array, with what algorithm could I tell if one player's pieces are captivated by the other's? In other words, how can I recognise whether the pieces of one colour form a circle?
    Sorry for my English.

  2. #2
    Registered User
    Join Date
    May 2012
    Posts
    333
    Go to my website, and go to the binary image processing section.
    There's a fucntion called floodfill which will do what you want. You represent the opposing pieces as set bits, then floodfill. If no two opposite edges have floodfiled pixels, you point of interest is surrounded.
    I'm the author of MiniBasic: How to write a script interpreter and Basic Algorithms
    Visit my website for lots of associated C programming resources.
    http://www.malcolmmclean.site11.com/www

  3. #3
    Registered User
    Join Date
    Aug 2009
    Posts
    39
    Quote Originally Posted by Malcolm McLean View Post
    Go to my website, and go to the binary image processing section.
    There's a fucntion called floodfill which will do what you want. You represent the opposing pieces as set bits, then floodfill. If no two opposite edges have floodfiled pixels, you point of interest is surrounded.
    Are you sure? I could not find any function called "floodfill". Can you link me please? As I understand, this kind of code concerns graphics. Is it certain that it can also apply to my problem?

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    I'm not familiar with "Computer Co". Use [code]
    Code:
     tags around a text display of the board, and men 
                (so the spacing stays in place on the forum).
    You show the problem, and I'll show you the answer.

    Such a deal.

  5. #5
    Registered User
    Join Date
    May 2012
    Posts
    1,066
    Quote Originally Posted by vril View Post
    As I understand, this kind of code concerns graphics. Is it certain that it can also apply to my problem?
    Look at Flood fill on Wikipedia to see if that algorithm helps you.

    Bye, Andreas

  6. #6
    Registered User
    Join Date
    Aug 2009
    Posts
    39
    You, guys, are awesome! At first, I couldn't figure out how the floodfill algorithm can answer my decision problem (whether there is a connected area on my board), but I came up with an idea: I could use the algo to fill both the opposite colour and blanks with a target colour and then check the whole board. In case there is no piece of the opposite colour left, then there was a "leak", so no captivation. Right? In other case, the opposite pieces get eaten inside the clustered areas, so mission is accomplished. Now, though I have to think of an improved version.

  7. #7
    Registered User
    Join Date
    Aug 2009
    Posts
    39
    Is there any source code of the game, bacause I cannot find any?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. chess program for movement of queens and pawns...
    By mac025 in forum C Programming
    Replies: 21
    Last Post: 02-28-2006, 01:19 AM
  2. determine how many 0's are in a number (value)
    By pyazarian in forum C++ Programming
    Replies: 4
    Last Post: 07-06-2005, 01:20 PM
  3. Determine MessageBox
    By jkw2068 in forum Windows Programming
    Replies: 2
    Last Post: 08-04-2003, 04:01 PM
  4. how can i determine the size?
    By Mingzhi in forum C++ Programming
    Replies: 3
    Last Post: 07-31-2003, 06:05 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21