Comparing adjacent items on a grid. Best way to do this?
Posted: Mon Jun 23, 2003 7:02 pm
I'm writing a program that's similar to the card game in the game Final Fantasy 9. The game is played on a 4x4 grid with 0-6 blocks randomly chosen where you cannot place a card. The game goes back and forth between two player which play at card at each turn. Each of the cards can have a point on each of the sides and corner. If you place a card next to one of your opponent's cards, and a point on your card touches a side or corner of the opponent's card that doesn't have a point, you capture that card. If your card is placed so that an empty corner or side is touching an already placed oppenant's card's point, nothing happens.
My question is how should I work the placing of cards and the checking of points adjecent cards points?
Currently I have it so the grid is an array like this:
And the with each on of the 0's representing a block on the grid. As mentioned before, the zero turns to a 1 if it has been randomly chosen to be an unusable block.
The data of the cards is stored in an array like this (all we really care about for this problem are the last 8 keys):
Those last 8 keys are the places for the points, each on stand for a place where a point can be (ul=upper left corner, b=bottom, etc...), 0 if there's no point, 1 if there is.
So the first problem is I don't know how to assign a card to a spot on the grid. should I just put that array into the map's array and make it 3 dimentional? Can I just say like?
And I have no clue on how I would check for points. Any suggestions would be appriated, no code is needed, just kinda suggestions on how I should approach this problem.
My question is how should I work the placing of cards and the checking of points adjecent cards points?
Currently I have it so the grid is an array like this:
Code: Select all
<?php
$map = array (
array ( 0, 0, 0, 0 ),
array ( 0, 0, 0, 0 ),
array ( 0, 0, 0, 0 ),
array ( 0, 0, 0, 0 ),
);
?>The data of the cards is stored in an array like this (all we really care about for this problem are the last 8 keys):
Code: Select all
<?php
$card1 = array ( name => "Monsieus",
type => "fire",
age => 2,
attack => 2,
defence => 1,
ul => 0,
u => 1,
ur => 0,
l => 1,
r => 1,
bl => 0,
b => 1,
br => 0 );
?>So the first problem is I don't know how to assign a card to a spot on the grid. should I just put that array into the map's array and make it 3 dimentional? Can I just say like
Code: Select all
<?php
$map[0][0] = $card1
?>And I have no clue on how I would check for points. Any suggestions would be appriated, no code is needed, just kinda suggestions on how I should approach this problem.