[gray-matter] r1610 committed - some better testing code....

0 views
Skip to first unread message

codesite...@google.com

unread,
Jul 30, 2010, 12:42:22 PM7/30/10
to gray-matter-...@googlegroups.com
Revision: 1610
Author: protonspring
Date: Fri Jul 30 09:41:31 2010
Log: some better testing code.
some formatting.
some removal of unused old code.
a simple hash table implementation.
fixed insufficient: issue 44.


http://code.google.com/p/gray-matter/source/detail?r=1610

Modified:
/trunk/inc/table.h
/trunk/inc/xboard.h
/trunk/src/board_base.cpp
/trunk/src/search_mtdf.cpp
/trunk/src/xboard.cpp

=======================================
--- /trunk/inc/table.h Sun Sep 6 02:36:34 2009
+++ /trunk/inc/table.h Fri Jul 30 09:41:31 2010
@@ -73,50 +73,30 @@

inline bool probe(bitboard_t hash, int depth, int type, Move *move_ptr)
{
- uint64_t index = 0;
- index += (hash & 0x0000000000FFFFFFLL);
- index += (hash & 0x00000000FFFFFF00LL) >> 2;
- index += (hash & 0x000000FFFFFF0000LL) >> 4;
- index += (hash & 0x0000FFFFFF000000LL) >> 6;
- index += (hash & 0x00FFFFFF00000000LL) >> 8;
- index += (hash & 0xFFFFFF0000000000LL) >> 10;
- index = index%slots;
-
- if (data[index].hash == hash)
- {
+ uint64_t index = hash%slots;
+
+ if (data[index].hash == hash)
+ {
+ if (data[index].depth > depth)
+ {
+ //we've already searched this node
+ //the the specified depth or greater, so just
+ //return the move
*move_ptr = data[index].move;
- if (data[index].depth > depth &&
- (data[index].type == BOOK ||
- data[index].type == EXACT ||
- data[index].type == type))
- {
- //successful++;
- //total++;
- return true;
- }
- //semi_successful++;
- //total++;
- return false;
- }
- move_ptr->set_null();
- move_ptr->value = 0;
- //unsuccessful++;
- //total++;
+ return true;
+ }
+ }
return false;
}
+
+
inline void store(bitboard_t hash, int depth, int type, Move& move)
{
- uint64_t index = 0;
- index += (hash & 0x0000000000FFFFFFLL);
- index += (hash & 0x00000000FFFFFF00LL) >> 2;
- index += (hash & 0x000000FFFFFF0000LL) >> 4;
- index += (hash & 0x0000FFFFFF000000LL) >> 6;
- index += (hash & 0x00FFFFFF00000000LL) >> 8;
- index += (hash & 0xFFFFFF0000000000LL) >> 10;
- index = index%slots;
-
- //overwrite if deeper or in conflict
- if ((data[index].hash != hash) ||
+ uint64_t index = hash%slots;
+
+ //overwrite if same board and deeper
+ //or in conflict
+ if ((data[index].hash != hash) ||
(depth > data[index].depth))
{
data[index].hash = hash;
@@ -126,13 +106,10 @@
return;
}
}
+
private:
uint64_t slots; ///< The number of slots.
xpos_slot_t *data; ///< The slots themselves.
- //int successful; ///< The number of successful queries.
- //int semi_successful; ///< The number of semi-successful queries.
- //int unsuccessful; ///< The number of unsuccessful queries;
- //int total; ///< The total number of queries.
};


/*----------------------------------------------------------------------------*\
@@ -183,24 +160,20 @@
void clear();
inline bool probe(bitboard_t hash, value_t *value_ptr)
{
- /// Given the pawn structure described in hash, check the pawn
table to see if
- /// we've evaluated it before. If so, then save its previous
evaluation to the
- /// memory pointed to by value_ptr and return success. If not,
then return
+ /// Given the pawn structure described in hash, check the
+ /// pawn table to see if we've evaluated it before. If so,
+ /// then save its previous evaluation to the memory pointed
+ /// to by value_ptr and return success. If not, then return
/// failure.
-
uint64_t index = hash % slots;
bool found = data[index].hash == hash;
*value_ptr = found ? data[index].value : 0;
- //successful += found ? 1 : 0;
- //unsuccessful += found ? 0 : 1;
- //total++;
return found;
}
inline void store(bitboard_t hash, value_t value)
{
/// We've just evaluated the pawn structure described in hash. Save
its
/// evaluation in the pawn table for future probes.
-
uint64_t index = hash % slots;
data[index].hash = hash;
data[index].value = value;
@@ -208,9 +181,6 @@
private:
uint64_t slots; ///< The number of slots.
pawn_slot_t *data; ///< The slots themselves.
- //int successful; ///< The number of successful queries.
- //int unsuccessful; ///< The number of unsuccessful queries;
- //int total; ///< The total number of queries.
};

#endif
=======================================
--- /trunk/inc/xboard.h Thu Dec 24 13:12:34 2009
+++ /trunk/inc/xboard.h Fri Jul 30 09:41:31 2010
@@ -27,7 +27,7 @@
#include "search_base.h"

#define BUFFER_SIZE 160
-#define TESTSUITE_TIMETOMOVE 10*100 // 10 seconds
+#define TESTSUITE_TIMETOMOVE 1*100 // 1 seconds

/// Chess Engine Communication Protocol.
class xboard
=======================================
--- /trunk/src/board_base.cpp Wed Jul 28 22:54:14 2010
+++ /trunk/src/board_base.cpp Fri Jul 30 09:41:31 2010
@@ -485,8 +485,12 @@
return ILLEGAL;

// Are the kings attacking one other?
- int n = FST(state.piece[WHITE][KING]);
- if (squares_king[n & 0x7][n >> 3] & state.piece[BLACK][KING])
+ //int n = FST(state.piece[WHITE][KING]);
+ //if (squares_king[n & 0x7][n >> 3] & state.piece[BLACK][KING])
+ //return ILLEGAL;
+
+ //if the king on move is in check, then this position is illegal
+ if (check(state.piece[OFF_MOVE][KING], ON_MOVE))
return ILLEGAL;

if (mate_test)
@@ -495,8 +499,8 @@
case STALEMATE: return STALEMATE;
case CHECKMATE: return CHECKMATE;
}
- //if (insufficient())
- //return INSUFFICIENT;
+ if (insufficient())
+ return INSUFFICIENT;
if (three())
return THREE;
if (fifty())
=======================================
--- /trunk/src/search_mtdf.cpp Wed Jul 28 22:54:14 2010
+++ /trunk/src/search_mtdf.cpp Fri Jul 30 09:41:31 2010
@@ -480,8 +480,10 @@
// When doing MTD(f) zero-window searches, our move search
should
// never return an exact score. I've only accounted for this
in the
// interest of robustness.
- if ((max_depth-depth) > 3)
- table_ptr->store(hash, max_depth-depth-1, EXACT, m);
+ //if ((max_depth-depth) > 3)
+ //table_ptr->store(hash, max_depth-depth-1, EXACT, m);
+ if (depth < max_depth) //no special branches
+ table_ptr->store(hash, max_depth-depth,EXACT,m);
//else if (m.value <= saved_alpha)
//table_ptr->store(hash, max_depth-depth, UPPER, m);
//}
=======================================
--- /trunk/src/xboard.cpp Wed Jul 28 22:54:14 2010
+++ /trunk/src/xboard.cpp Fri Jul 30 09:41:31 2010
@@ -680,7 +680,9 @@
// Parse the test suite
if(!inputfile) {
cerr << "Cannot open '" << testfile << "'" << endl;
- } else if (TESTFILE.find(".EPD") != string::npos) {
+ } else if ((TESTFILE.find(".EPD") != string::npos) ||
+ (TESTFILE.find(".epd") != string::npos))
+ {
// Extended Positinal Diagram, format is:
// FEN bm (best move) am (avoid move)
// pm (predicted move) pv (predicted variation)
@@ -714,7 +716,8 @@
ts_erroneous++;
}
} while (inputfile.good());
- } else if (TESTFILE.find(".PGN") != string::npos) {
+ } else if ((TESTFILE.find(".PGN") != string::npos) ||
+ (TESTFILE.find(".pgn") != string::npos)) {
// Portable Game Notation
int status = 0;
string::size_type idx, pos;
@@ -784,7 +787,8 @@
cerr << "Unknown file type '" << testfile << "'" << endl;
}

- assert(ts_fen.size() == ts_sol.size());
+ if(ts_fen.size() != ts_sol.size())
+ cout << "GM: Can't find best moves. . we'll just try to get
through it." << endl;

if (ts_fen.size()) {
ts_mode = true;
@@ -800,7 +804,8 @@
void xboard::test_suite_next(Move m) {

// Check whether we did the right thing
- if (ts_sol.size()) {
+ if (ts_sol.size())
+ {
string solution = ts_sol.front();
ts_sol.erase(ts_sol.begin());
string desc = ts_desc.front();
@@ -812,18 +817,19 @@
board_ptr->coord_to_san(m, str);

// Compare result
- if (str == "null") {
- cerr << desc << " : error!" << endl;
+ if (str == "null")
+ {
+ cout << desc << " : error!" << endl;
ts_erroneous++;
} else if (solution.find(str) != string::npos) {
// Gray's suggestion (str) is a substring of the best move (bm) string.
// Because there can be multiple best moves, we assume that Gray is
right
// if 'str' is a substring of 'solution'.
- cerr << desc << " : '" << solution << "' == '" << str << "'" << endl;
+ cout << desc << " : '" << solution << "' == '" << str << "'" << endl;
ts_success++;
} else {
// Gray's suggestion is not found in the best move (bm) string.
- cerr << desc << " : '" << solution << "' != '" << str << "'" << endl;
+ cout << desc << " : '" << solution << "' != '" << str << "'" << endl;
ts_failure++;
}
}
@@ -834,7 +840,9 @@
ts_fen.erase(ts_fen.begin());
do_setboard(fen);
clock_ptr->set_mode(board_ptr->get_whose(), 1, TESTSUITE_TIMETOMOVE, 0);
+
do_go();
+ cout << "Remaining Tests: " << ts_fen.size() << " - ";
} else {
// Test suite finished
ts_mode = false;

Reply all
Reply to author
Forward
0 new messages