3

Hello I've been trying for couple of days to write a script to generate a progressive map using PHP. What I'm trying to achieve but with no success would be something like this: enter image description here

In short I have a "node" defined as 5,6 on xy ( as an example ) then randomly add a random number of "players" close to the "node". From here I want to connect the closest "player" to the node while having a list of criteria that will determine to which node the "player" will be connected (how many connections are for that node, what's the max number of connections etc ). I haven't written any code yet because I don't know exactly where to start or with what should I start since I'm not that great with math only pretty good with PHP. Andy ideas or advice any help is welcomed.

Bogdan
  • 693
  • 7
  • 26
  • are you trying to generate a graphic like the one you show or actually creating some type of routing mechanism that works as depicted on that image? – thwd Sep 02 '11 at 12:07
  • no just a map for a simple game. the blue points are players and the red one a "node" you could think of a network of computers with a node that gives you the internet connection.. or the network connection to the rest of the users.. – Bogdan Sep 02 '11 at 12:53
  • Use the GDLib functions to generate the map graphic: http://php.net/manual/en/ref.image.php – thwd Sep 02 '11 at 13:01
  • Tom isn't that going to generate an image of the map ? :-) – Bogdan Sep 02 '11 at 13:29

2 Answers2

1

I made a game board 10 x 10 with interacting color elimination.

I use an array to first define the grid. Below creates an array with 100 object slots.

SAMPLE: Game at http://apps.facebook.com/AnotherGrid/ Just login to play and see the grid in action. This array generates 1000 grids for my game dynamicly.

<?php
$lvl = array(
/* row0 */' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
/* row1 */' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
/* row2 */' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
/* row3 */' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
/* row4 */' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
/* row5 */' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
/* row6 */' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
/* row7 */' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
/* row8 */' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
/* row9 */' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '
);
?>

then i used:

foreach ($lvl as $key => $value) {
echo '<div class="grid" id="'.$key.'"onclick="null">'.$value.'</div>';
}

to write the grid, and used CSS to define display: inline-block to each div.

For positioning of each is based on the position of the array object. < div id="0" > would be the very first square upto 99.

<?php
$lvl = array(
/* row0 */'black', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
/* row1 */' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
/* row2 */' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
/* row3 */' ', ' ', ' ', ' ', 'yellow', ' ', ' ', ' ', ' ', ' ',
/* row4 */' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
/* row5 */' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
/* row6 */' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
/* row7 */' ', ' ', ' ', 'blue', ' ', ' ', ' ', 'green', ' ', ' ',
/* row8 */' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
/* row9 */' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '
);
?>
ShawnDaGeek
  • 4,145
  • 1
  • 22
  • 39
1

Well, I think you want to create a topology of the network, having as root the internet provider.

So, I'm thinking that the best way is to create a graph. The root is the red dot. Than the players attached to it. Than the players attached to the already attached players and so on.

something like this :

            *
         /  |  \
         O  O   O
       / |  |    |
      O  O  O    O

now. Each node of the graph can have some info associated to it: type: player | node coordX : 5 coordY: 6 etc...

Displaying the map will just mean that you can walk the tree and draw the elements based on their positions, you can draw lines based on the connections.

If your topology conains cycles, that is player1 connected to player2 which is connected to player3 ..... player n which is connected to player1, than you need a graph structure.

If i described correctly your problem, than you should find some articles about tree / graph algorithm, how to parse them, etc.. and should be able to do your job.

Dan Bizdadea
  • 1,292
  • 8
  • 15
  • Dan i will have a look over graph algo's and anything related about then i will come back with a reply :-). And yes that's what i`m looking for starting from the red dot connect players with the red dot ( in visual representation and on the xy map by chooising the points closer to a certain dot). – Bogdan Sep 23 '11 at 04:42