adjacent objects

Kay C Lan lan.kc.macmail at gmail.com
Sun Dec 6 22:25:11 EST 2015


On Mon, Dec 7, 2015 at 3:33 AM, Richmond <richmondmathewson at gmail.com>
wrote:

>
> If we imagine a chessboard . . .
>
> ...
>
> Of course, the main criticism about my idea of using a field to store prop
> details is that looking up info in it
> will be significantly slower than using an array.
>
> As the base game of Carcassonne uses 72 tiles this may involve quite a hit.
>
> I'm not familiar with Carcassonne but if it were Chess I'd approach it
this way:

For each piece I'd store in a custom property (no I wouldn't use fields) a
list of legal positions the piece could move to. For instance at the very
start of a game the King on either side has no legal positions to move to.
I'd then keep an array (sorry) of all the possible legal positions (the
keys) that can be used and which pieces can use them (the elements) .i.e
some squares could be moved into by one of a number of pieces.

(key)
(a3) wp1 (w = white, p = pawn)
(a4) wp2
(a6) bp8,bkn2 (b = black, kn = knight)
...

When a piece is moved it's new position is compared to it's own custom
property list of legal position and if it matches it's allowed and all new
legal positions for that single piece are recalculated. The ALL legal
position array would then be checked to see which other pieces could move
to that position and then those pieces have their individual legal
positions recalculated. Finally the ALL legal positions array would be
updated to reflect the new list of legal positions and the pieces that can
use them.

The thing to note is that with any 'move one piece at a time game' it
doesn't matter if there are 32, 72, or 720 pieces, you do not have to
calculate ALL the possibilities of all the pieces but typically it is only
a very small subset; so you have to nut out how to quickly and easily
maintain a list of valid moves.

Again, using chess as a basis,

1) I'd be using behaviours as much as possible. All the pawns, whether
black or white, would use the same algorithm.
2) I'd store their legal position in custom properties - easy to double
check during development
3) I'd store ALL legal positions of ALL pieces in an array - but his could
be printed out to a field during development to ease the troubleshooting
process.
4) Updating would only occur after the placement of a piece and would be
restricted to ONLY those pieces that are effected.

 I appreciate that you don't want to use an array and really for such a
slow turn by turn based game it would be possible to figure out a grid
based system i.e. line 5 item 11, and store the details of the pieces that
can legally use that position.

HTH



More information about the use-livecode mailing list