Module pleco::core::sq [−][src]
Contains the representation of a chessboard's square.
Internally, a SQ
is just a u8. The number of a SQ
maps to the following
squares of a chessboard:
8 | 56 57 58 59 60 61 62 63
7 | 48 49 50 51 52 53 54 55
6 | 40 41 42 43 44 45 46 47
5 | 32 33 34 35 36 37 38 39
4 | 24 25 26 27 28 29 30 31
3 | 16 17 18 19 20 21 22 23
2 | 8 9 10 11 12 13 14 15
1 | 0 1 2 3 4 5 6 7
-------------------------
a b c d e f g h
Examples
use pleco::core::sq::*; let h1 = SQ::H1; let h2 = SQ::H2; let g2 = SQ(14); assert_eq!(h1.distance(h2), 1); assert_eq!(h1.file(), h2.file()); assert_eq!(g2.rank(), h2.rank());
Use of NO_SQ
NO_SQ
is used to signify the lack of a legal square. Think about this as being a
lazy version of Option<SQ>
where the result is None
. With normal operation, this
shouldn't be a case worth considering.
use pleco::core::sq::*; let no_sq: SQ = NO_SQ; let sq_64 = SQ(64); assert!(!no_sq.is_okay()); assert!(!sq_64.is_okay()); assert_eq!(no_sq, sq_64);
General Safety
Generally, all of these methods for a SQ
are safe to use. The exception to this is
when a SQ::is_okay()
returns false, meaning the square is outside the legal bounds.
If methods are used on a square that is not legal, then undefined behavior will follow.
Structs
SQ |
Represents a singular square of a chessboard. |
Constants
NO_SQ |
|