Difference between revisions of "Squares"

From Chessprogramming wiki
Jump to: navigation, search
(Created page with "'''Home * Chess * Squares''' border|right|thumb| [[Arts#Mondrian|Piet Mondrian - Tableau I <ref>Arts#Mondrian|Pi...")
 
 
(4 intermediate revisions by the same user not shown)
Line 2: Line 2:
  
 
[[FILE:Tableau I, by Piet Mondriaan.jpg|border|right|thumb|
 
[[FILE:Tableau I, by Piet Mondriaan.jpg|border|right|thumb|
[[Arts#Mondrian|Piet Mondrian]] - Tableau I <ref>[[Arts#Mondrian|Piet Mondrian]] - [https://commons.wikimedia.org/wiki/File:Tableau_I,_by_Piet_Mondriaan.jpg Tableau I], 1921, [https://en.wikipedia.org/wiki/Gemeentemuseum_Den_Haag Gemeentemuseum Den Haag]</ref>]]  
+
[[:Category:Piet Mondrian|Piet Mondrian]] - Tableau I <ref>[[:Category:Piet Mondrian|Piet Mondrian]] - [https://commons.wikimedia.org/wiki/File:Tableau_I,_by_Piet_Mondriaan.jpg Tableau I], 1921, [https://en.wikipedia.org/wiki/Gemeentemuseum_Den_Haag Gemeentemuseum Den Haag]</ref>]]  
  
 
A '''Square''' in chess is one of 64 elements of a [[Chessboard|chessboard]], which might be empty or [[Occupancy|occupied]] by a chess [[Pieces|man]]. '''Square centric''' [[Board Representation|representations]], like [[Mailbox|mailbox]] or [[0x88]] board [[Array|arrays]], contain [[Pieces#PieceCoding|piece codes]], the information, what piece, if any, resides on a particular square. The '''piece centric''' [[Bitboards|bitboard]], as array of 64 bits, represent a boolean property of each square by a single bit.  
 
A '''Square''' in chess is one of 64 elements of a [[Chessboard|chessboard]], which might be empty or [[Occupancy|occupied]] by a chess [[Pieces|man]]. '''Square centric''' [[Board Representation|representations]], like [[Mailbox|mailbox]] or [[0x88]] board [[Array|arrays]], contain [[Pieces#PieceCoding|piece codes]], the information, what piece, if any, resides on a particular square. The '''piece centric''' [[Bitboards|bitboard]], as array of 64 bits, represent a boolean property of each square by a single bit.  
Line 23: Line 23:
 
<span id="Algebraic"></span>
 
<span id="Algebraic"></span>
 
=Algebraic Square Notation=
 
=Algebraic Square Notation=
In [[Algebraic chess notation]] a [[Target Square|target square]] of a [[Moves|move]] is specified by two characters for its [https://en.wikipedia.org/wiki/Cartesian_coordinates cartesian coordinate], per convention a letter for the [[Files|file]] ('a'-'h'), followed by a digit for the [[Ranks|rank]] number ('1'-'8').
+
In [[Algebraic Chess Notation|algebraic chess notation]] a [[Target Square|target square]] of a [[Moves|move]] is specified by two characters for its [https://en.wikipedia.org/wiki/Cartesian_coordinates cartesian coordinate], per convention a letter for the [[Files|file]] ('a'-'h'), followed by a digit for the [[Ranks|rank]] number ('1'-'8').
  
 
=Square Definition=  
 
=Square Definition=  
Line 68: Line 68:
 
* [[Intersection Squares]]
 
* [[Intersection Squares]]
 
* [[Butterfly Boards]]
 
* [[Butterfly Boards]]
 +
* [[Files#TwoSquares|Two Squares on a File]]
 +
* [[Ranks#TwoSquares|Two Squares on a Rank]]
 +
* [[Diagonals#TwoSquares|Two Squares on a Diagonal]]
 +
* [[Anti-Diagonals#TwoSquares|Two Squares on a Anti-Diagonal]]
 
==Areas==  
 
==Areas==  
 
* [[Center]]
 
* [[Center]]
Line 76: Line 80:
 
* [[Chessboard]]
 
* [[Chessboard]]
 
* [[Board Representation]]
 
* [[Board Representation]]
: [[Mailbox]]
+
** [[Mailbox]]
: [[0x88|0x88 Board Representation]]
+
** [[Vector Attacks]]
: [[Bitboards]]
+
** [[Bitboards]]
** [[Flipping Mirroring and Rotating]]
+
*** [[Flipping Mirroring and Rotating]]
** [[Square Mapping Considerations]]
+
*** [[Square Mapping Considerations]]
** [[King Pattern#SetwiseRuleoftheSquare|Setwise Rule of the Square]]
+
*** [[King Pattern#SetwiseRuleoftheSquare|Setwise Rule of the Square]]
: [[Quad-Bitboards]]
+
** [[Quad-Bitboards]]
  
 
=Pawn Squares=
 
=Pawn Squares=
 
* [[En passant]]
 
* [[En passant]]
: [[Forsyth-Edwards Notation#Enpassanttargetsquare|En passant target square]] inside the [[Forsyth-Edwards Notation]]
+
** [[Forsyth-Edwards Notation#Enpassanttargetsquare|En passant target square]] inside the [[Forsyth-Edwards Notation]]
 
* [[Promotion Square]]
 
* [[Promotion Square]]
 
* [[Stop Square]]
 
* [[Stop Square]]
Line 97: Line 101:
 
* [https://en.wikipedia.org/wiki/Square Square from Wikipedia]
 
* [https://en.wikipedia.org/wiki/Square Square from Wikipedia]
 
* [https://en.wikipedia.org/wiki/Magic_square Magic square from Wikipedia]
 
* [https://en.wikipedia.org/wiki/Magic_square Magic square from Wikipedia]
* [http://www.chess.com/article/view/the-eulers-8x8-magic-square The Euler's 8x8 magic square - Chess.com]
+
* [http://www.chess.com/article/view/the-eulers-8x8-magic-square The Euler's 8x8 magic square], [[Chess.com]]
  
 
=References=  
 
=References=  
Line 103: Line 107:
  
 
'''[[Chess|Up one Level]]'''
 
'''[[Chess|Up one Level]]'''
 +
[[Category:Piet Mondrian]]

Latest revision as of 18:40, 25 February 2021

Home * Chess * Squares

Piet Mondrian - Tableau I [1]

A Square in chess is one of 64 elements of a chessboard, which might be empty or occupied by a chess man. Square centric representations, like mailbox or 0x88 board arrays, contain piece codes, the information, what piece, if any, resides on a particular square. The piece centric bitboard, as array of 64 bits, represent a boolean property of each square by a single bit.

Depending on the underlying data structure of the board representation, each square has an address inside the board. Square centric representations keep arrays of squares, containing the information which piece (if any) resides on each square. That is why these representation is often called mailbox approach, since each square has a associated mailbox which is either empty or contains a chess piece. To find the address of a certain square index in the a1..h8 aka 0..63 range sometimes requires additional computation or lookup, for instance to map coordinates for 0x88 boards or surrounded mailbox boards.

In bitboards the address of a square correspondents to a bit-index, containing a boolean property of that square (bit set), or not (bit clear). The square mapping determines how bit-indices associate the squares on the board.

Square by Rank and File

A Square, like a point inside a cartesian coordinate system, can be determined by x- and y-coordinates, here the labels of files and ranks. Since each rank and file has eight squares, the mentioned rank-file mapping implies following formulas to determine the the square address:

square = 8*rank + file;
square = (rank << 3) + file;

with the obvious relation to calculate rank- and file-indices from the square index:

rank = square >> 3; // div 8
file = square  & 7; // modulo 8

Algebraic Square Notation

In algebraic chess notation a target square of a move is specified by two characters for its cartesian coordinate, per convention a letter for the file ('a'-'h'), followed by a digit for the rank number ('1'-'8').

Square Definition

A typical little-endian rank-file mapping enumeration in C++:

enum enumSquare {
  a1, b1, c1, d1, e1, f1, g1, h1,
  a2, b2, c2, d2, e2, f2, g2, h2,
  a3, b3, c3, d3, e3, f3, g3, h3,
  a4, b4, c4, d4, e4, f4, g4, h4,
  a5, b5, c5, d5, e5, f5, g5, h5,
  a6, b6, c6, d6, e6, f6, g6, h6,
  a7, b7, c7, d7, e7, f7, g7, h7,
  a8, b8, c8, d8, e8, f8, g8, h8
};

Square Properties

Multiple Squares

Lines

Two squares

Often, but not always related to a move

Areas

The whole Board

Lists, Arrays and Sets of Squares

Pawn Squares

See also

External Links

References

Up one Level