Files

From Chessprogramming wiki
Revision as of 21:51, 15 May 2018 by GerdIsenberg (talk | contribs)
Jump to: navigation, search

Home * Chess * Files

For disambiguation see also Computer file

Files are the eight vertical lines or columns of a Chessboard, labeled from 'A' to 'H', or 'a' to 'h'. Each file contains eight vertically arranged Squares of alternating white and black, or light and dark Color.

File Names

In a descriptive notation, files are also nominated by the Pieces from their initial position (similar to Pawns), like Rook-Files (a- and h-File, see diagram), Knight-Files (b- and g-File), Bishop-Files (c- and f-File), and Queen-File (d-File) and King-File (e-File), also called Center Files.

 abcdefgh 
8
7
6
5
4
3
2
1
    
    
    
    
    
    
    
    
        
        
        
        
        
        
        
        
•      •
•      •
•      •
•      •
•      •
•      •
•      •
•      •
8
7
6
5
4
3
2
1
 abcdefgh 

Square Mapping Notes

Whether the square difference of neighbored squares on a rank or file is either 1 or 8, depends on the square mapping. We further rely on little-endian rank-file mapping, which keeps consecutive squares of a rank as neighbored elements in Memory (or register).

Square Difference

Within a 0..63 square index range and the mentioned square mapping (a1 = 0), the difference of two neighbored squares on a File is eight.

Enumeration

As mentioned, on a Chessboard the eight files are labeled from 'A' to 'H'. To make them zero based indices as appropriate for C like programming languages, we enumerate files from 0 to 7. Little-endian file-mapping (as used here) assigns the A-File to index zero. Three bits are required to enumerate from 0 to 7.

A little-endian file-mapping enumeration in C++ might look like this:

enum enumFile {
  efAFile = 0,
  efBFile = 1,
  efCFile = 2,
  efDFile = 3,
  efEFile = 4,
  efFFile = 5,
  efGFile = 6,
  efHFile = 7,
};

File from Square

Rank-File mapping of squares keeps the file as the three lower bits of a Square index.

file = square & 7; // modulo 8

File-Distance

The file-distance is the absolute difference between two files (their 0-7 indices). The maximum file-distance is 7.

fileDistance = abs (file1 - file2);
fileDistance = abs (file2 - file1);

Pawns and Files

See also

Up one Level