/*
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
- Copyright (C) 2008-2012 Marco Costalba, Joona Kiiski, Tord Romstad
+ Copyright (C) 2008-2013 Marco Costalba, Joona Kiiski, Tord Romstad
Stockfish is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
/// | only in 64-bit mode. For compiling requires hardware with
/// | popcnt support.
+#include <cassert>
#include <cctype>
#include <climits>
#include <cstdlib>
enum Phase {
PHASE_ENDGAME = 0,
- PHASE_MIDGAME = 128
+ PHASE_MIDGAME = 128,
+ MG = 0, EG = 1, PHASE_NB = 2
};
enum ScaleFactor {
VALUE_ENSURE_INTEGER_SIZE_P = INT_MAX,
VALUE_ENSURE_INTEGER_SIZE_N = INT_MIN,
- Mg = 0, Eg = 1,
-
PawnValueMg = 198, PawnValueEg = 258,
KnightValueMg = 817, KnightValueEg = 846,
BishopValueMg = 836, BishopValueEg = 857,
};
enum Piece {
- NO_PIECE = 16, // color_of(NO_PIECE) == NO_COLOR
+ NO_PIECE = 0,
W_PAWN = 1, W_KNIGHT = 2, W_BISHOP = 3, W_ROOK = 4, W_QUEEN = 5, W_KING = 6,
B_PAWN = 9, B_KNIGHT = 10, B_BISHOP = 11, B_ROOK = 12, B_QUEEN = 13, B_KING = 14,
PIECE_NB = 16
CACHE_LINE_ALIGNMENT
extern Score pieceSquareTable[PIECE_NB][SQUARE_NB];
-extern Value PieceValue[2][18]; // [Mg / Eg][piece / pieceType]
+extern Value PieceValue[PHASE_NB][PIECE_NB];
extern int SquareDistance[SQUARE_NB][SQUARE_NB];
struct MoveStack {
}
inline Color color_of(Piece p) {
+ assert(p != NO_PIECE);
return Color(p >> 3);
}
return SquareDistance[s1][s2];
}
-inline char file_to_char(File f) {
- return char(f - FILE_A + int('a'));
+inline char file_to_char(File f, bool tolower = true) {
+ return char(f - FILE_A + (tolower ? 'a' : 'A'));
}
inline char rank_to_char(Rank r) {
- return char(r - RANK_1 + int('1'));
+ return char(r - RANK_1 + '1');
}
inline Square pawn_push(Color c) {
template<MoveType T>
inline Move make(Square from, Square to, PieceType pt = KNIGHT) {
- return Move(to | (from << 6) | T | ((pt - KNIGHT) << 12)) ;
+ return Move(to | (from << 6) | T | ((pt - KNIGHT) << 12));
}
inline bool is_ok(Move m) {
return ch;
}
-/// Our insertion sort implementation, works with pointers and iterators and is
-/// guaranteed to be stable, as is needed.
-template<typename T, typename K>
-void sort(K first, K last)
-{
- T tmp;
- K p, q;
-
- for (p = first + 1; p < last; p++)
- {
- tmp = *p;
- for (q = p; q != first && *(q-1) < tmp; --q)
- *q = *(q-1);
- *q = tmp;
- }
-}
-
#endif // !defined(TYPES_H_INCLUDED)