Go Back   kirupaForum > Flash > Game/AI Programming

Reply
 
Thread Tools Display Modes
Old 11-12-2009, 07:50 AM   #1
[MuG]
Registered User
Jigsaw Type Tile Game

Hey All,

I've been playing around with making a game for a couple of days now. The game itself is pretty simple and I've got the game playing through pretty well bar the tile placement rules.

Essentially its a jigsaw that doesn't have a set layout. You have 24 different tile types and each tile has certain features on it which lead off from any side of the tile. To place a tile you must place next to any existing tile. Corner to corner placement isn't allowed. The features must continue from any existing tile to the newly laid tile. Its like a jigsaw piece must "fit" with the already laid tiles. You can rotate the tiles too.

I don't think it should be that complicated but I was wondering whether anyone here might have some good ideas of how to implement this efficiently??

Cheers,

MuG
[MuG] is offline   Reply With Quote

Sponsored Links (Guests Only) - Register | Need Help?
 

Old 11-12-2009, 11:47 PM   #2
therobot
Block user.
I'll take a stab at this since no one else has yet

I don't know how far along you are with this, but here is a rough idea of how I would model my data.

ActionScript Code:
// create a few different types of connections.
// I'd prefer to just create this with a loop since they're all so similar
var connectionA:Object = new Object();
    connectionA.type = 0;// id so we can easily recognize possible connection
    connectionA.piece_male = "connection_0_male";// linkage to male connection
    connectionA.piece_female = "connection_0_female";// linkage to female connection

var connectionB:Object = new Object();
    connectionB.type = 1;// id so we can easily recognize possible connection
    connectionB.piece_male = "connection_1_male";// linkage to male connection
    connectionB.piece_female = "connection_1_female";// linkage to female connection
             
var connectionC:Object = new Object();
    connectionC.type = 2;// id so we can easily recognize possible connection
    connectionC.piece_male = "connection_2_male";// linkage to male connection
    connectionC.piece_female = "connection_2_female";// linkage to female connection
             

// here's a couple sample puzzle pieces
var puzzlePiece1:Object = new Object();
    puzzlePiece1.connection_up = {connectionType:connectionA, isMale:true};
    puzzlePiece1.connection_down = {connectionType:connectionB, isMale:true};
    puzzlePiece1.connection_left = {connectionType:connectionC, isMale:true};
    puzzlePiece1.connection_right = {connectionType:connectionA, isMale:true};
   
var puzzlePiece2:Object = new Object();
    puzzlePiece2.connection_up = {connectionType:connectionA, isMale:false};
    puzzlePiece2.connection_down = {connectionType:connectionB, isMale:true};
    puzzlePiece2.connection_left = {connectionType:connectionB, isMale:false};
    puzzlePiece2.connection_right = {connectionType:connectionB, isMale:true};


The important thing to consider is that a puzzle piece consists of 4 connections to neighboring pieces - a connection to the up, down, left and right. A connection in itself is an object that keeps a reference of the type of connection it is, and a reference to its male and female components. When I say male and female components, think like stereo plugs or whatever..one thing (male) snaps into another thing (female), like traditional puzzle pieces.

The idea here is that if two puzzle pieces of connections of the same type and one is male and the other female, they may connect, otherwise they cannot.

Sorry if I did a mediocre job explaining that.

Once you get your head around the data structure, assembling a puzzle would be an easy randomization job. You would want to create the fully assembled puzzle first - create a 2d array, pick a random starting position, and run a breadth first search across your 2d array, creating a new puzzle piece for each slot in your matrix.

Essentially, you'd create the first puzzle piece at a random location, assign it random connection types for all four connections it has, then move on to neighboring puzzle pieces. From this point forward, each neighbor will have at least one neighboring connection that you should already know, so you match up the ones you do know, and assign a random connection type for unchecked neighbors.

If I've lost you at this point, I feel like I'd almost need to draw a picture for you but let's see how much of that you got.

__________________
you = function(){
setEnabled( true );
live();
setEnabled( false );
}
therobot is offline   Reply With Quote
Old 11-13-2009, 05:18 AM   #3
[MuG]
Registered User
Hey Robot thanks for replying

I can see what you're doing there and it all makes sense and I've got about as far as that when I posted the message. After I posted the message I created a 2d array to store all the possible possibles a tile could go making it easier to find out which tiles to check.

The only problem I can see with that is that it would be impossible to create the puzzle as there would (and there must) never be a fixed result.

The concept is based on a game called Carcassonne : http://en.wikipedia.org/wiki/Carcass...8board_game%29

So the first piece is fixed and then when the next random piece is drawn is when I'd have to do a check to where the drawn piece can be placed.

Using this sort of data structure (instead of male / female it would be something like road / road or field / field) I can, like you say, run through the placed pieces and check where the pieces can be matched. The pieces can be rotated as well to add a bit of complexity (or simplicity as you don't have to check side to side but instead just if ANY of the sides match).

The only bit that makes this more complicated is that you can "claim" features on a piece. It's probably easier to look at the rules and see what it says - its a bit tricky to explain :S

So basically the data structure for all the different types and tiles might end up being quite complicated!
[MuG] is offline   Reply With Quote
Old 11-13-2009, 02:17 PM   #4
therobot
Block user.
Quote:
Originally Posted by [MuG] View Post
The only problem I can see with that is that it would be impossible to create the puzzle as there would (and there must) never be a fixed result.
By fixed, do you mean you're example requires there only being one possible solution?

With what i have written in my example, it COULD be possible to have multiple solutions in that the pieces might be able to snap together because of the way the random connections ended up getting layed out. You could easily fix this though, by storing the 'final' grid positions in each puzzle piece. With that, even if you had two puzzle pieces that could snap together because of having similar connections, you'd do a check against the puzzle's solution to see if the pieces are actually next to each other.

__________________
you = function(){
setEnabled( true );
live();
setEnabled( false );
}
therobot is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 03:13 PM.

SUPPORTERS:

kirupa.com's fast and reliable hosting provided by Media Temple. flash components
Creative web apps. Make your own free flash banners and photo slideshows.
Check out the great, high-quality flash extensions. Buy or sell stock flash, video, audio and fonts for as little as 50 cents at FlashDen.

Flash Transition Effects

Flash Effect Tutorials

Digicrafts Components
Flash effects. Art without coding. Upload, publish, deliver. Secure hosting for your professional or academic video, presentations & more. Screencast.com
Streamsolutions Content Delivery Networks Flipping Book - page flip flash component.
Flash-Gallery.com - Get your flash photo gallery (flash component or swf gallery Learn how to advertise on kirupa.com
 

cdn
content delivery network (cdn)

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd. Copyright 2010 - kirupa.com Copyright 2010 - kirupa.com