- Home /
Object position in relation to another object
Once again still doing Othello, I have a game object (the game board grid) and the tokens. I'm trying to have the token get its XY from the grid object. I have them communicating but its handing it null values and thus I'm getting errors about it not being tied to an object. so my figuring is that if I can figure out the object's relative XY the error about it not being tied to an object will go away. Any suggestions?
Answer by MountDoomTeam · Nov 26, 2012 at 08:22 AM
I don't understand the question that well, if you have 2 objects, it's not possible that the position of one compared to the other is null, unless you're not referencing one of the object properly.
Anyway, in a Chequers type of game, the board should have a fixed position and you should use some fixed mathematics to calculate all the positions of everything I think?
I would have chosen to have each square of the board as an integer and the tokens positions always at one integer or another, then it's really easy to do the mathematics for comparing all the tokens relative to each other, get all items called token, compare them to the last one played, do some logic to see if there are any that are tracked by the last played taken in all directions around it, I am estimating the entire program in its simplest form would be about 100-200 lines of code excluding variables.
to make a board, probably just do black and white squares ultimately in fixed positions, either by hand or by a formula that does 64 squares alternating by 8 and by 2 colours...
then you don't really need to worry about the board,
just focus on tokens within set positions and deleting some after callinga loop saying- check lines in all directions and see if any tokens are trapped. For that, the tokens positions need formulas like-
if token position X equals token position X+1, variable tokensinline equals 2, etc.and proceed through the loop like +1, +2, +3
it's funny that Chris Butler should ask questions about othello! I thought he was a polo player