Put picture of GTK build on home page
[xboard.git] / Betza.html
1 <html>
2 <header>
3 <title>Betza notation</title>
4 </header>
5 <body>
6 <h1>Betza notation and XBoard</h1>
7 <p>
8 This page describes Betza's notation system for piece moves,
9 so far as relevant for the XBoard project.
10 XBoard uses this notation to allow engines to inform it on the moves of non-standard pieces in Chess variants,
11 so that features like target-square highlighting, legality checking and SAN generation
12 can work with their usual accuracy even in the presence of such pieces.
13 The current XBoard (4.8.0) only implements a simple form of Betza notation.
14 Future versions might have full understanding of Betza 2.0.
15 But the latter is already of relevance now,
16 as it is used to describe the moves of the more complex pieces
17 on the web pages that describe the rules of the variants supported by XBoard.
18 </p>
19 <h2>The basics</h2>
20 <p>
21 <b>Atoms -</b> Betza notation describes Chess pieces by dividing their moves into groups with the same board step,
22 such as all 8 moves of the Knight.
23 By default these moves can be made as capture as well as non-capture.
24 Such a group of symmetry-equivalent moves ('atom') is indicated by a single capital,
25 usually the common abbreviation of the piece that has those moves, and only those moves
26 (see table 1).
27 The atom <b>O</b> (oh) is sometimes used for null move (staying in place, but consuming the turn),
28 and <b>U</b> for 'universal leaper' (able to leap to every square on the board except the one it is on),
29 but XBoard 4.8.0 does not implement those.
30 If a piece can do several unrelated moves, it is described by a concatenation of the descriptions of each group. 
31 </p>
32 <pre>
33 Table 1: moves of atoms
34 =======================
35 G Z C H C Z G     W = Wazir     (1,0)
36 Z A N D N A Z     F = Ferz      (1,1)
37 C N F W F N C     D = Dabbaba   (2,0)
38 H D W * W D H     N = Knight    (2,1)
39 C N F W F N C     A = Alfil     (2,2)
40 Z A N D N A Z     C = Camel     (3,1) older notation J
41 G Z C H C Z G     Z = Zebra     (3,2) older notation L
42 </pre>
43 <p>
44 <b>Range -</b> To describe sliders, the letter indicating the atom must be followed by a number,
45 which then indicates the maximum number of times the step described by the atom can be repeated in absence of obstacles.
46 By convention a 0 here means 'without limit'.
47 (Older versions of the notation duplicated the atom name for this, but XBoard does not understand that.)
48 Thus <b>N0</b> (obsolete <b>NN</b>) describes the Nightrider, repeating Knight steps in the same (but arbitrary) direction.
49 There are some shorthands for common expressions: <b>B</b>, <b>R</b>, <b>Q</b> and <b>K</b> describe the orthodox Chess pieces,
50 which formally should have been written as <b>F0</b>, <b>W0</b>, <b>F0W0</b> = <b>BR</b> and <b>FW</b>, respectively.
51 This way an Archbishop can be written as <b>BN</b>. (Or <b>NB</b>; the order has no significance.)
52 </p>
53 <p>
54 <b>Directional modifiers -</b> If a piece does not have all the 8 moves belonging to the atom (or 4 for purely diagonal or orthogonal moves),
55 the subset of it can be indicated by 'directional modifier' prefixes.
56 These are lower-case letters indicating directions or sets of directions:
57 f, b, r, l, v, s, h for forward, backward, right, left, vertical (f+b), sideway (l+r),
58 and half, respectively.
59 Note that the exact meaning of each of these depends on the type of atom;
60 for orthogonal moves f, b, r and l each specify a single move,
61 for diagonal and oblique moves they specify move pairs.
62 To subdivide the pairs, a second directional modifier for the perpendicular direction must again be written in front of the first.
63 So <b>lfN</b> corresponds to the move Ng1-f3, the left-most move of the forward pair.
64 Combinations like 'fh' can only be used on oblique moves, and do the opposite:
65 the 'h' expands the meaning of 'f' to all 4 moves that have a component in that general direction.
66 Directional modifiers that do not combine to a single direction imply that moving in each of the corresponding directions is allowed.
67 E.g. <b>frW</b> can move one step forward, or one step right (but not backward or left).
68 If what was parsed upto now can combine with the next letter, it will.
69 To avoid unwanted combining of adjacent directional modifiers to a single direction,
70 they sometimes need to be doubled, e.g. <b>ffrrN</b> is a Knight with the two forwardmost and rightmost moves.
71 </p>
72 <pre>
73 Table 2: directional modifiers
74 ==============================
75  K  N  K  N  K     Outer ring applies to 8-fold movers N and K
76  N  F  W  F  K     Inner ring applies to 4-fold movers F and W
77  K  W  *  W  K
78  N  F  W  F  K
79  K  N  K  N  K
80
81  half-planes      right/left pairs   single directions       chiral
82 fh fh fh fh fh     lv lv  . rv rv     lf lf ff rf rf      . hl  . hr  .
83 fh  f  .  f fh     ll  .  .  . rr     fl lf  f rf fr     hr  .  .  . hl
84  .  .  *  .  .      .  .  *  .  .     ll  l  *  r rr      .  .  *  .  .
85 bh  b  .  b bh     ll  .  .  . rr     bl lb  b rb br     hl  .  .  . hr
86 bh bh bh bh bh     lv lv  . rv rv     lb lb bb rb rb      . hr  . hl  .
87
88                   forw/backw pairs  diam. pairs/quartets
89 lh lh  . rh rh     fs ff  . ff fs      .  v  v  v  .
90 lh  l  .  r rh     fs  .  .  . fs      s  .  v  .  s
91 lh  .  *  . rh      .  .  *  .  .      s  s  *  s  s
92 lh  l  .  r rh     bs  .  .  . bs      s  .  v  .  s
93 lh lh  . rh rh     bs bb  . bb bs      .  v  v  v  .
94 </pre>
95 <p>
96 <b>Modality modifiers -</b> If a piece is 'divergent', i.e. it cannot both capture and non-capture with the same move,
97 then a 'move modality' prefix will describe what the move can do (c = capture, m = non-capture).
98 A Shatranj Pawn (which does not have initial double-push or e.p.) thus is <b>fmWfcF</b>.
99 </p>
100 <h2>Advanced modifiers</h2>
101 <p>
102 <b>Jumping -</b> The original Betza notation includes a number of special-purpose modifiers,
103 defined in a rather ad-hoc way to indicate certain aspects of common pieces that could not be handled by the basic system.
104 'Lame leapers' are pieces that can be blocked on squares they cannot move to,
105 and are indicated by modifiers 'j' and 'n', for 'must jump' and 'non-jumping'.
106 By default moves to non-neighboring squares can do both, as they completely ignore the state of other board squares,
107 even those geometrically between their origin and destination.
108 A Xiangqi Elephant would thus be <b>nA</b>, where a Shatranj Alfil is simply <b>A</b>.
109 The weakness of these modifiers is that they are only unambiguously defined on purely diagonal or orthogonal atoms,
110 as in other cases it is not clear what constitutes the path taken to reach the destination.
111 In XBoard 4.8.0 'n' or 'j' are only testing a single intermediate square, exactly halfway,
112 which should be considered broken for all atoms other than <b>N</b>, <b>A</b>, and <b>D</b>.
113 As fractional steps are rounded towards zero, this happens to make <b>nN</b> the Xiangqi Horse.
114 When (correctly) applied to atoms of longer stride, it can make sense to distinguish between prefixes 'j' (must jump one)
115 and 'jj' (can jump many).
116 </p>
117 <p>
118 <b>Hopping -</b> Hoppers are pieces that must move over an occupied square (the 'platform') that they might be able to move to in other situations.
119 Famous examples are the Xiangqi Cannon ('Pao', a Rook which must jump before it can capture),
120 and the Grasshopper (a Queen that can only land on squares directly behind the first obstacle in its path).
121 The modifier 'p' can prefix slider moves, and indicates that these moves can and must jump exactly one obstacle,
122 so that the Cannon can be denoted as <b>mRcpR</b>.
123 The modifier 'g' indicates a slider move that in a similar way can only continue a single step after hitting the obstacle,
124 so that a Grasshopper is <b>gQ</b>.
125 The more general case, where pieces could also change direction ('bifurcators') or stride after hopping the platform,
126 could not be covered in the original Betza system without introducing new ad-hoc modifiers describing each case separately.
127 XBoard 4.8.0 implements both 'g' and 'p'.
128 </p>
129 <p>
130 <b>Specials -</b> Other ad-hoc modifiers in the original Betza system are 'q' and 'z',
131 for riders that move along curved and zig-zag trajectories.
132 I.e. they take their consecutive steps not in the same direction, but with a fixed angle between them,
133 rotating in the same direction on every new step for 'q', and alternating direction for 'z'.
134 It is a bit ill-defined how exactly the direction changes; one assumes by the minimum amount, which depends on the atom.
135 The prefix 'o' is used to indicate moves on a cylinder board, which would wrap around from the side edges.
136 XBoard 4.8.0 does not implement the 'q' and 'z' modifiers, but it does implement 'o'.
137 </p>
138 <h2>XBoard-specific ad-hoc extensions and restrictions ('XBetza')</h2>
139 <p>
140 <b>En passant -</b> Not in the original Betza system, but very much in the spirit of it,
141 a prefix 'i' can be put on a move that is only allowed for 'virgin' pieces.
142 Similarly, 'e' is a very useful additional move modality next to 'm' and 'c',
143 indicating en-passant captures (which go to that empty square where the previous opponent's move could have been blocked due to an 'n' prefix,
144 had it not been empty, and remove that moved piece as a side effect).
145 These modifiers are implemented in XBoard 4.8.0, to allow accurate description of Pawns;
146 a FIDE Pawn would be <b>fmWfceFifmnD</b>, which includes both the blockable initial double push <b>ifmnD</b> and the e.p. capture <b>feF</b>
147 on top of the Shatranj Pawn.
148 The actual creation of e.p. rights and removal of the victim is still done by the hard-coded logic for Pawn moves, however,
149 irrespective of what you specify.
150 </p>
151 <p>
152 <b>Castling -</b> Unique to XBoard is a way to describe conventional castling with an <b>O</b> (oh) atom,
153 where the following number indicates the number of steps the piece having this move takes in the direction of the corner.
154 It implies that the corner piece then has to swing around it,
155 and applies the usual restrictions on virginity of the corner piece,
156 and not moving through check (if the described piece is royal, but currently XBoard only understands castling of Kings).
157 Not writing a castling move on the King makes it keep its original castling for the current variant!
158 To get a King that cannot castle in variants where it normally does, specify an initial position without castling rights. 
159 </p>
160 <b>Drops -</b> The atom <b>@</b> indicates a piece can be dropped from the hand. (Never mind how it got there!)
161 Directional modifiers make no sense here,
162 so the corresponding letters are reused to indicate other things.
163 'f' restricts the drop to board files that do not contain a piece of this type yet.
164 Similarly 's' forbids a drop on squares the same color as where there already is such a piece,
165 and 'b' even forbids the drop if there is already such a piece anywhere on the board.
166 These modifiers can be duplicated to crank up the maximum to two pieces of the same type.
167 XBoard 4.8.0 does not implement this atom, as it has its own hard-wired code for judging drops,
168 separate from the move generator, and does not highlight possible drop squares.
169 It terminates parsing the Betza string when it encounters '@' (as for any unrecognized atom),
170 so if it is included for future reference, it should better be the final atom.
171 </p>
172 <p>
173 A numeric suffix on the <b>@</b>, which normally would indicate a range,
174 indicates the depth of the 'drop zone' measured in ranks,
175 (default 1),
176 starting at the back rank.
177 A 'j' prefix means the back-rank itself is exempted.
178 So in Crazyhouse Pawns would have <b>j@7</b>, the other pieces <b>@8</b>.
179 In Shogi we have P:<b>fWf@8</b>, L:<b>fR@8</b>, N:<b>fN@7</b>, while other pieces would have <b>@9</b>.
180 </p>
181 <p>
182 <b>Skipping -</b> A 'j' modifier on a slider (<b>W<i>n</i></b> or <b>F<i>n</i></b>, as opposed to rider, which makes larger strides),
183 indicates it skips the first square, irrespective of its occupancy.
184 This overloading of the 'j' symbol is possible because the original meaning ('must jump')
185 makes no sense on <b>W</b> or <b>F</b>.
186 </p>
187 <p>
188 <b>Multi-leg -</b> Newly proposed is the 'a' ('again') modifier,
189 which indicates that the piece can do <i>another move</i> after its first one is completed.
190 modifiers preceding 'a' apply to the first 'leg' of the move, whatever follows is describes the second leg.
191 The direction and modality of the legs can thus be specified independently.
192 Together with some new conventions for the interpretation of the existing modifiers in such a context,
193 this makes an immensely powerful system, able to describe complex trajectories and many exotic modes of capture.
194 (e.g. a Checker can capture on its first <b>fF</b> step,
195 and then must move again in the same direction to an empty square, <b>fcafmF</b>).
196 Directions for a continuation leg are indicated <i>relative</i> to the previous leg,
197 where continuing in the same direction counts as 'forward'.
198 So <b>masR</b> would be a Rook that can do two moves per turn ('a'),
199 the second perpendicular to the first ('s'),
200 where the first should be a non-capture, ('m'), and the second can both capture and non-capture, as usual.
201 The continuation directions are specified in the (8-fold) K system even for 4-way atoms;
202 when purely orthogonal or diagonal atoms get a continuation direction specified that they do not have,
203 (i.e. intermediate to the directions they stand for),
204 they are <i>converted</i> into each other for the remainder of that move.
205 F interconverts with W, (and thus B with R), D with A and G with H this way.
206 E.g. <b>mafsR</b> for a trajectory that starts orthogonal and then bends 45 degrees ('fs') on any empty square ('m') reached that way.
207 </p>
208 <p>
209 For non-final legs there are more options for the modality that make sense than just mc:
210 because the moving piece doesn't intend to stay on that square, it is not necessary to clean the latter out.
211 We can also leave an occupant undisturbed, denoted by 'p', ('hop' or 'pass through').
212 Thus <b>pasR</b> would be a Rook that can turn a corner only at the point where it hits the first obstacle,
213 while <b>casR</b> would be a Rook that can capture a foe, and then continue at 90-degrees,
214 possibly for a second capture.
215 Of course it is possible to combine modalities, like <b>cpasR</b>, which either captures the platform, or leaves it undisturbed.
216 The 'a' can be applied multiple times;
217 <b>mamaK</b> means three King steps arbitrary changing direction, traversing empty intermediate squares only,
218 while it can capture (or just move to) the final square in the third step.
219 </p>
220 <p>
221 By default continuation legs go in all directions <i>except exactly backwards</i>.
222 Default modality in non-final legs is 'm', i.e. the intermediate square must be empty.
223 (So the leading 'm' in many of the preceding examples can actually be dropped, e.g. <b>aaK</b>,
224 although this often does not make it easier to understand the notation.)
225 The final leg follows the rules for single-leg moves, i.e. default modality 'mc',
226 while 'p' has a slightly different meaning there.
227 Note that an 'mp' modality on a non-final step makes it ignore the relay square completely.
228 This can be used to glue leaper moves into longer leaps in a 'transparent' way, e.g. <b>mpafN</b> for a (2,4) leaper.
229 </p>
230 <p>
231 The modifier 'g' can be generalized to non-final legs in a similar way as 'p',
232 the difference between the two (as always) being that the latter limits the range after the hop to a single step.
233 Thus <b>gQ</b> = <b>gafQ</b>, just as <b>pR</b> = <b>pafR</b>.
234 This can be generalized even further by making this work in the opposite direction as well,
235 turning leapers into sliders when the range already was 1.
236 This makes <b>gafK</b> a time-reversed Grasshopper, different from <b>pafK</b> = <b>nAnD</b>.
237 The range is changed by interconvering FWK with BRQ after stripping off any explicitly written range,
238 while on other atoms the written or implied range will be changed from 1 to infinite and from not-1 to 1.
239 This makes <b>gafsR</b> behave differently from <b>gafsW0</b>:
240 the first turns into <b>fsW</b> = <b>fF</b> and must thus land directly (diagonally) behind the platform,
241 but the latter changes into <b>fsR</b> = <b>fB</b> with unlimited range.
242 An extra modifier 't' can be combined with 'g' and 'p' to exclude hopping over enemy pieces.
243 </p>
244 <p>
245 Like 'g' is a range-changing version of 'p', both doing their thing at an occupied square,
246 the non-standard modifier 'y' can be seen as a range-changing version of 'm',
247 doing their thing on empty squares.
248 So where <b>masR</b> is a Hook Mover that does two perpendicular Rook moves,
249 <b>yafsW</b> would be a piece that makes a Bishop move after single W step.
250 This can also be used to indicate pieces that bend their path just before or after an obstacle as 3-leg moves:
251 <b>gabyabsR</b> would be a collision-type bifurcator, which moves like Rook to an obstacle and changes to W there ('g'),
252 takes one step back ('b'), spontaneously restoring the slider range ('y'),
253 and then continues with a sideway backward (compared to the previous leg, so forward w.r.t. the starting direction) = B move.
254 </p>
255 <p>
256 Beware: once a path bends, 'l' and 'r' are no longer symmetry equivalent,
257 and using 's' after that would describe two essentially different paths.
258 Oblique atoms already bend in the first step.
259 To make it easier to specify a unique path for their continuation,
260 the 'hr' and 'hl' direction-set specifiers are added to indicate the set of right-handed
261 an left-handed moves of those.
262 (In XBoard 4.8.0 these cannot be combined with other direction specifications!)
263 Thus a 'Chiral Knight' <b>hrN</b> on e4 attacks only to f6, g3, d2 and c5,
264 and writing the 'hr' and 'hl' moves separately allows you to write the
265 symmetry-equivalent path on the 'hl' moves with 'r' and 'l' interchanged.
266 Which you already could (and had to) do for chiral moves starting as orthogonal or diagonal atoms,
267 such as <b>afraflWaflafrW</b> for a lame <b>C</b> that can be blocked at W or N squares.
268 </p>
269 <p>
270 <b>Tame pieces -</b> XBoard interprets a modifier 't' on a final (or only) leg of a move as a prohibition to capture Kings.
271 This is intended as a work-around, to allow approximate description of pieces that are too complex for the current implemetation to handle.
272 Such an approximate description will either lack some legal moves,
273 (which is fatal, because XBoard will then reject those),
274 or have some extra imagined moves.
275 The latter would also be fatal, because checking with such an imagined move will make XBoard reject most opponent moves,
276 as it will insist the opponent evades the imagined check first.
277 By labeling all imagined moves as non-checking, XBoard will never reject anything that is legal,
278 while allowing something that was in fact illegal can always be rejected by the engine.
279 </p>
280 <p>
281 <b>XBoard limitations -</b> In Betza notation the modifiers can usually be permuted in many ways without altering the meaning,
282 but the XBoard implementation is more demanding;
283 the modifiers <u>must</u> come in the order i, <i>directional</i>, m, c, d, e, t, p, g, o, y, n, j.
284 Sinning against this directive will make it ignore many of the modifiers.
285 Ranges can be at most two digits and must not start with a redundant zero.
286 Parsing will terminate without error message when an unknown atom is encountered.
287 XBoard's internal move logic is limited to a single side-effect capture.
288 There is no limit on the number of 'non-destructive' legs, however.
289 Moves with a non-final-leg capture must be specified after other moves to that capture square.
290 Castling is reserved for Kings, (but any corner piece will do), and e.p. capture to Pawns.
291 </p>
292 <h1>Betza 2.0</h1>
293 <p>
294 The proposed Betza 2.0 extension of Betza notation is based on the concept of 'chaining':
295 a move can in general consist out of multiple legs,
296 which could have arbitrarily different properties.
297 (This is a generalization of the 'a' modifier, which has the limitation that both steps must belong to the same atom.)
298 So each leg is described using the full power of the basic Betza notation system,
299 and that they are part of the same move is indicated by chaining them with a dash ('-').
300 This method makes many of the ad-hoc modifiers of the original Betza system redundant;
301 a Xiangqi Elephant, for instance, can be described as <b>mF-F</b>, the first leg moving to an empty neighboring square,
302 the second leg continuing to the final destination without restriction.
303 The chain must thus be traversed as a whole, there can be no stopping half-way,
304 and by default later legs go in the same direction as the previous one.
305 A Checker can be described as <b>fmF(fcF-mF)</b>, where the first leg now is capture-only,
306 allowed only when it can complete the chain by continuing to an empty square.
307 (Parentheses are allowed in Betza 2.0 to enhance readability.)
308 </p>
309 <p>
310 To reap the full power of the chaining concept, some extra move modalities are needed on the legs,
311 which would make no sense on a complete move (i.e. on the final leg).
312 Unfortunately the original Betza system had more or less used up the alphabet completely.
313 But as it is always evident whether an atom is a complete move, or just a leg of a chain,
314 the same letters can be reused with (slightly) different meaning.
315 E.g. 'p' indicated a move that hopped, but on a leg it indicates the hop itself,
316 i.e. it has become a modality modifier that specifies moving into an occupied square without removing the occupant.
317 So the Cannon capture move becomes <b>pR-cR</b>: move to the platform as Rook, and continue to capture as Rook.
318 A Grasshopper becomes <b>pQ-K</b>: move to platform as Queen, and then continue (in the same direction) as King.
319 The 'g' prefix thus has become entirely superfluous, although <b>gQ</b> is of course more compact than <b>pQ-K</b>.
320 The latter is much more flexible, though, as it allows general 'identity change' after the hop,
321 such as for a 'bifurcator' <b>pR-B</b>, which moves to an obstacle like Rook, and then continues as Bishop.
322 </p>
323 <p>
324 Chaining allows detailed specification of the path taken to the destination square,
325 so that lame leapers can be described unambiguously even if they have oblique moves.
326 The Xiangqi Horse is mW-F, explicitly indicating it can be blocked only on the W squares.
327 To minimize writing, the default modality on non-final legs is taken as 'm' rather than 'mc',
328 as this is the far-more-common case, so that <b>W-F</b> will do for the Horse.
329 Bent trajectories can be indicated by slamming directional modifiers of the continuation legs.
330 Unlike general directional modifiers on complete moves, which are sets of directions,
331 continuation legs must specify a single direction to keep the path unique.
332 The convention here is that the directions are described relative to the previous leg,
333 where 'f' then indicates the direction that deflects least,
334 and thus is the default in continuation legs.
335 (Where for complete moves the default is of course the set of all directions.) 
336 </p>
337 <p>
338 Other useful move modalities on non-final legs are 'd' ('destroy', i.e. capture own piece),
339 't' ('test', i.e. hop over own piece only),
340 'o' (stray off board, to either re-enter it with a further leg or wrap around,
341 to describe bouncing and cylinder pieces),
342 and 'u' (to unload something that was captured or destroyed on an earlier leg,
343 to implement magnetic pieces and catapults, which displace other pieces as side effect of their move).
344 General side effects can then be implemented by specifying a path that makes the piece visit
345 all squares on which these side-effects should take place,
346 to remove pieces, carry them around and put them down elsewhere.
347 It would even be possible to describe castling by having the King carry the Rook to its destination,
348 e.g. <b>irdiW03-buD-bW</b> on the white King for O-O,
349 where the extra convention is used that 'di' indicates you can destroy virgin pieces only.
350 </p>
351 <h2>Quirky stuff</h2>
352 <p>
353 Betza 2.0 allows the use of parentheses for readability,
354 but also to turn a complex path into an atom,
355 on which a range can be specified to indicate how many times that entire path can be repeated.
356 E.g. <b>(W-F)0</b> is the Mao-rider, which repeats the (blockable) steps of the Xiangqi Horse.
357 The advantage over original Betza's <b>nN0</b> is that it can specify more precisely where the moves can be blocked.
358 </p>
359 <p>
360 The default left-leg modality and right-leg direction implied by a range count
361 can be overruled by putting modifiers on the range count itself.
362 Thus, where <b>N0</b> means Nightrider, <b>Nrf0</b> indicates a 'Rose', with a curved trajectory.
363 The advantage over original Betza's  <b>qN</b> is the possibility to precisely indicate the curvature.
364 This can also be used to get non-standard modality for intermediate steps:
365 <b>Rc0</b> describes a Rook that captures all enemies in its path!
366 (But it would be blocked by an own piece.
367 To also hop over these would require  <b>Rct0</b>,
368 and to destroy friend and foe alike  <b>Rcd0</b>.)
369 A modality prefix on the entire chain would only affect the final step.
370 </p>
371
372 </body>
373 </html>