User Tag List

Results 1 to 5 of 5

Thread: How do i detect if 4 of the same type is next to each other ("Connect 4" Game)

  1. #1
    Clicker Fusion 2.5 (Steam)

    Join Date
    Apr 2017
    0 Post(s)
    0 Thread(s)

    Question How do i detect if 4 of the same type is next to each other ("Connect 4" Game)

    So, I am trying to make a "Connect 4" style game. I have made the game itself, that was simple, but i have run into issues with detecting when 1 player has 4 in a row (both Vertically, Horizontally, and Up/down sideways)

    I want it to detect some like these (Blue Examples):

    I want it to be able to make the player that gets 4 in a row win.

    Any suggestions on how this can be done?

    Thanks in advance!

  2. #2
    Clicker Fusion 2.5 DeveloperHTML5 Export Module

    Join Date
    Jun 2006
    10 Post(s)
    0 Thread(s)
    You need to do a google search for this. There are multi-ways from using minmax functions to basic loops. The code is listed for your consideration in articles.

  3. #3
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleiOS Export ModuleSWF Export Module
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)
    Popcorn's Avatar
    Join Date
    Jun 2006
    Norway, Bergen
    13 Post(s)
    0 Thread(s)
    Use fastloops. If you don't know how they work, learn about them first. There are lots of tutorials on it. Then come back here.

    Create three detectors (active objects). Detector 1 should move across the frame from left to right across all rows and detector two should move from top to bottom across all columns. Detector 3 should move diagonally across all tiles. Detector 1 detects horizontal matches, and Detector 2 detects vertical matches.
    You can do this by starting loop Detect Horizontal X as many times as there are columns, and on each of those loops, start the loop Detect Horizontal Y as many times as there are rows.
    On each Detect Horizontal Y set the detector's X position to x of left edge + tile width / 2.0 + loopindex("Detect Horizontal X") * tile width, and set y position to top edge + tile width / 2.0 + loopindex("Detect Horizontal Y") * tile width.
    Then on each loop (the same one, but another event) check if the detector is overlapping a brick. If it is overlapping a blue brick, add one to a counter named blue and set a counter named red to 0. If it is overlapping a red brick, add one to a counter named red, and set blue to 0. If it is not overlapping a brick, set both red and blue to 0.
    If the counter is 4 or more, you have a match.
    Repeat the same procedure for vertical detection. Diagonal detection is slightly more tricky as you need a detector to move diagonally, but the same logic remains.

  4. #4
    Clicker Fusion 2.5 Developer

    Join Date
    Jul 2008
    16 Post(s)
    0 Thread(s)
    There's no need to scan the whole board like that. Players take turns, so you only need to check the spaces in line with the piece that was just played - if there were lines of 4 anywhere else, they would have already been detected on a previous turn.

    Each time a piece is played, you use its position as your starting point.
    You run a loop to scan down the column, until you reach a space that doesn't contain a piece of the same color, at which point you stop the loop. Each loop iteration, you add 1 to a value somewhere - and then at the end you compare that value to 4.
    You don't need to scan upwards, because in Connect 4 the pieces always drop down from the top. Also, if the piece just played is less than 4 spaces from the bottom, you can skip this step because you know there can't possibly be a vertical line of four. Likewise, you don't need to start checking at all until both players have placed at least 4 pieces.

    For horizontal lines, you still start with the last piece played, but then scan both left and right, add the resulting two values together, and then compare that to 4. Don't forget to include the piece that was just played, but don't count it twice by accident. And then you can do the same for the two diagonals.

    Also, the advanced game board extension is designed for exactly this...

  5. #5
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export Module
    Fusion 2.5 (Steam)
    schrodinger's Avatar
    Join Date
    Nov 2014
    28 Post(s)
    1 Thread(s)
    Adding to all the cool options explained above,
    I have an extensionless (>>>cross platform) example here,
    which is rather short and uses a simple approach and should be customizable a bit (iirc ):

Similar Threads

  1. Ideas on how I could make a "Tecmo Bowl" type game.
    By Emerson3 in forum Fusion 2.5
    Replies: 3
    Last Post: 12th November 2015, 06:39 PM
  2. Issues with my game "Umi Force Unlimited" on iTunes Connect
    By Koji_Kabuto in forum iOS Export Module 2.5
    Replies: 3
    Last Post: 19th December 2014, 08:44 PM
  3. "pending an apple release" on itunes connect
    By SoftWarewolf in forum iOS Export Module Version 2.0
    Replies: 3
    Last Post: 25th July 2012, 02:22 PM
  4. "Labyrinth" game type movement
    By uncleswell in forum Multimedia Fusion 2 - Technical Support
    Replies: 2
    Last Post: 23rd August 2011, 01:06 AM
  5. Little "Shift" and "Ctrl" signs popping up in-game
    By Jocastus in forum Multimedia Fusion 2 - Technical Support
    Replies: 4
    Last Post: 18th January 2009, 10:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts