Using directions instead of zones! Log Out | Topics | Search
Moderators | Register | Edit Profile

Zillions of Games Discussion Forum » Designing Games for Zillions » Using directions instead of zones! « Previous Next »

Author Message
Karl Scherer (Karl)
Posted on Monday, February 12, 2001 - 2:51 am:   

Using directions instead of zones.
==================================

I would like to make authors aware that
often it is much easier to use specially
designed directions instead of zones in Zillions rules files.
Often much less code is needed in coding a direction than in coding a zone.

Let me give you two practical examples here:

1. example : zones on a board
In a chess variation, you want to check whether
a piece is on ranks 1 or 2 if it is white
and whether it is on ranks 7 and 8, if it is a black piece.

Conventional:
You could define two zones separately by listing all the 16 positions each
and then later check whether the piece in in the zone. But for this you also
would need to know whether the piece is white or black.
So you also have to either give them corresponding piece-attributes
or define pieces with different names for Black and White.

Using direction:
in the board definition, define
(ss 0 2) ;direction pointing two steps to South.
We then make use of the symmetry command for directions in chess board definition,
all we have to check later in the code is:
(if (on-board? ss) ...)

2. example: second, invisible board.
Many games use a second, invisible board to store information.
This is usually by adding more letters to the grid statement.

Again I will use the chess board as the classic example:
(dimensions
("a/b/c/d/e/f/g/h/A/B/C/D/E/F/G/H" (24 0)) ; 16 files
("8/7/6/5/4/3/2/1" (0 24)) ;8 ranks
)
creates a second chess board next to the original one.

Conventional:
You would have to type 64 positions(!) to create a zone that
encompasses the left (or right) chess board.
(you need about 300 keystrokes for that!)

Using directions:
We simply add the 8-step directions ee and ww to the directions:

(directions (n 0 -1) (e 1 0) (s 0 1) (w -1 0)
(ne 1 -1) (nw -1 -1) (se 1 1) (sw -1 1)
(ee 8 0)(ww -8 0) ;to connect second board
)

That costs exactly 17 keystrokes !
You check whether a position is on the left board by
(if (on-board? ee)...
Similary, you check whether a position is on the left board by
(if (on-board? ww)...

I hope I could convey some of the excellent applications of
specially-designed directions.
Maybe you can add a few yourself here!?

............................................
P.S. the directions "ee" and "ww" come in handy in many other ways, too:
They make it very easy to store any information about the board longterm.
For example, you may initialize the second board with invisible dummy pieces.
And store information on a current board position by coding
...
ee
(change-type info1)
ww
...

Example games:
- Rabbit
- Cat&Mouse IV (out next week)
- many others

Happy programming!
Karl
Karl Scherer (Karl)
Posted on Monday, February 12, 2001 - 2:54 am:   

Typo correction: (if (on-board? ss) ...)
should read (if (not-on-board? ss) ...)
Dan Troyka (Dtroyka)
Posted on Monday, February 12, 2001 - 1:52 pm:   

I believe zones are player-specific so you don't need to separately define pieces so long as you separately define the zones. Even so, your point still holds in certain circumstances.

You can also define an invisible board using a third dimension statement and setting off the resulting duplicate board to one side. This has the advantage of allowing you to set the duplicate board as far as way as you like, but the disadvantage of adding an extra coordinate to the positions on the principal board.

Add Your Message Here
Post:
Username: Posting Information:
This is a private posting area. Only registered users and moderators may post messages here.
Password:
Options: Enable HTML code in message
Automatically activate URLs in message
Action: