Direction

Home * Chess * Squares * Direction



The Direction is a information of the geometrical relation of two squares on a chessboard without the information of distance. Mathematically, direction may be uniquely specified by a unit vector, or equivalently by the angle with respect to a specified set of axes.

=Move Directions= Directions on the chessboard are usually related to from- to-coordinates of moves, that is four orthogonal and four diagonal ray-directions plus the eight directions a knight may move. Following Compass roses give the directions and single step increments of an 8x8 Board.

Ray Directions
northwest   north   northeast noWe        nort         noEa +7   +8    +9              \  |  /  west    -1 <-  0 -> +1    east / |  \          -9    -8    -7  soWe         sout         soEa southwest   south   southeast

Knight Directions
noNoWe   noNoEa +15 +17             |     | noWeWe  +6 __|     |__+10  noEaEa \  /               >0<           __ /   \ __ soWeWe -10   |     |   -6  soEaEa |    |            -17  -15        soSoWe    soSoEa

=Directions between any Squares=

In Degrees
Based on arctangent of the quotient of file- and rank-distance, one may calculate following 15 times 15 sheet with all possible angels which might occur between any squares in Degree (rounded to integer). Inner squares whose angle occur on farther squares are left blank, so each angle given is distinct, 144 from 224 (15x15-1), move directions are given in bold:

In Begrees
Enumerating all distinct integer degrees of the above rose in order but without any gaps, leaves a circle with 144 board degrees (Begrees) - only the 16 angels with modulo 9 equals zero are actually covered by move directions (bold). A possible application of Begrees is to select moves with a direction to an "interesting" area of the board, specified by some center- or gravity square.

Opposed to the compass-rose above, all inner squares are filled with Begrees as well.

=Lookup= Since the computation is quite expensive, a two dimensional table with pre-calculated values might be used for that purpose. The enumerated type enumDir might contain only ray- or move directions, Degrees, Begrees, or a structure combining them. enumDir arrDirection[64][64]; // 4 KByte

enumDir direction(enumSquare sq1, enumSquare sq2) { return arrDirection[sq1][sq2]; } =Lookup by 0x88 Difference= The 0x88 square relation permits a denser lookup approach. The difference of valid 0x88 coordinates of two squares is unique with respect to distance and direction. That way, one can greatly reduce the size of the lookup array to only 240 instead of 4096 elements. Some additional computation required, if one has to convert usual square coordinates to 0x88. If one already relies on 0x88 coordinates, it becomes even cheaper: enumDir arrDirectionBy0x88Diff[240];

unsigned int x88diff(enumSquare sq1, enumSquare sq2) { return sq2 - sq1 + (sq2|7) - (sq1|7) + 120; }

enumDir direction(enumSquare sq1, enumSquare sq2) { return arrDirectionBy0x88Diff[x88diff(sq1, sq2)]; } =See also=
 * 0x88 Square Relations
 * Attacks on the otherwise empty Board
 * Butterfly Boards
 * Distance
 * Flipping Mirroring and Rotating
 * Intersection Squares
 * Knight-Distance
 * Manhattan-Distance
 * Pieces versus Directions
 * Vector Attacks

=Forum Posts=
 * Extract direction (ray) informations from two squares by Mathieu Pagé, CCC, June 18, 2013 » Rays, Square Attacked By

=External Links=
 * Direction from Wikipedia
 * Relative direction from Wikipedia
 * Windward and leeward from Wikipedia
 * Starboard from Wikipedia
 * Port (nautical) from Wikipedia
 * Origins of the Compass Rose by Bill Thoen
 * Boxing the compass from Wikipedia
 * Weather Report - Directions, 73rd NDR-Jazzworkshop, IFA Berlin, September 03, 1971, YouTube Video
 * Joe Zawinul, Wayne Shorter, Miroslav Vitouš, Alphonse Mouzon, Dom Um Romão, & guests John Surman, Eje Thelin, Alan Skidmore

=References=

Up one Level