From 9a45b7fc950d86130bd382b790bcb8e91afc2621 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frank=20L=C3=B6ffler?= Date: Fri, 29 May 2015 15:07:36 -0500 Subject: [PATCH 01/44] comment asserts that won't compile --- headers/parallel_support.hpp | 2 +- src/alphabeta.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/headers/parallel_support.hpp b/headers/parallel_support.hpp index 9e2ad9c..895fc06 100644 --- a/headers/parallel_support.hpp +++ b/headers/parallel_support.hpp @@ -146,7 +146,7 @@ struct thread_task : public task { } virtual void start() { joined = false; - assert(info.valid()); + //assert(info.valid()); if(pfunc == search_f) { th = std::async(std::launch::async,search_pt,info); } else if(pfunc == search_ab_f) { diff --git a/src/alphabeta.cpp b/src/alphabeta.cpp index e32bd0c..9ee8a1a 100644 --- a/src/alphabeta.cpp +++ b/src/alphabeta.cpp @@ -165,7 +165,7 @@ score_t search_ab(boost::shared_ptr proc_info) for(size_t n_=0;n_ child_task = tasks[n]; - assert(child_task.valid()); + //assert(child_task.valid()); child_task->join(); boost::shared_ptr child_info = child_task->info; From e6f75e676c342386471c4afd366bb427e4dd7392 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frank=20L=C3=B6ffler?= Date: Mon, 1 Jun 2015 10:49:04 -0500 Subject: [PATCH 02/44] enable readline --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 744f00d..174a1e4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,7 +40,7 @@ endif() set(EXTRA_LIBS pthread) -#find_package(Readline) +find_package(Readline) if(READLINE_FOUND) message("Readline was found.") From a940385b5ad0ccb58da5f6b317568eab4d0fa8e6 Mon Sep 17 00:00:00 2001 From: Frank Loeffler Date: Mon, 1 Jun 2015 11:32:44 -0500 Subject: [PATCH 03/44] make perl harnesses executable --- harness_helgrind.pl | 0 harness_memcheck.pl | 0 harness_plain.pl | 0 3 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 harness_helgrind.pl mode change 100644 => 100755 harness_memcheck.pl mode change 100644 => 100755 harness_plain.pl diff --git a/harness_helgrind.pl b/harness_helgrind.pl old mode 100644 new mode 100755 diff --git a/harness_memcheck.pl b/harness_memcheck.pl old mode 100644 new mode 100755 diff --git a/harness_plain.pl b/harness_plain.pl old mode 100644 new mode 100755 From d25319ba21d055d8a35389c402b310ad1ab0aa1a Mon Sep 17 00:00:00 2001 From: Frank Loeffler Date: Mon, 1 Jun 2015 12:15:34 -0500 Subject: [PATCH 04/44] make perl scripts executable --- harness_helgrind.pl | 0 harness_memcheck.pl | 0 harness_plain.pl | 0 3 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 harness_helgrind.pl mode change 100755 => 100644 harness_memcheck.pl mode change 100755 => 100644 harness_plain.pl diff --git a/harness_helgrind.pl b/harness_helgrind.pl old mode 100755 new mode 100644 diff --git a/harness_memcheck.pl b/harness_memcheck.pl old mode 100755 new mode 100644 diff --git a/harness_plain.pl b/harness_plain.pl old mode 100755 new mode 100644 From 9aa8bd919638fd43734966f9a5835e8300786d10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frank=20L=C3=B6ffler?= Date: Mon, 1 Jun 2015 12:53:02 -0500 Subject: [PATCH 05/44] add sqlite3 support to cmake --- cmake/FindSQLite3.cmake | 87 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 cmake/FindSQLite3.cmake diff --git a/cmake/FindSQLite3.cmake b/cmake/FindSQLite3.cmake new file mode 100644 index 0000000..aa650e3 --- /dev/null +++ b/cmake/FindSQLite3.cmake @@ -0,0 +1,87 @@ +# - Try to find Sqlite3 +# Once done this will define +# +# SQLITE3_FOUND - system has Sqlite3 +# SQLITE3_INCLUDE_DIRS - the Sqlite3 include directory +# SQLITE3_LIBRARIES - Link these to use Sqlite3 +# SQLITE3_DEFINITIONS - Compiler switches required for using Sqlite3 +# +# Copyright (c) 2008 Andreas Schneider +# +# Redistribution and use is allowed according to the terms of the New +# BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. +# + + +if (SQLITE3_LIBRARIES AND SQLITE3_INCLUDE_DIRS) + # in cache already + set(SQLITE3_FOUND TRUE) +else (SQLITE3_LIBRARIES AND SQLITE3_INCLUDE_DIRS) + # use pkg-config to get the directories and then use these values + # in the FIND_PATH() and FIND_LIBRARY() calls + if (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4) + include(UsePkgConfig) + pkgconfig(sqlite3 _SQLITE3_INCLUDEDIR _SQLITE3_LIBDIR _SQLITE3_LDFLAGS _SQLITE3_CFLAGS) + else (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4) + find_package(PkgConfig) + if (PKG_CONFIG_FOUND) + pkg_check_modules(_SQLITE3 sqlite3) + endif (PKG_CONFIG_FOUND) + endif (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4) + find_path(SQLITE3_INCLUDE_DIR + NAMES + sqlite3.h + PATHS + ${_SQLITE3_INCLUDEDIR} + /usr/include + /usr/local/include + /opt/local/include + /sw/include + ) + + find_library(SQLITE3_LIBRARY + NAMES + sqlite3 + PATHS + ${_SQLITE3_LIBDIR} + /usr/lib + /usr/local/lib + /opt/local/lib + /sw/lib + ) + + if (SQLITE3_LIBRARY) + set(SQLITE3_FOUND TRUE) + endif (SQLITE3_LIBRARY) + + set(SQLITE3_INCLUDE_DIRS + ${SQLITE3_INCLUDE_DIR} + ) + + if (SQLITE3_FOUND) + set(SQLITE3_LIBRARIES + ${SQLITE3_LIBRARIES} + ${SQLITE3_LIBRARY} + ) + endif (SQLITE3_FOUND) + + if (SQLITE3_INCLUDE_DIRS AND SQLITE3_LIBRARIES) + set(SQLITE3_FOUND TRUE) + endif (SQLITE3_INCLUDE_DIRS AND SQLITE3_LIBRARIES) + + if (SQLITE3_FOUND) + if (NOT Sqlite3_FIND_QUIETLY) + message(STATUS "Found Sqlite3: ${SQLITE3_LIBRARIES}") + endif (NOT Sqlite3_FIND_QUIETLY) + else (SQLITE3_FOUND) + if (Sqlite3_FIND_REQUIRED) + message(FATAL_ERROR "Could not find Sqlite3") + endif (Sqlite3_FIND_REQUIRED) + endif (SQLITE3_FOUND) + + # show the SQLITE3_INCLUDE_DIRS and SQLITE3_LIBRARIES variables only in the advanced view + mark_as_advanced(SQLITE3_INCLUDE_DIRS SQLITE3_LIBRARIES) + +endif (SQLITE3_LIBRARIES AND SQLITE3_INCLUDE_DIRS) + From c5edeed95a20593e28b50aa4529a97b1517540c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frank=20L=C3=B6ffler?= Date: Mon, 1 Jun 2015 12:55:38 -0500 Subject: [PATCH 06/44] add sqlite3 support to cmake --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 174a1e4..2c2adda 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,6 +41,7 @@ endif() set(EXTRA_LIBS pthread) find_package(Readline) +find_package(SQLite3) if(READLINE_FOUND) message("Readline was found.") From 05aa081bd770a9c9dedcc1599f0e1f9f69f5039d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frank=20L=C3=B6ffler?= Date: Mon, 1 Jun 2015 13:10:29 -0500 Subject: [PATCH 07/44] add pgn command (unused so far) --- src/main.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 826a7a0..ed97e62 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -54,6 +54,8 @@ void chx_terminate() { int auto_move = 0; int computer_side; +bool pgn_enabled = false; + #ifdef HPX_SUPPORT std::ofstream **streams; bool file_output_enabled = false; @@ -189,6 +191,11 @@ int chx_main() continue; } #endif + if (input[0] == "pgn") { + pgn_enabled = !pgn_enabled; + cout << "PGN output " << (pgn_enabled?"enabled.":"disabled.") << std::endl; + continue; + } if (input[0] == "new") { computer_side = EMPTY; init_board(board); @@ -354,14 +361,15 @@ int chx_main() << "simple" << ((chosen_evaluator == SIMPLE) ? "=current" : "") << ")" << std::endl; std::cout << " search \n\tswitches the current search method in use" << std::endl; - std::cout << " go\n\tcomputer makes a chess_move" << std::endl; - std::cout << " auto\n\tcomputer will continue to make moves until game is over" << std::endl; - std::cout << " new\n\tstarts a new game" << std::endl; + std::cout << " go\tcomputer makes a chess_move" << std::endl; + std::cout << " auto\tcomputer will continue to make moves until game is over" << std::endl; + std::cout << " new\tstarts a new game" << std::endl; std::cout << " wd \n\tsets white search depth (currently " << depth[LIGHT] << ")" << std::endl; std::cout << " bd \n\tsets black search depth (currently " << depth[DARK] << ")" << std::endl; - std::cout << " d\n\tdisplay the board" << std::endl; + std::cout << " d\tdisplay the board" << std::endl; std::cout << " o \n\ttoggles engine output on or off (default on)" << std::endl; - std::cout << " exit\n\texit the program" << std::endl; + std::cout << " pgn\ttoggles output of moves to pgn file." << std::endl; + std::cout << " exit\texit the program" << std::endl; std::cout << " Enter moves in coordinate notation, e.g., e2e4, e7e8Q" << std::endl; std::cout << std::endl; continue; From 3a62f3d2bacdd1fa07c25c3b09b806467eeff875 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frank=20L=C3=B6ffler?= Date: Mon, 1 Jun 2015 13:10:47 -0500 Subject: [PATCH 08/44] ignore some generated files --- .gitignore | 5 +++++ src/.gitignore | 4 ++++ 2 files changed, 9 insertions(+) create mode 100644 .gitignore create mode 100644 src/.gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e853770 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.bench +CMakeCache.txt +CMakeFiles +Makefile +cmake_install.cmake diff --git a/src/.gitignore b/src/.gitignore new file mode 100644 index 0000000..60e2163 --- /dev/null +++ b/src/.gitignore @@ -0,0 +1,4 @@ +CMakeFiles +Makefile +chx +cmake_install.make From 21bf0770b272e648ab35b0a3cc401a57193c0d04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frank=20L=C3=B6ffler?= Date: Mon, 1 Jun 2015 13:35:16 -0500 Subject: [PATCH 09/44] add (empty) output routine for pgn --- headers/pgn.hpp | 6 ++++++ src/CMakeLists.txt | 3 ++- src/main.cpp | 4 ++++ src/pgn.cpp | 4 ++++ 4 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 headers/pgn.hpp create mode 100644 src/pgn.cpp diff --git a/headers/pgn.hpp b/headers/pgn.hpp new file mode 100644 index 0000000..f67b916 --- /dev/null +++ b/headers/pgn.hpp @@ -0,0 +1,6 @@ +#ifndef CHESS_MOVE_H + +#include "chess_move.hpp" +void pgn_output(const chess_move &move); + +#endif diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a7b3401..55894ba 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -12,7 +12,8 @@ set(sources minimax.cpp log_board.cpp timer.cpp - alphabeta.cpp) + alphabeta.cpp + pgn.cpp) if(HPX_FOUND) set(sources ${sources} diff --git a/src/main.cpp b/src/main.cpp index ed97e62..b1ba393 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -18,6 +18,7 @@ #include "parallel_support.hpp" #include #include "main.hpp" +#include "pgn.hpp" #include #include #include @@ -132,6 +133,8 @@ int chx_main() if (output) print_board(board, std::cout); + if (pgn_enabled) + pgn_output(move_to_make); if (auto_move) auto_move = print_result(workq, board); else @@ -387,6 +390,7 @@ int chx_main() board.ply = 0; workq.clear(); gen(workq, board); + pgn_output(mov); print_result(workq, board); } } diff --git a/src/pgn.cpp b/src/pgn.cpp new file mode 100644 index 0000000..7bb2e17 --- /dev/null +++ b/src/pgn.cpp @@ -0,0 +1,4 @@ +#include "pgn.hpp" +void pgn_output(const chess_move &move) +{ +} From 90e230d2a2fe29b031f808658e9121d0310dd229 Mon Sep 17 00:00:00 2001 From: "Steven R. Brandt" Date: Mon, 1 Jun 2015 13:49:17 -0500 Subject: [PATCH 10/44] fix linking. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2c2adda..981917d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,7 +38,7 @@ else() message("Could not find HPX. Configuring without HPX support.") endif() -set(EXTRA_LIBS pthread) +set(EXTRA_LIBS pthread sqlite3) find_package(Readline) find_package(SQLite3) From 11a675ecee9174c2a407630e4223070bd8080f88 Mon Sep 17 00:00:00 2001 From: "Steven R. Brandt" Date: Mon, 1 Jun 2015 13:59:26 -0500 Subject: [PATCH 11/44] fixing help message --- src/main.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index b1ba393..40db91c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -363,7 +363,11 @@ int chx_main() << "original" << ((chosen_evaluator == ORIGINAL) ? "=current" : "") << "," << "simple" << ((chosen_evaluator == SIMPLE) ? "=current" : "") << ")" << std::endl; - std::cout << " search \n\tswitches the current search method in use" << std::endl; + std::cout << " search \n\tswitches the current search method in use (" + << "minimax" << (search_method == MINIMAX ? "=current" : "") + << ",alphabeta"<< (search_method == ALPHABETA ? "=current" : "") + << ",mtdf" << (search_method == MTDF ? "=current" : "") + << ")" << std::endl; std::cout << " go\tcomputer makes a chess_move" << std::endl; std::cout << " auto\tcomputer will continue to make moves until game is over" << std::endl; std::cout << " new\tstarts a new game" << std::endl; From 4c67c7a7b10c618ba481923992b65876a5259303 Mon Sep 17 00:00:00 2001 From: "Steven R. Brandt" Date: Mon, 1 Jun 2015 14:02:10 -0500 Subject: [PATCH 12/44] added white space for test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 40db91c..fa21507 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -341,7 +341,7 @@ int chx_main() search_m = input.at(1); } catch (out_of_range&) { - std::cout << "Name of search method (minimax,alphabeta,mtdf): "; + std::cout << "Name of search method (minimax,alphabeta,mtdf): "; std::cin >> search_m; } if (search_m == "minimax") { From b9cfa55c1efed7143dd857fae1e5c4424b6b3c39 Mon Sep 17 00:00:00 2001 From: "Steven R. Brandt" Date: Mon, 1 Jun 2015 14:04:31 -0500 Subject: [PATCH 13/44] testing webhooks --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index fa21507..126581f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -363,7 +363,7 @@ int chx_main() << "original" << ((chosen_evaluator == ORIGINAL) ? "=current" : "") << "," << "simple" << ((chosen_evaluator == SIMPLE) ? "=current" : "") << ")" << std::endl; - std::cout << " search \n\tswitches the current search method in use (" + std::cout << " search \n\tswitches the current search method in use (" << "minimax" << (search_method == MINIMAX ? "=current" : "") << ",alphabeta"<< (search_method == ALPHABETA ? "=current" : "") << ",mtdf" << (search_method == MTDF ? "=current" : "") From f20d491c5aeebf27ede009fe619b2f0e3de02ce2 Mon Sep 17 00:00:00 2001 From: "Steven R. Brandt" Date: Mon, 1 Jun 2015 14:07:22 -0500 Subject: [PATCH 14/44] test webhook --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 126581f..fa21507 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -363,7 +363,7 @@ int chx_main() << "original" << ((chosen_evaluator == ORIGINAL) ? "=current" : "") << "," << "simple" << ((chosen_evaluator == SIMPLE) ? "=current" : "") << ")" << std::endl; - std::cout << " search \n\tswitches the current search method in use (" + std::cout << " search \n\tswitches the current search method in use (" << "minimax" << (search_method == MINIMAX ? "=current" : "") << ",alphabeta"<< (search_method == ALPHABETA ? "=current" : "") << ",mtdf" << (search_method == MTDF ? "=current" : "") From 68bb6904be072eb19271a0afb1b17a449a8bbe8f Mon Sep 17 00:00:00 2001 From: "Steven R. Brandt" Date: Mon, 1 Jun 2015 14:11:06 -0500 Subject: [PATCH 15/44] test webhook --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index fa21507..126581f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -363,7 +363,7 @@ int chx_main() << "original" << ((chosen_evaluator == ORIGINAL) ? "=current" : "") << "," << "simple" << ((chosen_evaluator == SIMPLE) ? "=current" : "") << ")" << std::endl; - std::cout << " search \n\tswitches the current search method in use (" + std::cout << " search \n\tswitches the current search method in use (" << "minimax" << (search_method == MINIMAX ? "=current" : "") << ",alphabeta"<< (search_method == ALPHABETA ? "=current" : "") << ",mtdf" << (search_method == MTDF ? "=current" : "") From 61fd8e22429b38ada78a4785b3510ddfe785ebed Mon Sep 17 00:00:00 2001 From: "Steven R. Brandt" Date: Mon, 1 Jun 2015 14:13:18 -0500 Subject: [PATCH 16/44] test webhook --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 126581f..fa21507 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -363,7 +363,7 @@ int chx_main() << "original" << ((chosen_evaluator == ORIGINAL) ? "=current" : "") << "," << "simple" << ((chosen_evaluator == SIMPLE) ? "=current" : "") << ")" << std::endl; - std::cout << " search \n\tswitches the current search method in use (" + std::cout << " search \n\tswitches the current search method in use (" << "minimax" << (search_method == MINIMAX ? "=current" : "") << ",alphabeta"<< (search_method == ALPHABETA ? "=current" : "") << ",mtdf" << (search_method == MTDF ? "=current" : "") From 08b378504b5bb0376ee718612ddede7f0bd2041e Mon Sep 17 00:00:00 2001 From: "Steven R. Brandt" Date: Mon, 1 Jun 2015 14:14:49 -0500 Subject: [PATCH 17/44] test webhook --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index fa21507..126581f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -363,7 +363,7 @@ int chx_main() << "original" << ((chosen_evaluator == ORIGINAL) ? "=current" : "") << "," << "simple" << ((chosen_evaluator == SIMPLE) ? "=current" : "") << ")" << std::endl; - std::cout << " search \n\tswitches the current search method in use (" + std::cout << " search \n\tswitches the current search method in use (" << "minimax" << (search_method == MINIMAX ? "=current" : "") << ",alphabeta"<< (search_method == ALPHABETA ? "=current" : "") << ",mtdf" << (search_method == MTDF ? "=current" : "") From 6fc2ee774ad3a4288df97debe84569eece0841e8 Mon Sep 17 00:00:00 2001 From: "Steven R. Brandt" Date: Mon, 1 Jun 2015 14:15:56 -0500 Subject: [PATCH 18/44] test webhook --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 126581f..fa21507 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -363,7 +363,7 @@ int chx_main() << "original" << ((chosen_evaluator == ORIGINAL) ? "=current" : "") << "," << "simple" << ((chosen_evaluator == SIMPLE) ? "=current" : "") << ")" << std::endl; - std::cout << " search \n\tswitches the current search method in use (" + std::cout << " search \n\tswitches the current search method in use (" << "minimax" << (search_method == MINIMAX ? "=current" : "") << ",alphabeta"<< (search_method == ALPHABETA ? "=current" : "") << ",mtdf" << (search_method == MTDF ? "=current" : "") From d514af3558811a68deaf79f0fafd8d4e4a632e47 Mon Sep 17 00:00:00 2001 From: "Steven R. Brandt" Date: Mon, 1 Jun 2015 14:16:47 -0500 Subject: [PATCH 19/44] test webhook --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index fa21507..126581f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -363,7 +363,7 @@ int chx_main() << "original" << ((chosen_evaluator == ORIGINAL) ? "=current" : "") << "," << "simple" << ((chosen_evaluator == SIMPLE) ? "=current" : "") << ")" << std::endl; - std::cout << " search \n\tswitches the current search method in use (" + std::cout << " search \n\tswitches the current search method in use (" << "minimax" << (search_method == MINIMAX ? "=current" : "") << ",alphabeta"<< (search_method == ALPHABETA ? "=current" : "") << ",mtdf" << (search_method == MTDF ? "=current" : "") From 34da98ea8622e1983b471446a781bd3f4fe1abac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frank=20L=C3=B6ffler?= Date: Mon, 1 Jun 2015 14:46:21 -0500 Subject: [PATCH 20/44] make perl scripts executable --- harness_helgrind.pl | 0 harness_memcheck.pl | 0 harness_plain.pl | 0 src/chess_move.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 38 insertions(+) mode change 100644 => 100755 harness_helgrind.pl mode change 100644 => 100755 harness_memcheck.pl mode change 100644 => 100755 harness_plain.pl create mode 100644 src/chess_move.cpp diff --git a/harness_helgrind.pl b/harness_helgrind.pl old mode 100644 new mode 100755 diff --git a/harness_memcheck.pl b/harness_memcheck.pl old mode 100644 new mode 100755 diff --git a/harness_plain.pl b/harness_plain.pl old mode 100644 new mode 100755 diff --git a/src/chess_move.cpp b/src/chess_move.cpp new file mode 100644 index 0000000..49dc010 --- /dev/null +++ b/src/chess_move.cpp @@ -0,0 +1,38 @@ +#include +#include "defs.hpp" +#include "chess_move.hpp" + +using namespace std; + +string chess_move::str() +{ + ostringstream ostr; + + if (getBits() & 32) + { + ostr << COL(getFrom()) << "a" << 8 - ROW(getFrom()) << + COL(getTo()) << "a" << 8 - ROW(getTo()); + switch (getPromote()) + { + case KNIGHT: + ostr << "n"; + break; + case BISHOP: + ostr << "b"; + break; + case ROOK: + ostr << "r"; + break; + default: + ostr << "q"; + break; + } + } else + ostr << COL(getFrom()) << "a" << 8 - ROW(getFrom()) << + COL(getTo()) << "a" << 8 - ROW(getTo()); + return ostr.str(); +} +const char* chess_move::c_str() +{ + return this->str().c_str(); +} From 5a1c57ffd3b7e872be008f486b95f720477ccaf8 Mon Sep 17 00:00:00 2001 From: "Steven R. Brandt" Date: Mon, 1 Jun 2015 14:46:46 -0500 Subject: [PATCH 21/44] test webhook --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 126581f..fa21507 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -363,7 +363,7 @@ int chx_main() << "original" << ((chosen_evaluator == ORIGINAL) ? "=current" : "") << "," << "simple" << ((chosen_evaluator == SIMPLE) ? "=current" : "") << ")" << std::endl; - std::cout << " search \n\tswitches the current search method in use (" + std::cout << " search \n\tswitches the current search method in use (" << "minimax" << (search_method == MINIMAX ? "=current" : "") << ",alphabeta"<< (search_method == ALPHABETA ? "=current" : "") << ",mtdf" << (search_method == MTDF ? "=current" : "") From bbf7587318dca9f0d640e4b3d6605c5ae12fb068 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frank=20L=C3=B6ffler?= Date: Mon, 1 Jun 2015 14:46:49 -0500 Subject: [PATCH 22/44] move to member function for printing of moves --- harness_helgrind.pl | 0 harness_memcheck.pl | 0 harness_plain.pl | 0 headers/chess_move.hpp | 3 +++ src/CMakeLists.txt | 1 + src/chess_move.cpp | 8 +++---- src/main.cpp | 48 +++++------------------------------------- src/pgn.cpp | 6 ++++++ src/xboard.cpp | 6 +++--- 9 files changed, 22 insertions(+), 50 deletions(-) mode change 100755 => 100644 harness_helgrind.pl mode change 100755 => 100644 harness_memcheck.pl mode change 100755 => 100644 harness_plain.pl diff --git a/harness_helgrind.pl b/harness_helgrind.pl old mode 100755 new mode 100644 diff --git a/harness_memcheck.pl b/harness_memcheck.pl old mode 100755 new mode 100644 diff --git a/harness_plain.pl b/harness_plain.pl old mode 100755 new mode 100644 diff --git a/headers/chess_move.hpp b/headers/chess_move.hpp index 16d18f5..e9769a4 100644 --- a/headers/chess_move.hpp +++ b/headers/chess_move.hpp @@ -9,6 +9,7 @@ #define CHESS_MOVE_HPP_C1BEDE43_B47B_4694_ACF4_F41143D72B97 #include +#include /* This is the basic description of a chess_move. promote is what piece to promote the pawn to, if the chess_move is a pawn promotion. bits is a bitfield that describes the chess_move, @@ -95,6 +96,8 @@ class chess_move { ar & this->promote; ar & this->bits; } + std::string str(); + const char *c_str(); }; #endif diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 55894ba..ee937e8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -13,6 +13,7 @@ set(sources log_board.cpp timer.cpp alphabeta.cpp + chess_move.cpp pgn.cpp) if(HPX_FOUND) diff --git a/src/chess_move.cpp b/src/chess_move.cpp index 49dc010..160f25f 100644 --- a/src/chess_move.cpp +++ b/src/chess_move.cpp @@ -10,8 +10,8 @@ string chess_move::str() if (getBits() & 32) { - ostr << COL(getFrom()) << "a" << 8 - ROW(getFrom()) << - COL(getTo()) << "a" << 8 - ROW(getTo()); + ostr << (char)('a' + COL(getFrom())) << 8 - ROW(getFrom()) << + (char)('a' + COL(getTo())) << 8 - ROW(getTo()); switch (getPromote()) { case KNIGHT: @@ -28,8 +28,8 @@ string chess_move::str() break; } } else - ostr << COL(getFrom()) << "a" << 8 - ROW(getFrom()) << - COL(getTo()) << "a" << 8 - ROW(getTo()); + ostr << (char)('a' + COL(getFrom())) << 8 - ROW(getFrom()) << + (char)('a' + COL(getTo())) << 8 - ROW(getTo()); return ostr.str(); } const char* chess_move::c_str() diff --git a/src/main.cpp b/src/main.cpp index b1ba393..09a1bda 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -122,7 +122,7 @@ int chx_main() continue; } if (output) - std::cout << "Computer's chess_move: " << move_str(move_to_make) << " time=" << std::setprecision(3) << 1e-3*(end-start) << " sec" + std::cout << "Computer's chess_move: " << move_to_make.str() << " time=" << std::setprecision(3) << 1e-3*(end-start) << " sec" << std::endl; makemove(board, move_to_make); // Make the chess_move for our master board board.ply = 0; // Reset the board ply to 0 @@ -387,10 +387,11 @@ int chx_main() std::cout << "Illegal chess_move or command." << std::endl; else { makemove(board, mov); + if (pgn_enabled) + pgn_output(mov); board.ply = 0; workq.clear(); gen(workq, board); - pgn_output(mov); print_result(workq, board); } } @@ -610,10 +611,10 @@ void start_benchmark(std::string filename, int ply_level, int num_runs,bool para } else { - std::cout << " Computer's chess_move: " << move_str(move_to_make) + std::cout << " Computer's chess_move: " << move_to_make.str() << std::endl; - logfile << " Computer's chess_move: " << move_str(move_to_make) + logfile << " Computer's chess_move: " << move_to_make.str() << std::endl; } // Allow time for aborted threads to get cleaned up @@ -688,45 +689,6 @@ int parse_move(std::vector& workq, const char *s) } -// move_str returns a string with chess_move m in coordinate notation - -char *move_str(chess_move& m) -{ - static char str[6]; - - char c; - - if (m.getBits() & 32) { - switch (m.getPromote()) { - case KNIGHT: - c = 'n'; - break; - case BISHOP: - c = 'b'; - break; - case ROOK: - c = 'r'; - break; - default: - c = 'q'; - break; - } - sprintf(str, "%c%d%c%d%c", - COL(m.getFrom()) + 'a', - 8 - ROW(m.getFrom()), - COL(m.getTo()) + 'a', - 8 - ROW(m.getTo()), - c); - } - else - sprintf(str, "%c%d%c%d", - COL(m.getFrom()) + 'a', - 8 - ROW(m.getFrom()), - COL(m.getTo()) + 'a', - 8 - ROW(m.getTo())); - return str; -} - // print_board() prints the board void print_board(const node_t& board, std::ostream& out) diff --git a/src/pgn.cpp b/src/pgn.cpp index 7bb2e17..e0ac51d 100644 --- a/src/pgn.cpp +++ b/src/pgn.cpp @@ -1,4 +1,10 @@ #include "pgn.hpp" +#include +//#include + +using namespace std; + void pgn_output(const chess_move &move) { + cout << "pgn\n"; } diff --git a/src/xboard.cpp b/src/xboard.cpp index 718c8e1..08becb4 100644 --- a/src/xboard.cpp +++ b/src/xboard.cpp @@ -34,7 +34,7 @@ void xboard() computer_side = EMPTY; continue; } - std::cout << "chess_move " << move_str(move_to_make.b) << std::endl; + std::cout << "chess_move " << move_to_make.b.str() << std::endl; std::cout.flush(); makemove(board, move_to_make.b); board.ply = 0; @@ -91,7 +91,7 @@ void xboard() think(board, false); if (move_to_make.u == 0) continue; - std::cout << "Hint: " << move_str(move_to_make.b) << std::endl; + std::cout << "Hint: " << move_to_make.b.str() << std::endl; continue; } @@ -109,4 +109,4 @@ void xboard() print_result(workq, board); } } -} \ No newline at end of file +} From 6825d4eb5b8ba95c9dbae7dd63595908fb981f17 Mon Sep 17 00:00:00 2001 From: "Steven R. Brandt" Date: Mon, 1 Jun 2015 14:48:26 -0500 Subject: [PATCH 23/44] test webhook --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index fa21507..126581f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -363,7 +363,7 @@ int chx_main() << "original" << ((chosen_evaluator == ORIGINAL) ? "=current" : "") << "," << "simple" << ((chosen_evaluator == SIMPLE) ? "=current" : "") << ")" << std::endl; - std::cout << " search \n\tswitches the current search method in use (" + std::cout << " search \n\tswitches the current search method in use (" << "minimax" << (search_method == MINIMAX ? "=current" : "") << ",alphabeta"<< (search_method == ALPHABETA ? "=current" : "") << ",mtdf" << (search_method == MTDF ? "=current" : "") From a5b2204ac36643374bf8d3797e3d3ce3990ae370 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frank=20L=C3=B6ffler?= Date: Mon, 1 Jun 2015 14:50:35 -0500 Subject: [PATCH 24/44] add shebangs --- harness_helgrind.pl | 1 + harness_memcheck.pl | 1 + harness_plain.pl | 1 + 3 files changed, 3 insertions(+) mode change 100644 => 100755 harness_helgrind.pl mode change 100644 => 100755 harness_memcheck.pl mode change 100644 => 100755 harness_plain.pl diff --git a/harness_helgrind.pl b/harness_helgrind.pl old mode 100644 new mode 100755 index 7939af0..ad8d8d5 --- a/harness_helgrind.pl +++ b/harness_helgrind.pl @@ -1,3 +1,4 @@ +#!/usr/bin/perl ################################################################################ ## Copyright (c) 2011 Steve Brandt and Philip LeBlanc ## diff --git a/harness_memcheck.pl b/harness_memcheck.pl old mode 100644 new mode 100755 index 04007ac..cbd19f5 --- a/harness_memcheck.pl +++ b/harness_memcheck.pl @@ -1,3 +1,4 @@ +#!/usr/bin/perl ################################################################################ ## Copyright (c) 2011 Steve Brandt and Philip LeBlanc ## diff --git a/harness_plain.pl b/harness_plain.pl old mode 100644 new mode 100755 index 0bef76f..53da91c --- a/harness_plain.pl +++ b/harness_plain.pl @@ -1,3 +1,4 @@ +#!/usr/bin/perl ################################################################################ ## Copyright (c) 2011 Steve Brandt and Philip LeBlanc ## From 7e0e1b4b5dee8e97e3296cddb9859c438272dc9c Mon Sep 17 00:00:00 2001 From: Patrick Mancuso Date: Mon, 1 Jun 2015 14:54:34 -0500 Subject: [PATCH 25/44] new database file --- headers/main.hpp | 4 +++- headers/parallel.hpp | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/headers/main.hpp b/headers/main.hpp index cd0d25e..f6009dc 100644 --- a/headers/main.hpp +++ b/headers/main.hpp @@ -1,4 +1,4 @@ -//////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2011 Steve Brandt and Phillip LeBlanc // // Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -15,6 +15,7 @@ #include "data.hpp" #include "search.hpp" #include "chess_move.hpp" +#include "database.hpp" int main(int argc, char *argv[]); int parse_move(std::vector& workq, const char *s); @@ -26,6 +27,7 @@ int get_ms(); std::string get_log_name(); int chx_main(); #ifdef HPX_SUPPORT +extern database dbase; extern std::ofstream **streams; extern bool file_output_enabled; #endif diff --git a/headers/parallel.hpp b/headers/parallel.hpp index b4a9ff3..fc64cc6 100644 --- a/headers/parallel.hpp +++ b/headers/parallel.hpp @@ -40,3 +40,4 @@ struct ScopedLock { #endif #endif +//extern Mutex mutex; From bf59e02326e43c4441f0a526e3095d6db294c71a Mon Sep 17 00:00:00 2001 From: Patrick Mancuso Date: Mon, 1 Jun 2015 15:01:38 -0500 Subject: [PATCH 26/44] new database file --- headers/database.hpp | 128 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 headers/database.hpp diff --git a/headers/database.hpp b/headers/database.hpp new file mode 100644 index 0000000..8c8b6ca --- /dev/null +++ b/headers/database.hpp @@ -0,0 +1,128 @@ +#ifndef DATABASE_H +#define DATABASE_H +#include +#include +#include "hash.hpp" +#include "node.hpp" +#include "data.hpp" +#include "defs.hpp" +#include "chess_move.hpp" +#include "sqlite3.h" +//include "main.cpp" + +using namespace std; + + +class database { + public: + sqlite3 *db; + char *zErrMsg=0; + int rc; + + + database(){ + char *sql; + rc = sqlite3_open("test.db", &db); + if( rc ){ + fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db)); + exit(0); + }else{ + fprintf(stderr, "Opened database successfully\n"); + } + /* Create SQL statement */ + sql = "CREATE TABLE MoveSet(" \ + "PLY INTEGER NOT NULL," \ + "BOARD TEXT NOT NULL,"\ + "HI INTEGER NOT NULL,"\ + "LO INTEGER NOT NULL,"\ + "HASH INTEGER NOT NULL,"\ + "PRIMARY KEY (PLY, BOARD));"; + //Execute SQL statement + rc = sqlite3_exec(db, sql, 0, 0, &zErrMsg); + if( rc != SQLITE_OK ){ + fprintf(stderr, "%s\n", zErrMsg); + sqlite3_free(zErrMsg); + }else{ + fprintf(stdout, "Table created successfully\n"); + } + }; + +//destructor + ~database(){ + get_data(); + sqlite3_close(db); + cout<<"database closed. \n"; + }; + + void add_data(const node_t& board, int ply, int hi, int lo){ + auto hash= board.hash; + const char *sql; //maybe find a way to make work without const + //create SQL statement from string into char * array + std::ostringstream o; + + o<< "REPLACE INTO \"MoveSet\"VALUES ("< Date: Mon, 1 Jun 2015 15:15:28 -0500 Subject: [PATCH 27/44] Minor compilation problems. --- headers/database.hpp | 4 ++-- headers/search.hpp | 2 +- src/alphabeta.cpp | 2 +- src/minimax.cpp | 2 +- src/search.cpp | 13 ++++++++++--- 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/headers/database.hpp b/headers/database.hpp index 8c8b6ca..ba22d4d 100644 --- a/headers/database.hpp +++ b/headers/database.hpp @@ -21,7 +21,7 @@ class database { database(){ - char *sql; + const char *sql; rc = sqlite3_open("test.db", &db); if( rc ){ fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db)); @@ -100,7 +100,7 @@ class database { int get_data(){ const char *data= "Callback function called"; - char *sql= "SELECT * from MoveSet"; + const char *sql= "SELECT * from MoveSet"; rc= sqlite3_exec(db, sql, callback, (void*)data, &zErrMsg); if (rc!= SQLITE_OK ){ fprintf(stderr, "SQL error: %s\n", zErrMsg); diff --git a/headers/search.hpp b/headers/search.hpp index 316fcff..9b5556c 100644 --- a/headers/search.hpp +++ b/headers/search.hpp @@ -38,7 +38,7 @@ int min(int a,int b); int max(int a,int b); void xboard(); -extern Mutex mutex; +extern Mutex cmutex; extern const int num_proc; struct safe_move { diff --git a/src/alphabeta.cpp b/src/alphabeta.cpp index 9ee8a1a..7571588 100644 --- a/src/alphabeta.cpp +++ b/src/alphabeta.cpp @@ -221,7 +221,7 @@ score_t search_ab(boost::shared_ptr proc_info) if (board.ply == 0) { assert(max_move != INVALID_MOVE); - ScopedLock s(mutex); + ScopedLock s(cmutex); move_to_make = max_move; } diff --git a/src/minimax.cpp b/src/minimax.cpp index e9224a2..2874a16 100644 --- a/src/minimax.cpp +++ b/src/minimax.cpp @@ -137,7 +137,7 @@ score_t search(boost::shared_ptr info) if (board.ply == 0) { assert(max_move != INVALID_MOVE); - ScopedLock s(mutex); + ScopedLock s(cmutex); move_to_make = max_move; } diff --git a/src/search.cpp b/src/search.cpp index 7b7d3e0..273bfa5 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -23,7 +23,7 @@ #include #include -Mutex mutex; +Mutex cmutex; const int num_proc = chx_threads_per_proc(); int min(int a,int b) { return a < b ? a : b; } @@ -339,12 +339,19 @@ void sort_pv(std::vector& workq, int index) #define TRANSPOSE_ON 1 +inline int iabs(int n) { + if(n < 0) + return -n; + else + return n; +} + zkey_t transposition_table[table_size]; bool get_transposition_value(const node_t& board,score_t& lower,score_t& upper) { bool gotten = false; #ifdef TRANSPOSE_ON - int n = abs(board.hash^board.depth) % table_size; + int n = iabs(board.hash^board.depth) % table_size; zkey_t *z = &transposition_table[n]; ScopedLock s(z->mut); if(z->depth >= 0 && board_equals(board,z->board)) { @@ -361,7 +368,7 @@ bool get_transposition_value(const node_t& board,score_t& lower,score_t& upper) void set_transposition_value(const node_t& board,score_t lower,score_t upper) { #ifdef TRANSPOSE_ON - int n = abs(board.hash^board.depth) % table_size; + int n = iabs(board.hash^board.depth) % table_size; zkey_t *z = &transposition_table[n]; ScopedLock s(z->mut); if(board.depth >= z->depth) { From 36ce3d5085a9b20c0450464ca27e7ab62a42f6ff Mon Sep 17 00:00:00 2001 From: "Steven R. Brandt" Date: Mon, 1 Jun 2015 15:19:23 -0500 Subject: [PATCH 28/44] test webhook --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 5e3ac1b..844e2b7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -363,7 +363,7 @@ int chx_main() << "original" << ((chosen_evaluator == ORIGINAL) ? "=current" : "") << "," << "simple" << ((chosen_evaluator == SIMPLE) ? "=current" : "") << ")" << std::endl; - std::cout << " search \n\tswitches the current search method in use (" + std::cout << " search \n\tswitches the current search method in use (" << "minimax" << (search_method == MINIMAX ? "=current" : "") << ",alphabeta"<< (search_method == ALPHABETA ? "=current" : "") << ",mtdf" << (search_method == MTDF ? "=current" : "") From 7cf167762044ddcc8722c5cd437ec5e212283f86 Mon Sep 17 00:00:00 2001 From: "Steven R. Brandt" Date: Mon, 1 Jun 2015 15:23:46 -0500 Subject: [PATCH 29/44] test webhook --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 844e2b7..5e3ac1b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -363,7 +363,7 @@ int chx_main() << "original" << ((chosen_evaluator == ORIGINAL) ? "=current" : "") << "," << "simple" << ((chosen_evaluator == SIMPLE) ? "=current" : "") << ")" << std::endl; - std::cout << " search \n\tswitches the current search method in use (" + std::cout << " search \n\tswitches the current search method in use (" << "minimax" << (search_method == MINIMAX ? "=current" : "") << ",alphabeta"<< (search_method == ALPHABETA ? "=current" : "") << ",mtdf" << (search_method == MTDF ? "=current" : "") From 56b90060226b9d358c3e1e2ccc408f651d822341 Mon Sep 17 00:00:00 2001 From: linamaria11 Date: Mon, 1 Jun 2015 15:42:29 -0500 Subject: [PATCH 30/44] updated database --- headers/database.hpp | 7 ++++--- src/alphabeta.cpp | 5 +++++ src/main.cpp | 4 ++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/headers/database.hpp b/headers/database.hpp index ba22d4d..1bfb74f 100644 --- a/headers/database.hpp +++ b/headers/database.hpp @@ -54,8 +54,9 @@ class database { cout<<"database closed. \n"; }; - void add_data(const node_t& board, int ply, int hi, int lo){ - auto hash= board.hash; + void add_data(const node_t& board, int hi, int lo){ + int ply = board.ply; + auto hash= board.hash; const char *sql; //maybe find a way to make work without const //create SQL statement from string into char * array std::ostringstream o; @@ -71,7 +72,7 @@ class database { fprintf(stderr, "SQL error: %s\n", zErrMsg); sqlite3_free(zErrMsg); }else{ - fprintf(stdout, "Records created sucessfully\n"); + //fprintf(stdout, "Records created sucessfully\n"); } }; diff --git a/src/alphabeta.cpp b/src/alphabeta.cpp index 7571588..a4c2e98 100644 --- a/src/alphabeta.cpp +++ b/src/alphabeta.cpp @@ -8,12 +8,16 @@ //#undef NDEBUG #include "parallel_support.hpp" +#include "database.hpp" +#include "main.hpp" #include "search.hpp" #include #include "parallel.hpp" #include "zkey.hpp" #include +database dbase; + void search_ab_pt(boost::shared_ptr info) { info->result = search_ab(info); @@ -87,6 +91,7 @@ score_t search_ab(boost::shared_ptr proc_info) score_t max_val = bad_min_score; score_t zlo,zhi; + dbase.add_data(board, zhi, zlo); if(get_transposition_value(board,zlo,zhi)) { if(zlo >= beta) { return zlo; diff --git a/src/main.cpp b/src/main.cpp index 5e3ac1b..84017d6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -17,6 +17,7 @@ #include "parallel_support.hpp" #include +#include "database.hpp" #include "main.hpp" #include "pgn.hpp" #include @@ -34,6 +35,7 @@ #include #include + using namespace std; double sum_exec_times2 = 0; @@ -41,6 +43,8 @@ double sum_exec_times = 0; int count_exec_times; pcounter task_counter; + + void chx_terminate() { for(int i=0;i<3;i++) std::cout << std::endl; From b1eee759425c43fde32e9263a7c311fce43411cb Mon Sep 17 00:00:00 2001 From: "Steven R. Brandt" Date: Mon, 1 Jun 2015 16:01:06 -0500 Subject: [PATCH 31/44] Use case-sensitive print board. --- headers/database.hpp | 76 ++++++++++++++++---------------------------- headers/main.hpp | 3 +- src/main.cpp | 2 +- 3 files changed, 30 insertions(+), 51 deletions(-) diff --git a/headers/database.hpp b/headers/database.hpp index 1bfb74f..ddb16fa 100644 --- a/headers/database.hpp +++ b/headers/database.hpp @@ -8,11 +8,10 @@ #include "defs.hpp" #include "chess_move.hpp" #include "sqlite3.h" -//include "main.cpp" +#include "main.hpp" using namespace std; - class database { public: sqlite3 *db; @@ -49,55 +48,36 @@ class database { //destructor ~database(){ - get_data(); - sqlite3_close(db); - cout<<"database closed. \n"; - }; + get_data(); + sqlite3_close(db); + cout<<"database closed. \n"; + } void add_data(const node_t& board, int hi, int lo){ - int ply = board.ply; - auto hash= board.hash; - const char *sql; //maybe find a way to make work without const - //create SQL statement from string into char * array - std::ostringstream o; - - o<< "REPLACE INTO \"MoveSet\"VALUES ("<& workq, const char *s); char *move_str(chess_move& m); -void print_board(const node_t& board, std::ostream& out); +void print_board(const node_t& board, std::ostream& out,bool trimmed=false); int print_result(std::vector& workq, node_t& board); void start_benchmark(std::string filename, int ply_level, int num_runs,bool parallel); int get_ms(); diff --git a/src/main.cpp b/src/main.cpp index 84017d6..0cf29cf 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -699,7 +699,7 @@ int parse_move(std::vector& workq, const char *s) // print_board() prints the board -void print_board(const node_t& board, std::ostream& out) +void print_board(const node_t& board, std::ostream& out,bool trimmed) { int i; From 204d947578e9a0c038b5805700272e6ddee9ef95 Mon Sep 17 00:00:00 2001 From: Patrick Mancuso Date: Mon, 1 Jun 2015 16:23:43 -0500 Subject: [PATCH 32/44] trimmed print_board function --- src/main.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 0cf29cf..b11dd3a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -702,25 +702,26 @@ int parse_move(std::vector& workq, const char *s) void print_board(const node_t& board, std::ostream& out,bool trimmed) { int i; - - out << std::endl << "8 "; + + if (!trimmed) out << std::endl << "8 "; for (i = 0; i < 64; ++i) { + if (!trimmed) out << " "; switch (board.color[i]) { case EMPTY: - out << " ."; + out << "."; break; case LIGHT: - out << " " << piece_char[(size_t)board.piece[i]]; + out << piece_char[(size_t)board.piece[i]]; break; case DARK: char ch = (piece_char[(size_t)board.piece[i]] + ('a' - 'A')); - out << " " << ch; + out << ch; break; } if ((i + 1) % 8 == 0 && i != 63) - out << std::endl << 7 - ROW(i) << " "; + if (!trimmed) out << std::endl << 7 - ROW(i) << " "; } - out << std::endl << std::endl << " a b c d e f g h" << std::endl << std::endl; + if (!trimmed) out << std::endl << std::endl << " a b c d e f g h" << std::endl << std::endl; } From b8b8614745ad89c0cd28ece163a7ebb672196610 Mon Sep 17 00:00:00 2001 From: linamaria11 Date: Tue, 2 Jun 2015 11:06:37 -0500 Subject: [PATCH 33/44] new function --- headers/database.hpp | 26 ++++++++++++++++++++++++-- src/alphabeta.cpp | 5 +++-- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/headers/database.hpp b/headers/database.hpp index ddb16fa..d8a663c 100644 --- a/headers/database.hpp +++ b/headers/database.hpp @@ -78,7 +78,7 @@ class database { //fprintf(stdout, "Records created sucessfully\n"); } } - +//look for boards that are the same, look for boards >= to current depth, most importantly score greater than the current score int get_data(){ const char *data= "Callback function called"; const char *sql= "SELECT * from MoveSet"; @@ -89,7 +89,29 @@ class database { }else fprintf(stdout, "Operation done sucessfully\n"); return 0; - }; + } + + int search_board(const node_t& board){ + const char *sql; + const char *data= "Callback function called"; + std::ostringstream current; + print_board(board,current,true); + std::string curr = current.str(); + std::ostringstream out; + out<< "SELECT * FROM MoveSet WHERE BOARD=\""< proc_info) } + //int dbase.search_board(board); score_t max_val = bad_min_score; score_t zlo,zhi; - dbase.add_data(board, zhi, zlo); + dbase.search_board(board); if(get_transposition_value(board,zlo,zhi)) { if(zlo >= beta) { return zlo; @@ -235,7 +236,7 @@ score_t search_ab(boost::shared_ptr proc_info) DECL_SCORE(z,0,board.hash); return z; } - + dbase.add_data(board, zhi, zlo); set_transposition_value(board, max(zlo,max_val >= beta ? max_val : bad_min_score), min(zhi,max_val < alpha ? max_val : bad_max_score)); From 6e03023ff51b3ced6e37e146ec17d9c331476174 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frank=20L=C3=B6ffler?= Date: Tue, 2 Jun 2015 11:33:15 -0500 Subject: [PATCH 34/44] remove unused function --- headers/chess_move.hpp | 1 - src/chess_move.cpp | 4 ---- 2 files changed, 5 deletions(-) diff --git a/headers/chess_move.hpp b/headers/chess_move.hpp index e9769a4..72ca7ee 100644 --- a/headers/chess_move.hpp +++ b/headers/chess_move.hpp @@ -97,7 +97,6 @@ class chess_move { ar & this->bits; } std::string str(); - const char *c_str(); }; #endif diff --git a/src/chess_move.cpp b/src/chess_move.cpp index 160f25f..538b774 100644 --- a/src/chess_move.cpp +++ b/src/chess_move.cpp @@ -32,7 +32,3 @@ string chess_move::str() (char)('a' + COL(getTo())) << 8 - ROW(getTo()); return ostr.str(); } -const char* chess_move::c_str() -{ - return this->str().c_str(); -} From 09e2889f1f43f0726fd3b09ae2573158745ffe11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frank=20L=C3=B6ffler?= Date: Tue, 2 Jun 2015 11:35:54 -0500 Subject: [PATCH 35/44] intruduce new (but still empty) function chess_move::pgn --- headers/chess_move.hpp | 1 + src/chess_move.cpp | 13 ++++++------- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/headers/chess_move.hpp b/headers/chess_move.hpp index 72ca7ee..49dd40f 100644 --- a/headers/chess_move.hpp +++ b/headers/chess_move.hpp @@ -97,6 +97,7 @@ class chess_move { ar & this->bits; } std::string str(); + std::string pgn(); }; #endif diff --git a/src/chess_move.cpp b/src/chess_move.cpp index 538b774..ba526c3 100644 --- a/src/chess_move.cpp +++ b/src/chess_move.cpp @@ -7,11 +7,9 @@ using namespace std; string chess_move::str() { ostringstream ostr; - + ostr << (char)('a' + COL(getFrom())) << 8 - ROW(getFrom()) << + (char)('a' + COL(getTo())) << 8 - ROW(getTo()); if (getBits() & 32) - { - ostr << (char)('a' + COL(getFrom())) << 8 - ROW(getFrom()) << - (char)('a' + COL(getTo())) << 8 - ROW(getTo()); switch (getPromote()) { case KNIGHT: @@ -27,8 +25,9 @@ string chess_move::str() ostr << "q"; break; } - } else - ostr << (char)('a' + COL(getFrom())) << 8 - ROW(getFrom()) << - (char)('a' + COL(getTo())) << 8 - ROW(getTo()); return ostr.str(); } +string chess_move::str() +{ +} + From 384a732bfe9763e92b2fee6fc6d54c4f12c40112 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frank=20L=C3=B6ffler?= Date: Tue, 2 Jun 2015 11:59:37 -0500 Subject: [PATCH 36/44] remove unused function --- headers/chess_move.hpp | 8 -------- src/main.cpp | 2 +- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/headers/chess_move.hpp b/headers/chess_move.hpp index 49dd40f..8774b71 100644 --- a/headers/chess_move.hpp +++ b/headers/chess_move.hpp @@ -38,14 +38,6 @@ class chess_move { uint32_t get32BitMove() { return u; } - void set32BitMove(int32_t mv) - { - u = mv; - from = ((mv >> 24) & 0xFF); - to = ((mv >> 16) & 0xFF); - promote = ((mv >> 8) & 0xFF); - bits = ((mv >> 0) & 0xFF); - } void setBytes(int8_t from, int8_t to, int8_t promote, int8_t bits) { this->from = from; diff --git a/src/main.cpp b/src/main.cpp index 5e3ac1b..582d812 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -140,7 +140,7 @@ int chx_main() else print_result(workq, board); - move_to_make.set32BitMove(0); // Reset the chess_move to make + move_to_make.setBytes(0,0,0,0); // Reset the chess_move to make continue; } From 9cdd439643a8d79b266cf9011c966677475fd7ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frank=20L=C3=B6ffler?= Date: Tue, 2 Jun 2015 12:01:12 -0500 Subject: [PATCH 37/44] add unused function again, might be useful later --- headers/chess_move.hpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/headers/chess_move.hpp b/headers/chess_move.hpp index 8774b71..49dd40f 100644 --- a/headers/chess_move.hpp +++ b/headers/chess_move.hpp @@ -38,6 +38,14 @@ class chess_move { uint32_t get32BitMove() { return u; } + void set32BitMove(int32_t mv) + { + u = mv; + from = ((mv >> 24) & 0xFF); + to = ((mv >> 16) & 0xFF); + promote = ((mv >> 8) & 0xFF); + bits = ((mv >> 0) & 0xFF); + } void setBytes(int8_t from, int8_t to, int8_t promote, int8_t bits) { this->from = from; From fbf6e1ad824714cd6dfb6540aff8c77984bde121 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frank=20L=C3=B6ffler?= Date: Tue, 2 Jun 2015 12:09:26 -0500 Subject: [PATCH 38/44] add a little more towards pgn output --- headers/pgn.hpp | 2 +- src/chess_move.cpp | 24 +++++++++++++++++++++++- src/main.cpp | 4 ++-- src/pgn.cpp | 4 ++-- 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/headers/pgn.hpp b/headers/pgn.hpp index f67b916..1a02616 100644 --- a/headers/pgn.hpp +++ b/headers/pgn.hpp @@ -1,6 +1,6 @@ #ifndef CHESS_MOVE_H #include "chess_move.hpp" -void pgn_output(const chess_move &move); +void pgn_output(chess_move &move); #endif diff --git a/src/chess_move.cpp b/src/chess_move.cpp index ba526c3..9f9711a 100644 --- a/src/chess_move.cpp +++ b/src/chess_move.cpp @@ -1,5 +1,6 @@ #include #include "defs.hpp" +#include "data.hpp" #include "chess_move.hpp" using namespace std; @@ -27,7 +28,28 @@ string chess_move::str() } return ostr.str(); } -string chess_move::str() +string chess_move::pgn() { + ostringstream ostr; + ostr << piece_char[getFrom()]; + ostr << (char)('a' + COL(getFrom())) << 8 - ROW(getFrom()) << + (char)('a' + COL(getTo())) << 8 - ROW(getTo()); + if (getBits() & 32) + switch (getPromote()) + { + case KNIGHT: + ostr << "=N"; + break; + case BISHOP: + ostr << "=B"; + break; + case ROOK: + ostr << "=R"; + break; + default: + ostr << "=Q"; + break; + } + return ostr.str(); } diff --git a/src/main.cpp b/src/main.cpp index 582d812..d185dc6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -124,6 +124,8 @@ int chx_main() if (output) std::cout << "Computer's chess_move: " << move_to_make.str() << " time=" << std::setprecision(3) << 1e-3*(end-start) << " sec" << std::endl; + if (pgn_enabled) + pgn_output(move_to_make); makemove(board, move_to_make); // Make the chess_move for our master board board.ply = 0; // Reset the board ply to 0 @@ -133,8 +135,6 @@ int chx_main() if (output) print_board(board, std::cout); - if (pgn_enabled) - pgn_output(move_to_make); if (auto_move) auto_move = print_result(workq, board); else diff --git a/src/pgn.cpp b/src/pgn.cpp index e0ac51d..7c724b8 100644 --- a/src/pgn.cpp +++ b/src/pgn.cpp @@ -4,7 +4,7 @@ using namespace std; -void pgn_output(const chess_move &move) +void pgn_output(chess_move &move) { - cout << "pgn\n"; + cout << "pgn " << move.pgn() << endl; } From bb55c4baa5820ee228e37f7e47576a46a35c9609 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frank=20L=C3=B6ffler?= Date: Tue, 2 Jun 2015 14:47:16 -0500 Subject: [PATCH 39/44] towards working pgn --- headers/chess_move.hpp | 12 ++++++------ headers/pgn.hpp | 5 ++++- src/chess_move.cpp | 4 ++-- src/main.cpp | 4 ++-- src/pgn.cpp | 9 +++++++-- 5 files changed, 21 insertions(+), 13 deletions(-) diff --git a/headers/chess_move.hpp b/headers/chess_move.hpp index 49dd40f..ad7a475 100644 --- a/headers/chess_move.hpp +++ b/headers/chess_move.hpp @@ -55,10 +55,10 @@ class chess_move { u = ((from & 0xFF) << 24) + ((to & 0xFF) << 16) + ((promote & 0xFF) << 8) + ((bits & 0xFF) << 0); } - uint8_t getFrom() { return from; } - uint8_t getTo() { return to; } - uint8_t getPromote() { return promote; } - uint8_t getBits() { return bits; } + uint8_t getFrom() const { return from; } + uint8_t getTo() const { return to; } + uint8_t getPromote() const { return promote; } + uint8_t getBits() const { return bits; } uint8_t getCapture() const { return (bits & 1) != 0; } @@ -96,8 +96,8 @@ class chess_move { ar & this->promote; ar & this->bits; } - std::string str(); - std::string pgn(); + std::string str() const; + std::string pgn() const; }; #endif diff --git a/headers/pgn.hpp b/headers/pgn.hpp index 1a02616..c40b07a 100644 --- a/headers/pgn.hpp +++ b/headers/pgn.hpp @@ -1,6 +1,9 @@ #ifndef CHESS_MOVE_H #include "chess_move.hpp" -void pgn_output(chess_move &move); +#include "node.hpp" +#include "data.hpp" + +const void pgn_output(const node_t &board, const chess_move &move); #endif diff --git a/src/chess_move.cpp b/src/chess_move.cpp index 9f9711a..83f545c 100644 --- a/src/chess_move.cpp +++ b/src/chess_move.cpp @@ -5,7 +5,7 @@ using namespace std; -string chess_move::str() +string chess_move::str() const { ostringstream ostr; ostr << (char)('a' + COL(getFrom())) << 8 - ROW(getFrom()) << @@ -28,7 +28,7 @@ string chess_move::str() } return ostr.str(); } -string chess_move::pgn() +string chess_move::pgn() const { ostringstream ostr; ostr << piece_char[getFrom()]; diff --git a/src/main.cpp b/src/main.cpp index f189ae9..fc6192d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -129,7 +129,7 @@ int chx_main() std::cout << "Computer's chess_move: " << move_to_make.str() << " time=" << std::setprecision(3) << 1e-3*(end-start) << " sec" << std::endl; if (pgn_enabled) - pgn_output(move_to_make); + pgn_output(board, move_to_make); makemove(board, move_to_make); // Make the chess_move for our master board board.ply = 0; // Reset the board ply to 0 @@ -396,7 +396,7 @@ int chx_main() else { makemove(board, mov); if (pgn_enabled) - pgn_output(mov); + pgn_output(board, mov); board.ply = 0; workq.clear(); gen(workq, board); diff --git a/src/pgn.cpp b/src/pgn.cpp index 7c724b8..114c123 100644 --- a/src/pgn.cpp +++ b/src/pgn.cpp @@ -4,7 +4,12 @@ using namespace std; -void pgn_output(chess_move &move) +const void pgn_output(const node_t &board, const chess_move &move) { - cout << "pgn " << move.pgn() << endl; + string piece; + piece = piece_char[(size_t)board.piece[move.getTo()]]; + if (piece == "p") + piece = ""; + cout << "pgn " << piece << (move.getCapture()?"x":"") << move.pgn() << endl; } + From 62e1ff122976d2b7ccb281940ee0b685dffdae99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frank=20L=C3=B6ffler?= Date: Tue, 2 Jun 2015 14:48:04 -0500 Subject: [PATCH 40/44] ignore db files --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index e853770..861cc3d 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ CMakeCache.txt CMakeFiles Makefile cmake_install.cmake +test.db* From bc531fbdf8bd114376a286c6e052c5811b7ea1df Mon Sep 17 00:00:00 2001 From: linamaria11 Date: Wed, 3 Jun 2015 14:08:32 -0500 Subject: [PATCH 41/44] for patrick --- headers/database.hpp | 49 +++++++++++++++++++++++++++++++------------- src/alphabeta.cpp | 3 +-- 2 files changed, 36 insertions(+), 16 deletions(-) diff --git a/headers/database.hpp b/headers/database.hpp index d8a663c..abb6178 100644 --- a/headers/database.hpp +++ b/headers/database.hpp @@ -70,7 +70,7 @@ class database { //char *sql = "REPLACE INTO \"MOVELIST\"VALUES (69,0);"; //"INSERT INTO \"MOVELIST\"VALUES (66,0);"; //execute SQL statement - rc = sqlite3_exec(db, sql, 0, 0, &zErrMsg); + rc = sqlite3_exec(db, sql, callback, 0, &zErrMsg); if ( rc!= SQLITE_OK ){ fprintf(stderr, "SQL error: %s\n", zErrMsg); sqlite3_free(zErrMsg); @@ -82,7 +82,7 @@ class database { int get_data(){ const char *data= "Callback function called"; const char *sql= "SELECT * from MoveSet"; - rc= sqlite3_exec(db, sql, callback, (void*)data, &zErrMsg); + rc= sqlite3_exec(db, sql, 0, (void*)data, &zErrMsg); if (rc!= SQLITE_OK ){ fprintf(stderr, "SQL error: %s\n", zErrMsg); sqlite3_free(zErrMsg); @@ -91,40 +91,61 @@ class database { return 0; } - int search_board(const node_t& board){ + int search_board(const node_t& board,std::ostringstream& out, const char *select, const char *value, std::string& search){ const char *sql; const char *data= "Callback function called"; - std::ostringstream current; - print_board(board,current,true); - std::string curr = current.str(); - std::ostringstream out; - out<< "SELECT * FROM MoveSet WHERE BOARD=\""<depth >= 0 && board_equals(board, z->board)){ + lower = z->lower; + upper = z->upper; + gotten = true + } else { + lower = bad_min_score; + upper = bad_max_score; + }*/ + return gotten; +} //callback used for select operation static int callback(void *NotUsed, int argc, char **argv, char **azColName){ int i; + std::ostringstream out; for(i=0; i proc_info) } - //int dbase.search_board(board); score_t max_val = bad_min_score; score_t zlo,zhi; - dbase.search_board(board); + dbase.get_transposition_value(board,zlo,zhi); if(get_transposition_value(board,zlo,zhi)) { if(zlo >= beta) { return zlo; From 7a346b0d174454af0626dab633d90152f3712802 Mon Sep 17 00:00:00 2001 From: Patrick Mancuso Date: Thu, 4 Jun 2015 15:15:30 -0500 Subject: [PATCH 42/44] uses table function from sqlite3 --- headers/database.hpp | 62 +++++++++++++++++++++++++++++++++++++++++--- src/alphabeta.cpp | 4 +-- src/main.cpp | 2 +- 3 files changed, 62 insertions(+), 6 deletions(-) diff --git a/headers/database.hpp b/headers/database.hpp index abb6178..cc05991 100644 --- a/headers/database.hpp +++ b/headers/database.hpp @@ -44,6 +44,7 @@ class database { }else{ fprintf(stdout, "Table created successfully\n"); } +// deleteAll(); }; //destructor @@ -53,6 +54,17 @@ class database { cout<<"database closed. \n"; } + void deleteAll(){ + const char *sql; + std::ostringstream o; + o<<"delete from \"MoveSet\""; + std::string result = o.str(); + sql=result.c_str(); + rc = sqlite3_exec(db, sql, callback, 0, &zErrMsg); + if ( rc == SQLITE_OK) cout<<"MoveSet sucessfully reset"; + else{ cout< 0) { + stringstream strValue; /* + strValue <<*azResult[5]; + //std::string s= *azResult[5]; + int num;//= atoi(s.c_str()); + strValue>>num; + if (num == board.depth){*/ + int num; + for (int i=0; i<2; i++){ + strValue<<* azResult[7+i]; + strValue>>num; + //s= *azResult[7+i]; + //num =atoi(s.c_str()); + if (i==1) zhi=num; + else zlo=num; +// } + gotten=true; + } + } + sqlite3_free_table(azResult); + return gotten; + } + int search_board(const node_t& board,std::ostringstream& out, const char *select, const char *value, std::string& search){ const char *sql; - const char *data= "Callback function called"; + char *data= (char *)calloc(1, sizeof (*data)); out<< "SELECT "< proc_info) score_t max_val = bad_min_score; score_t zlo,zhi; - dbase.get_transposition_value(board,zlo,zhi); - if(get_transposition_value(board,zlo,zhi)) { + //dbase.add_data(board,zlo,zhi); + if(dbase.get_database_value(board,zlo,zhi)) { if(zlo >= beta) { return zlo; } diff --git a/src/main.cpp b/src/main.cpp index fc6192d..cdc6458 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -702,7 +702,7 @@ int parse_move(std::vector& workq, const char *s) void print_board(const node_t& board, std::ostream& out,bool trimmed) { int i; - + //if (trimmed) out<<'&'; if (!trimmed) out << std::endl << "8 "; for (i = 0; i < 64; ++i) { if (!trimmed) out << " "; From 684b4820f05afeaee718863db7fdd33002fcfca4 Mon Sep 17 00:00:00 2001 From: "Steven R. Brandt" Date: Thu, 4 Jun 2015 16:05:13 -0500 Subject: [PATCH 43/44] got things closer to working. --- harness_plain.pl | 3 +- headers/database.hpp | 194 +++++++++++++++++++++---------------------- src/alphabeta.cpp | 6 +- 3 files changed, 100 insertions(+), 103 deletions(-) diff --git a/harness_plain.pl b/harness_plain.pl index 53da91c..ea1c419 100755 --- a/harness_plain.pl +++ b/harness_plain.pl @@ -96,7 +96,7 @@ for(my $ply=4;$ply<=6;$ply++) { for(my $b=1;$b<=4;$b++) { - for my $sm (("minimax","alphabeta","mtdf")) { + for my $sm (("alphabeta")) { # It takes too long for minimax above ply 4 # So I ran it once at 5 to verify the answer # and then introduced this next. @@ -133,6 +133,7 @@ $cmd="CHX_THREADS_PER_PROC=$threads $mem $chx < .bench|"; } print "cmd=$cmd\n"; + system("rm -f test.db"); open($fd,$cmd); my $ans = ""; my $score = $bad_score; diff --git a/headers/database.hpp b/headers/database.hpp index cc05991..20d4c90 100644 --- a/headers/database.hpp +++ b/headers/database.hpp @@ -32,8 +32,8 @@ class database { sql = "CREATE TABLE MoveSet(" \ "PLY INTEGER NOT NULL," \ "BOARD TEXT NOT NULL,"\ - "HI INTEGER NOT NULL,"\ - "LO INTEGER NOT NULL,"\ + "HI NUMERIC(20) NOT NULL,"\ + "LO NUMERIC(20) NOT NULL,"\ "HASH INTEGER NOT NULL,"\ "PRIMARY KEY (PLY, BOARD));"; //Execute SQL statement @@ -65,7 +65,7 @@ class database { else{ cout< 0) { - stringstream strValue; /* - strValue <<*azResult[5]; - //std::string s= *azResult[5]; - int num;//= atoi(s.c_str()); - strValue>>num; - if (num == board.depth){*/ - int num; - for (int i=0; i<2; i++){ - strValue<<* azResult[7+i]; - strValue>>num; - //s= *azResult[7+i]; - //num =atoi(s.c_str()); - if (i==1) zhi=num; - else zlo=num; -// } - gotten=true; - } - } - sqlite3_free_table(azResult); - return gotten; + bool get_database_value(const node_t& board, score_t& zlo, score_t& zhi){ + bool gotten = false; + const char *sql; + std::ostringstream current, out; + print_board(board, current, true); + std::string curr = current.str(); + out<< "SELECT LO, HI FROM MoveSet WHERE \"BOARD\"=\""< 0) { + for (int i=0; i<(nrow+1)*ncolumn;i++) + cout<<"azResult["<depth >= 0 && board_equals(board, z->board)){ - lower = z->lower; - upper = z->upper; - gotten = true - } else { - lower = bad_min_score; - upper = bad_max_score; - }*/ - return gotten; -} - - //callback used for select operation - static int callback(void *NotUsed, int argc, char **argv, char **azColName){ - int i; - std::ostringstream out; - char ** res = (char **) NotUsed; - //*res=NULL(sizeof(char *)); - // cout<depth >= 0 && board_equals(board, z->board)){ + lower = z->lower; + upper = z->upper; + gotten = true + } else { + lower = bad_min_score; + upper = bad_max_score; + }*/ + return gotten; + } + + //callback used for select operation + static int callback(void *NotUsed, int argc, char **argv, char **azColName){ + int i; + std::ostringstream out; + char ** res = (char **) NotUsed; + //*res=NULL(sizeof(char *)); + // cout< proc_info) score_t max_val = bad_min_score; - score_t zlo,zhi; + score_t zlo = bad_min_score,zhi = bad_max_score; //dbase.add_data(board,zlo,zhi); if(dbase.get_database_value(board,zlo,zhi)) { if(zlo >= beta) { @@ -235,7 +235,9 @@ score_t search_ab(boost::shared_ptr proc_info) DECL_SCORE(z,0,board.hash); return z; } - dbase.add_data(board, zhi, zlo); + dbase.add_data(board, + max(zlo,max_val >= beta ? max_val : bad_min_score), + min(zhi,max_val < alpha ? max_val : bad_max_score)); set_transposition_value(board, max(zlo,max_val >= beta ? max_val : bad_min_score), min(zhi,max_val < alpha ? max_val : bad_max_score)); From e4891456540e3d8409d73e35c5e9bf8e440633ce Mon Sep 17 00:00:00 2001 From: "Steven R. Brandt" Date: Thu, 4 Jun 2015 16:36:47 -0500 Subject: [PATCH 44/44] Don't confuse ply and depth. --- headers/database.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/headers/database.hpp b/headers/database.hpp index 20d4c90..c905210 100644 --- a/headers/database.hpp +++ b/headers/database.hpp @@ -66,7 +66,7 @@ class database { } void add_data(const node_t& board, score_t lo, score_t hi){ - int ply = board.ply; + int ply = board.depth; auto hash= board.hash; const char *sql; //maybe find a way to make work without const //create SQL statement from string into char * array