]> git.sesse.net Git - stockfish/commitdiff
Retire move.h
authorMarco Costalba <mcostalba@gmail.com>
Sun, 4 Dec 2011 09:53:40 +0000 (10:53 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Sun, 4 Dec 2011 10:36:03 +0000 (11:36 +0100)
Also some assorted comments fixes and other trivia.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
19 files changed:
src/benchmark.cpp
src/book.cpp
src/book.h
src/misc.cpp
src/misc.h
src/move.cpp
src/move.h [deleted file]
src/movegen.cpp
src/movegen.h
src/movepick.h
src/position.h
src/psqtab.h
src/rkiss.h
src/search.cpp
src/search.h
src/timeman.h
src/tt.h
src/types.h
src/uci.cpp

index ee1128043f32f9b94f20f1722f2df55bc074ae5b..052176cdc2c9b11ee3c5605815ff742be4f50679 100644 (file)
@@ -28,7 +28,7 @@
 
 using namespace std;
 
 
 using namespace std;
 
-static const string Defaults[] = {
+static const char* Defaults[] = {
   "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1",
   "r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq - 0 10",
   "8/2p5/3p4/KP5r/1R3p1k/8/4P1P1/8 w - - 0 11",
   "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1",
   "r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq - 0 10",
   "8/2p5/3p4/KP5r/1R3p1k/8/4P1P1/8 w - - 0 11",
@@ -59,7 +59,7 @@ static const string Defaults[] = {
 
 void benchmark(int argc, char* argv[]) {
 
 
 void benchmark(int argc, char* argv[]) {
 
-  std::vector<Move> searchMoves(1, MOVE_NONE);
+  vector<Move> searchMoves(1, MOVE_NONE);
   vector<string> fenList;
   Search::LimitsType limits;
   int64_t totalNodes;
   vector<string> fenList;
   Search::LimitsType limits;
   int64_t totalNodes;
@@ -85,7 +85,10 @@ void benchmark(int argc, char* argv[]) {
       limits.maxDepth = atoi(valStr.c_str());
 
   // Do we need to load positions from a given FEN file?
       limits.maxDepth = atoi(valStr.c_str());
 
   // Do we need to load positions from a given FEN file?
-  if (fenFile != "default")
+  if (fenFile == "default")
+      for (int i = 0; *Defaults[i]; i++)
+          fenList.push_back(Defaults[i]);
+  else
   {
       string fen;
       ifstream f(fenFile.c_str());
   {
       string fen;
       ifstream f(fenFile.c_str());
@@ -102,9 +105,6 @@ void benchmark(int argc, char* argv[]) {
 
       f.close();
   }
 
       f.close();
   }
-  else // Load default positions
-      for (int i = 0; !Defaults[i].empty(); i++)
-          fenList.push_back(Defaults[i]);
 
   // Ok, let's start the benchmark !
   totalNodes = 0;
 
   // Ok, let's start the benchmark !
   totalNodes = 0;
index 243583ff18276000a7c5050f0a54ffe330ff0bff..427ae56e677fdcc3532958d3f10c8ab653ae98ca 100644 (file)
@@ -28,6 +28,7 @@
 #include <iostream>
 
 #include "book.h"
 #include <iostream>
 
 #include "book.h"
+#include "misc.h"
 #include "movegen.h"
 
 using namespace std;
 #include "movegen.h"
 
 using namespace std;
index 0690d32b5e015d02a9cdd5e97211acf1b6af2744..f84d93899a8d69ee80a1babb914ce3dbe79092ad 100644 (file)
 #include <fstream>
 #include <string>
 
 #include <fstream>
 #include <string>
 
-#include "move.h"
 #include "position.h"
 #include "rkiss.h"
 
 
 #include "position.h"
 #include "rkiss.h"
 
 
-// A Polyglot book is a series of "entries" of 16 bytes. All integers are
-// stored highest byte first (regardless of size). The entries are ordered
-// according to key. Lowest key first.
+/// A Polyglot book is a series of "entries" of 16 bytes. All integers are
+/// stored highest byte first (regardless of size). The entries are ordered
+/// according to key. Lowest key first.
 struct BookEntry {
   uint64_t key;
   uint16_t move;
 struct BookEntry {
   uint64_t key;
   uint16_t move;
index 5e851f12f6ded08dfdebb1c967e12bd822b30367..4d91c0fbb11ef8e4e2ba20a434b086400761e4e3 100644 (file)
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-#if !defined(_MSC_VER)
+#if defined(_MSC_VER)
+
+#define _CRT_SECURE_NO_DEPRECATE
+#define NOMINMAX // disable macros min() and max()
+#include <windows.h>
+#include <sys/timeb.h>
+
+#else
 
 #  include <sys/time.h>
 #  include <sys/types.h>
 
 #  include <sys/time.h>
 #  include <sys/types.h>
 #     include <sys/pstat.h>
 #  endif
 
 #     include <sys/pstat.h>
 #  endif
 
-#else
-
-#define _CRT_SECURE_NO_DEPRECATE
-#define NOMINMAX // disable macros min() and max()
-#include <windows.h>
-#include <sys/timeb.h>
-
 #endif
 
 #if !defined(NO_PREFETCH)
 #endif
 
 #if !defined(NO_PREFETCH)
@@ -178,18 +178,13 @@ int cpu_count() {
 /// timed_wait() waits for msec milliseconds. It is mainly an helper to wrap
 /// conversion from milliseconds to struct timespec, as used by pthreads.
 
 /// timed_wait() waits for msec milliseconds. It is mainly an helper to wrap
 /// conversion from milliseconds to struct timespec, as used by pthreads.
 
-#if defined(_MSC_VER)
-
 void timed_wait(WaitCondition* sleepCond, Lock* sleepLock, int msec) {
 void timed_wait(WaitCondition* sleepCond, Lock* sleepLock, int msec) {
-  cond_timedwait(sleepCond, sleepLock, msec);
-}
 
 
+#if defined(_MSC_VER)
+  int tm = msec;
 #else
 #else
-
-void timed_wait(WaitCondition* sleepCond, Lock* sleepLock, int msec) {
-
   struct timeval t;
   struct timeval t;
-  struct timespec abstime;
+  struct timespec abstime, *tm = &abstime;
 
   gettimeofday(&t, NULL);
 
 
   gettimeofday(&t, NULL);
 
@@ -201,12 +196,11 @@ void timed_wait(WaitCondition* sleepCond, Lock* sleepLock, int msec) {
       abstime.tv_sec += 1;
       abstime.tv_nsec -= 1000000000LL;
   }
       abstime.tv_sec += 1;
       abstime.tv_nsec -= 1000000000LL;
   }
+#endif
 
 
-  cond_timedwait(sleepCond, sleepLock, &abstime);
+  cond_timedwait(sleepCond, sleepLock, tm);
 }
 
 }
 
-#endif
-
 
 /// prefetch() preloads the given address in L1/L2 cache. This is a non
 /// blocking function and do not stalls the CPU waiting for data to be
 
 /// prefetch() preloads the given address in L1/L2 cache. This is a non
 /// blocking function and do not stalls the CPU waiting for data to be
index 92b97461faee9e883b6fbc85adcd22c35d731212..303514f7ffd2655a3e4c1dff2b36bab1f6ff3454 100644 (file)
@@ -41,6 +41,11 @@ extern void dbg_mean_of(int v);
 extern void dbg_print_hit_rate();
 extern void dbg_print_mean();
 
 extern void dbg_print_hit_rate();
 extern void dbg_print_mean();
 
+class Position;
+extern Move move_from_uci(const Position& pos, const std::string& str);
+extern const std::string move_to_uci(Move m, bool chess960);
+extern const std::string move_to_san(Position& pos, Move m);
+
 struct Log : public std::ofstream {
   Log(const std::string& f = "log.txt") : std::ofstream(f.c_str(), std::ios::out | std::ios::app) {}
  ~Log() { if (is_open()) close(); }
 struct Log : public std::ofstream {
   Log(const std::string& f = "log.txt") : std::ofstream(f.c_str(), std::ios::out | std::ios::app) {}
  ~Log() { if (is_open()) close(); }
index b019110b974f044db3f08bb262e6ead65c711d99..1a312cbc90e0e2f5744da9dae64a9e98fa92adf7 100644 (file)
@@ -21,7 +21,6 @@
 #include <cstring>
 #include <string>
 
 #include <cstring>
 #include <string>
 
-#include "move.h"
 #include "movegen.h"
 #include "position.h"
 
 #include "movegen.h"
 #include "position.h"
 
diff --git a/src/move.h b/src/move.h
deleted file mode 100644 (file)
index 99e0c44..0000000
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
-  Stockfish, a UCI chess playing engine derived from Glaurung 2.1
-  Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
-  Copyright (C) 2008-2010 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
-  the Free Software Foundation, either version 3 of the License, or
-  (at your option) any later version.
-
-  Stockfish is distributed in the hope that it will be useful,
-  but WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-  GNU General Public License for more details.
-
-  You should have received a copy of the GNU General Public License
-  along with this program.  If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#if !defined(MOVE_H_INCLUDED)
-#define MOVE_H_INCLUDED
-
-#include <string>
-
-#include "misc.h"
-#include "types.h"
-
-// Maximum number of allowed moves per position
-const int MAX_MOVES = 256;
-
-/// A move needs 16 bits to be stored
-///
-/// bit  0- 5: destination square (from 0 to 63)
-/// bit  6-11: origin square (from 0 to 63)
-/// bit 12-13: promotion piece type - 2 (from KNIGHT-2 to QUEEN-2)
-/// bit 14-15: special move flag: promotion (1), en passant (2), castle (3)
-///
-/// Special cases are MOVE_NONE and MOVE_NULL. We can sneak these in
-/// because in any normal move destination square is always different
-/// from origin square while MOVE_NONE and MOVE_NULL have the same
-/// origin and destination square, 0 and 1 respectively.
-
-enum Move {
-  MOVE_NONE = 0,
-  MOVE_NULL = 65
-};
-
-
-struct MoveStack {
-  Move move;
-  int score;
-};
-
-inline bool operator<(const MoveStack& f, const MoveStack& s) { return f.score < s.score; }
-
-// An helper insertion sort implementation, works with pointers and iterators
-template<typename T, typename K>
-inline void sort(K firstMove, K lastMove)
-{
-    T value;
-    K cur, p, d;
-
-    if (firstMove != lastMove)
-        for (cur = firstMove + 1; cur != lastMove; cur++)
-        {
-            p = d = cur;
-            value = *p--;
-            if (*p < value)
-            {
-                do *d = *p;
-                while (--d != firstMove && *--p < value);
-                *d = value;
-            }
-        }
-}
-
-inline Square move_from(Move m) {
-  return Square((m >> 6) & 0x3F);
-}
-
-inline Square move_to(Move m) {
-  return Square(m & 0x3F);
-}
-
-inline bool is_special(Move m) {
-  return m & (3 << 14);
-}
-
-inline bool is_promotion(Move m) {
-  return (m & (3 << 14)) == (1 << 14);
-}
-
-inline int is_enpassant(Move m) {
-  return (m & (3 << 14)) == (2 << 14);
-}
-
-inline int is_castle(Move m) {
-  return (m & (3 << 14)) == (3 << 14);
-}
-
-inline PieceType promotion_piece_type(Move m) {
-  return PieceType(((m >> 12) & 3) + 2);
-}
-
-inline Move make_move(Square from, Square to) {
-  return Move(to | (from << 6));
-}
-
-inline Move make_promotion_move(Square from, Square to, PieceType promotion) {
-  return Move(to | (from << 6) | (1 << 14) | ((promotion - 2) << 12)) ;
-}
-
-inline Move make_enpassant_move(Square from, Square to) {
-  return Move(to | (from << 6) | (2 << 14));
-}
-
-inline Move make_castle_move(Square from, Square to) {
-  return Move(to | (from << 6) | (3 << 14));
-}
-
-inline bool is_ok(Move m) {
-  return move_from(m) != move_to(m); // Catches also MOVE_NONE
-}
-
-class Position;
-
-extern const std::string move_to_uci(Move m, bool chess960);
-extern Move move_from_uci(const Position& pos, const std::string& str);
-extern const std::string move_to_san(Position& pos, Move m);
-
-#endif // !defined(MOVE_H_INCLUDED)
index ba1cc334f40cb8e3f69d043763ca2e16656ca426..aa5d28d416f18a333c9a33df4bf729a3bc54cb03 100644 (file)
@@ -47,8 +47,7 @@ namespace {
   template<PieceType Pt>
   inline MoveStack* generate_discovered_checks(const Position& pos, MoveStack* mlist, Square from) {
 
   template<PieceType Pt>
   inline MoveStack* generate_discovered_checks(const Position& pos, MoveStack* mlist, Square from) {
 
-    assert(Pt != QUEEN);
-    assert(Pt != PAWN);
+    assert(Pt != QUEEN && Pt != PAWN);
 
     Bitboard b = pos.attacks_from<Pt>(from) & pos.empty_squares();
 
 
     Bitboard b = pos.attacks_from<Pt>(from) & pos.empty_squares();
 
@@ -62,8 +61,7 @@ namespace {
   template<PieceType Pt>
   inline MoveStack* generate_direct_checks(const Position& pos, MoveStack* mlist, Color us,
                                            Bitboard dc, Square ksq) {
   template<PieceType Pt>
   inline MoveStack* generate_direct_checks(const Position& pos, MoveStack* mlist, Color us,
                                            Bitboard dc, Square ksq) {
-    assert(Pt != KING);
-    assert(Pt != PAWN);
+    assert(Pt != KING && Pt != PAWN);
 
     Bitboard checkSqs, b;
     Square from;
 
     Bitboard checkSqs, b;
     Square from;
@@ -198,7 +196,7 @@ template MoveStack* generate<MV_NON_CAPTURE>(const Position& pos, MoveStack* mli
 template MoveStack* generate<MV_NON_EVASION>(const Position& pos, MoveStack* mlist);
 
 
 template MoveStack* generate<MV_NON_EVASION>(const Position& pos, MoveStack* mlist);
 
 
-/// generate_non_capture_checks() generates all pseudo-legal non-captures and knight
+/// generate<MV_NON_CAPTURE_CHECK> generates all pseudo-legal non-captures and knight
 /// underpromotions that give check. Returns a pointer to the end of the move list.
 template<>
 MoveStack* generate<MV_NON_CAPTURE_CHECK>(const Position& pos, MoveStack* mlist) {
 /// underpromotions that give check. Returns a pointer to the end of the move list.
 template<>
 MoveStack* generate<MV_NON_CAPTURE_CHECK>(const Position& pos, MoveStack* mlist) {
@@ -238,8 +236,8 @@ MoveStack* generate<MV_NON_CAPTURE_CHECK>(const Position& pos, MoveStack* mlist)
 }
 
 
 }
 
 
-/// generate_evasions() generates all pseudo-legal check evasions when
-/// the side to move is in check. Returns a pointer to the end of the move list.
+/// generate<MV_EVASION> generates all pseudo-legal check evasions when the side
+/// to move is in check. Returns a pointer to the end of the move list.
 template<>
 MoveStack* generate<MV_EVASION>(const Position& pos, MoveStack* mlist) {
 
 template<>
 MoveStack* generate<MV_EVASION>(const Position& pos, MoveStack* mlist) {
 
index a80db334cbef6e9c1ba4e92e802588168ee4601b..38351e32f70c1b29eaf2df30acb5e197a2df980a 100644 (file)
@@ -20,7 +20,7 @@
 #if !defined(MOVEGEN_H_INCLUDED)
 #define MOVEGEN_H_INCLUDED
 
 #if !defined(MOVEGEN_H_INCLUDED)
 #define MOVEGEN_H_INCLUDED
 
-#include "move.h"
+#include "types.h"
 
 enum MoveType {
   MV_CAPTURE,
 
 enum MoveType {
   MV_CAPTURE,
@@ -32,6 +32,8 @@ enum MoveType {
   MV_LEGAL
 };
 
   MV_LEGAL
 };
 
+class Position;
+
 template<MoveType>
 MoveStack* generate(const Position& pos, MoveStack* mlist);
 
 template<MoveType>
 MoveStack* generate(const Position& pos, MoveStack* mlist);
 
index 3ade58edf3f9e7eac3975ded6e9d7157848f0d7e..34329582d18854ed989a87f8119a824baec0db85 100644 (file)
@@ -21,7 +21,6 @@
 #define MOVEPICK_H_INCLUDED
 
 #include "history.h"
 #define MOVEPICK_H_INCLUDED
 
 #include "history.h"
-#include "move.h"
 #include "position.h"
 #include "types.h"
 
 #include "position.h"
 #include "types.h"
 
index e4b6bd0f06123453a006abd6c1be70d67bbbe10c..e1bdf39e2b5bbbbf7c398016301672cebd17ab4a 100644 (file)
 #include <cassert>
 
 #include "bitboard.h"
 #include <cassert>
 
 #include "bitboard.h"
-#include "move.h"
 #include "types.h"
 
 
 /// The checkInfo struct is initialized at c'tor time and keeps info used
 /// to detect if a move gives check.
 #include "types.h"
 
 
 /// The checkInfo struct is initialized at c'tor time and keeps info used
 /// to detect if a move gives check.
+class Position;
 
 struct CheckInfo {
 
 
 struct CheckInfo {
 
-    explicit CheckInfo(const Position&);
+  explicit CheckInfo(const Position&);
 
 
-    Bitboard dcCandidates;
-    Bitboard pinned;
-    Bitboard checkSq[8];
+  Bitboard dcCandidates;
+  Bitboard pinned;
+  Bitboard checkSq[8];
 };
 
 
 };
 
 
@@ -44,7 +44,6 @@ struct CheckInfo {
 /// object to its previous state when we retract a move. Whenever a move
 /// is made on the board (by calling Position::do_move), an StateInfo object
 /// must be passed as a parameter.
 /// object to its previous state when we retract a move. Whenever a move
 /// is made on the board (by calling Position::do_move), an StateInfo object
 /// must be passed as a parameter.
-class Position;
 
 struct StateInfo {
   Key pawnKey, materialKey;
 
 struct StateInfo {
   Key pawnKey, materialKey;
index cfbf4a4d2fc8b3492f9a52dca855cd29bd813dbb..30df2b76282a753561a16e5added4a06cb82c3c4 100644 (file)
 
 #define S(mg, eg) make_score(mg, eg)
 
 
 #define S(mg, eg) make_score(mg, eg)
 
-// PSQT[PieceType][Square] contains Piece-Square scores. For each piece type on a
-// given square a (midgame, endgame) score pair is assigned. PSQT is defined for
-// white side, for black side the tables are symmetric.
+
+/// PSQT[PieceType][Square] contains Piece-Square scores. For each piece type on
+/// a given square a (midgame, endgame) score pair is assigned. PSQT is defined
+/// for white side, for black side the tables are symmetric.
+
 static const Score PSQT[][64] = {
   { },
   { // Pawn
 static const Score PSQT[][64] = {
   { },
   { // Pawn
index 5c01a0e56403da996e95a2997080698d2d3d764c..d017849568ac67aa70495f1d14dbf558c042da8f 100644 (file)
   available under the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.
   available under the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.
-
- ** George Marsaglia invented the RNG-Kiss-family in the early 90's.
- ** This is a specific version that Heinz van Saanen derived and
- ** tested from some public domain code by Bob Jenkins:
- **
- ** Quite platform independent
- ** Passes ALL dieharder tests! Here *nix sys-rand() e.g. fails miserably:-)
- ** ~12 times faster than my *nix sys-rand()
- ** ~4 times faster than SSE2-version of Mersenne twister
- ** Average cycle length: ~2^126
- ** 64 bit seed
- ** Return doubles with a full 53 bit mantissa
- ** Thread safe
 */
 
 #if !defined(RKISS_H_INCLUDED)
 */
 
 #if !defined(RKISS_H_INCLUDED)
 
 #include "types.h"
 
 
 #include "types.h"
 
+/// RKISS is our pseudo random number generator (PRNG) used to compute hash keys.
+/// George Marsaglia invented the RNG-Kiss-family in the early 90's. This is a
+/// specific version that Heinz van Saanen derived from some public domain code
+/// by Bob Jenkins. Following the feature list, as tested by Heinz.
+///
+/// - Quite platform independent
+/// - Passes ALL dieharder tests! Here *nix sys-rand() e.g. fails miserably:-)
+/// - ~12 times faster than my *nix sys-rand()
+/// - ~4 times faster than SSE2-version of Mersenne twister
+/// - Average cycle length: ~2^126
+/// - 64 bit seed
+/// - Return doubles with a full 53 bit mantissa
+/// - Thread safe
+
 class RKISS {
 
   // Keep variables always together
 class RKISS {
 
   // Keep variables always together
index 51c2a27d330a7b12626185d74100b5bbc0bcbc6f..e625405d5eec56d9759df974dfda90cc898aa2d8 100644 (file)
@@ -30,7 +30,6 @@
 #include "evaluate.h"
 #include "history.h"
 #include "misc.h"
 #include "evaluate.h"
 #include "history.h"
 #include "misc.h"
-#include "move.h"
 #include "movegen.h"
 #include "movepick.h"
 #include "search.h"
 #include "movegen.h"
 #include "movepick.h"
 #include "search.h"
@@ -353,10 +352,9 @@ int64_t Search::perft(Position& pos, Depth depth) {
 }
 
 
 }
 
 
-/// think() is the external interface to Stockfish's search, and is called when
-/// the program receives the UCI 'go' command. It initializes various global
-/// variables, and calls id_loop(). It returns false when a "quit" command is
-/// received during the search.
+/// think() is the external interface to Stockfish's search, and is called by the
+/// main thread when the program receives the UCI 'go' command. It searches from
+/// RootPosition and at the end prints the "bestmove" to output.
 
 void Search::think() {
 
 
 void Search::think() {
 
index 84704b0dc5d5a29ef177cdbbc8ae65951bd6cab0..53e7444c8ad205c5bb6cc34ce22e4b2009621d1f 100644 (file)
@@ -23,7 +23,6 @@
 #include <cstring>
 #include <vector>
 
 #include <cstring>
 #include <vector>
 
-#include "move.h"
 #include "types.h"
 
 class Position;
 #include "types.h"
 
 class Position;
@@ -74,7 +73,7 @@ extern void init();
 extern int64_t perft(Position& pos, Depth depth);
 extern void think();
 
 extern int64_t perft(Position& pos, Depth depth);
 extern void think();
 
-}
+} // namespace
 
 extern void do_timer_event();
 
 
 extern void do_timer_event();
 
index 703dc234b7cf630fdbe3bce62aae8a066377bd6b..ee5fdcf2083017cf678345c65db2adf67d2993ef 100644 (file)
 #if !defined(TIMEMAN_H_INCLUDED)
 #define TIMEMAN_H_INCLUDED
 
 #if !defined(TIMEMAN_H_INCLUDED)
 #define TIMEMAN_H_INCLUDED
 
-struct SearchLimits;
+/// The TimeManager class computes the optimal time to think depending on the
+/// maximum available time, the move game number and other parameters.
 
 class TimeManager {
 public:
 
 class TimeManager {
 public:
-
   void init(const Search::LimitsType& limits, int currentPly);
   void pv_instability(int curChanges, int prevChanges);
   int available_time() const { return optimumSearchTime + unstablePVExtraTime; }
   void init(const Search::LimitsType& limits, int currentPly);
   void pv_instability(int curChanges, int prevChanges);
   int available_time() const { return optimumSearchTime + unstablePVExtraTime; }
index 03147bf1a8f5aadb8deb0162902b023d0c574c32..16e1cd9da1da2c69462cdef31770a8f26bbaf38e 100644 (file)
--- a/src/tt.h
+++ b/src/tt.h
@@ -22,7 +22,7 @@
 
 #include <iostream>
 
 
 #include <iostream>
 
-#include "move.h"
+#include "misc.h"
 #include "types.h"
 
 
 #include "types.h"
 
 
index 7040b5ad8fd8d333835143ea5cb96566eb4dd1fd..b5898b2568d6ca22efa4b6c5ba756175e66fe9d6 100644 (file)
@@ -155,6 +155,7 @@ const bool CpuIs64Bit = false;
 typedef uint64_t Key;
 typedef uint64_t Bitboard;
 
 typedef uint64_t Key;
 typedef uint64_t Bitboard;
 
+const int MAX_MOVES = 256;
 const int PLY_MAX = 100;
 const int PLY_MAX_PLUS_2 = PLY_MAX + 2;
 
 const int PLY_MAX = 100;
 const int PLY_MAX_PLUS_2 = PLY_MAX + 2;
 
@@ -176,6 +177,31 @@ const Bitboard Rank6BB = Rank1BB << (8 * 5);
 const Bitboard Rank7BB = Rank1BB << (8 * 6);
 const Bitboard Rank8BB = Rank1BB << (8 * 7);
 
 const Bitboard Rank7BB = Rank1BB << (8 * 6);
 const Bitboard Rank8BB = Rank1BB << (8 * 7);
 
+/// A move needs 16 bits to be stored
+///
+/// bit  0- 5: destination square (from 0 to 63)
+/// bit  6-11: origin square (from 0 to 63)
+/// bit 12-13: promotion piece type - 2 (from KNIGHT-2 to QUEEN-2)
+/// bit 14-15: special move flag: promotion (1), en passant (2), castle (3)
+///
+/// Special cases are MOVE_NONE and MOVE_NULL. We can sneak these in because in
+/// any normal move destination square is always different from origin square
+/// while MOVE_NONE and MOVE_NULL have the same origin and destination square.
+
+enum Move {
+  MOVE_NONE = 0,
+  MOVE_NULL = 65
+};
+
+struct MoveStack {
+  Move move;
+  int score;
+};
+
+inline bool operator<(const MoveStack& f, const MoveStack& s) {
+  return f.score < s.score;
+}
+
 enum ValueType {
   VALUE_TYPE_NONE  = 0,
   VALUE_TYPE_UPPER = 1,
 enum ValueType {
   VALUE_TYPE_NONE  = 0,
   VALUE_TYPE_UPPER = 1,
@@ -467,4 +493,73 @@ inline Square pawn_push(Color c) {
   return c == WHITE ? DELTA_N : DELTA_S;
 }
 
   return c == WHITE ? DELTA_N : DELTA_S;
 }
 
+// An helper insertion sort implementation, works with pointers and iterators
+template<typename T, typename K>
+inline void sort(K firstMove, K lastMove)
+{
+  T value;
+  K cur, p, d;
+
+  if (firstMove != lastMove)
+      for (cur = firstMove + 1; cur != lastMove; cur++)
+      {
+          p = d = cur;
+          value = *p--;
+          if (*p < value)
+          {
+              do *d = *p;
+              while (--d != firstMove && *--p < value);
+              *d = value;
+          }
+      }
+}
+
+inline Square move_from(Move m) {
+  return Square((m >> 6) & 0x3F);
+}
+
+inline Square move_to(Move m) {
+  return Square(m & 0x3F);
+}
+
+inline bool is_special(Move m) {
+  return m & (3 << 14);
+}
+
+inline bool is_promotion(Move m) {
+  return (m & (3 << 14)) == (1 << 14);
+}
+
+inline int is_enpassant(Move m) {
+  return (m & (3 << 14)) == (2 << 14);
+}
+
+inline int is_castle(Move m) {
+  return (m & (3 << 14)) == (3 << 14);
+}
+
+inline PieceType promotion_piece_type(Move m) {
+  return PieceType(((m >> 12) & 3) + 2);
+}
+
+inline Move make_move(Square from, Square to) {
+  return Move(to | (from << 6));
+}
+
+inline Move make_promotion_move(Square from, Square to, PieceType promotion) {
+  return Move(to | (from << 6) | (1 << 14) | ((promotion - 2) << 12)) ;
+}
+
+inline Move make_enpassant_move(Square from, Square to) {
+  return Move(to | (from << 6) | (2 << 14));
+}
+
+inline Move make_castle_move(Square from, Square to) {
+  return Move(to | (from << 6) | (3 << 14));
+}
+
+inline bool is_ok(Move m) {
+  return move_from(m) != move_to(m); // Catches also MOVE_NULL and MOVE_NONE
+}
+
 #endif // !defined(TYPES_H_INCLUDED)
 #endif // !defined(TYPES_H_INCLUDED)
index fb2d3eac5834e7e9d8dc28b88dc7022cef7e96fa..9948eb62b4114670d826ec7e32c3f9012f53e0e0 100644 (file)
@@ -24,7 +24,6 @@
 
 #include "evaluate.h"
 #include "misc.h"
 
 #include "evaluate.h"
 #include "misc.h"
-#include "move.h"
 #include "position.h"
 #include "search.h"
 #include "thread.h"
 #include "position.h"
 #include "search.h"
 #include "thread.h"