Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


2D int array and calculation of five in a row


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 pxsh   Members   -  Reputation: 130

Like
0Likes
Like

Posted 20 September 2012 - 07:44 AM

Hi, I'm working on a five in a row game in C# and I have all set but the winning conditions which is *drums...* connecting five of the same value in a row (can be either horizontal, diagonal or vertical. The game map is stored as a 2 dimensional int array (15,15).

I suppose a good solution would be to use the latest changed "brick" in the game map to be the starting point of calculation and then make calc that grows from that point until it either finds 5 in a row (win) or no more possible entries is found.

I´m seeking guidlines/help on how to understand/make this possible.

Sponsor:

#2 Álvaro   Crossbones+   -  Reputation: 13652

Like
0Likes
Like

Posted 20 September 2012 - 08:53 AM

bool five_in_a_row($square, $new_brick_color) {

  for each $direction in {North, NorthEast, East, SouthEast} {

	$a = count how many bricks of color $new_brick_color are found starting from $square+$direction along $direction

	$opposite_direction = -$direction

	$b = count how many bricks of color $new_brick_color are found starting from $square+$opposite_direction along $opposite_direction

	if ($a+$b >= 4) // because we didn't count the latest brick

	  return true;

  }

  return false;

}

Edited by alvaro, 20 September 2012 - 08:54 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS