• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Looking for guidance on a "4 in a row" win condition

Status
Not open for further replies.
Level 13
Joined
Mar 24, 2013
Messages
1,105
The map is a slightly tweaked version of tic-tac-toe.

The gameboard starts out as a grid 3x3 and each time a player marks a spot they increase the size of the board by one tile by adding a new space that connects to the current board on a full side (not diagonally).

My issue is catching when the player makes the move that gets them 4 in row, either up/down, left/right or diagonally are the possible ways to get it.

There is no guarantee that the last spot that completes the chain of 4 will be at the end of the chain. ( it could a middle spot that competes the chain of 4.)

My current plan is to check everytime the player makes a move and search for a 4 in a row chain in a 7x7 area around the newly marked spot. However, this would be something like 60 combinations to check everytime and I feel that there must be a better way.

Thanks for any feedback
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,201
You check all combinations for the change made. If it does complete a 4 in a row then out of all possible 4 in a row combinations that tile must make up one part of it.

There is up-down, left-right, top left-bottom right and bottom left-top right. That is 4 combinations. For each there are 4 different positions the tile might take for a 4 in a row to be complete. Total is 16 tests. Running 16 4 in a row tests is trivial. The maximum is 64 indices tested, however early exit tests will allow for less. Well under a thousand operations for each placement made.
 
Status
Not open for further replies.
Top