Sign in to follow this  
zz2

Five in a line evaluation logic

Recommended Posts

zz2    282
Hi, to avoid reinventing the wheel I would like to know if any known method of evaluating, if there are x no. of items of the same type in a line on a gird, exists.

For example: are there 5 items (of the same type) in a line anywhere on the grid.

Share this post


Link to post
Share on other sites
alvaro    21246
Typically you only have to check if the last stone placed on the board makes five in a line, which can be done by counting how many you got to the right, how many to the left and adding the new stone, and similarly for the other 3 directions.

Share this post


Link to post
Share on other sites
zz2    282
thanks! now that you said it like that it seems pretty easy.

On Change
for added or moved item check:
horizontal direction = 1 + count left + count right
vertical direction = 1 + count up + count down
diagonal A direction = 1 + count down left + count up right
diagonal B direction = 1 + count up left + count down right

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this