Results 1 to 9 of 9

Thread: Getting all squares from coordinates? *RESOLVED*

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2001
    Posts
    421

    Getting all squares from coordinates? *RESOLVED*

    I don't know if anyone remembers the old game called Metasquares, but it involved placing dots onto a 2D coordinate plane, and if four dots were made into a square (even if they squares were rotated), then it would draw a line going from one dot to the other, making a square outline. It was very fun and took a lot of strategy.

    My question is, what would the formula be for figuring out if 4 coordinates on a 2D plane form a square?
    Last edited by Oafo; Nov 1st, 2002 at 11:05 PM.
    [vbcode]
    ' comment
    Rem remark
    [/vbcode]

  2. #2
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    wher you have 4 small squares that are formed more or less like this:
    ----
    12
    34
    ----

    Pseudo code:
    -------------------------------------------------------------------
    If square2.X = (Square1.X + Square1.Width) and
    Square2.Y = Square1.Y and

    square3.X = square1.X and
    square3.Y = (square1.Y + square1.height) and

    square4.X = (Square1.X + square1.width) and
    square4.Y = (sqaure1.Y + sqaure4.height)

    then the make a square.
    -------------------------------------------------------------------

    But you loop in this situation want be that easy to figuer out.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2001
    Posts
    421
    I should have attached this first to let you know what I'm trying to do.

    The user will click an open spot to place a dot in it's place. If four of these dots form a square in any way, then points are awarded.. the bigger the square, the more points. The screenshot is just something I tossed together that I want the game to look like.
    Attached Images Attached Images  
    [vbcode]
    ' comment
    Rem remark
    [/vbcode]

  4. #4
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    Make a "coordinatesystem", on the picture you got 6*6 possitions. You could number all the coordinate like this:
    (11)(21)(31)(41)(51)(61)
    (12)(22)(32)(42)
    (13)(23)(33)(43)
    (14)
    (15)
    (16)

    and so one....
    When I look at my numbers now, it looks more like a 6dimensional array...maybe that would be the was. That would make the loop a lot easyer.


    So you could try this.
    If you want to check for scares that are formed like this:

    12
    34

    it would be something like this:

    Get the "coordinates" to the last green-spot that was visible. If the coordinates vas (32). Then you would have to check in your array if (31)(41)(42) also is visible, or (42)(33)(43) or (22)(23)(33) or (31)(21)(22) are visible. This would actually not be that difficult at all. Make a 6dimensiolnal array of Booleans. And check if this playses in the array is true...


    If you don't understand let me know, and I try to express myselv in an easyer way. Or if you have problems turning this in to reel code, just ask again...

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2001
    Posts
    421
    The squares aren't all at 0 degrees. Look at the picture in my last post and you'll see that the square formed is rotated. I'm still working on this also, if I come up with a solution, I'll let you know.
    [vbcode]
    ' comment
    Rem remark
    [/vbcode]

  6. #6
    Fanatic Member riis's Avatar
    Join Date
    Nov 2001
    Posts
    551
    When a player clicks at a point (x, y), check for all possible squares from that point. Start with (1,1), and go until (6,6).
    A square is formed by two deltas, let's say A and B. Important: A or B can also be negative, or 0 (in case you would have a rectangular square). A and B cannot both be zero.
    Starting with (1,1), then A will be x-1 and B will be y-1. To reach the next point of the square you should add B to the X-coordinate and subtract A from the Y-coordinate. (See image)
    Of course this will fall outside the game area, so you know this won't be a valid square.
    In certain cases you will achieve a valid square. In such a case you should check whether all points are occupied by one player.
    I hope this will work. Just ask if you need more info, and/or if I've been too unclear.
    Attached Images Attached Images  

  7. #7
    Fanatic Member riis's Avatar
    Join Date
    Nov 2001
    Posts
    551
    I've made a form which contains the logic which determines whether four points are in a square.
    It's attached to this post.
    Have fun!
    Attached Files Attached Files

  8. #8
    Fanatic Member riis's Avatar
    Join Date
    Nov 2001
    Posts
    551
    Some remarks and ideas:
    * I don't link any squares with lines. It shouldn't be too hard. Load linear shapes dynamically, and draw them from centerpoint to centerpoints of points forming a square.
    * Maybe you should make the size of the grid dynamically.
    * Maybe you should make it possible to remove (strategically) points (center point, corner points, etc), so there might be fun. It isn't necessary to restrict to square grids, imho.

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2001
    Posts
    421
    Perfect, thanks a lot. Now I'll use that logic and apply it to a simple multiplayer game, I'll post when it's done. Thanks again.
    [vbcode]
    ' comment
    Rem remark
    [/vbcode]

Posting Permissions

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



Click Here to Expand Forum to Full Width