Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
9a45b7f
comment asserts that won't compile
knarrff May 29, 2015
d80e552
Merge branch 'master' of https://github.com/STEllAR-GROUP/chess
knarrff May 29, 2015
1500950
Merge branch 'master' of https://github.com/STEllAR-GROUP/chess
knarrff Jun 1, 2015
e6f75e6
enable readline
knarrff Jun 1, 2015
dc98236
Merge branch 'master' of https://github.com/STEllAR-GROUP/chess
knarrff Jun 1, 2015
a940385
make perl harnesses executable
knarrff Jun 1, 2015
d25319b
make perl scripts executable
knarrff Jun 1, 2015
211cbe3
Merge branch 'master' of https://github.com/stevenrbrandt/chess
knarrff Jun 1, 2015
2a29883
Merge branch 'master' of https://github.com/stevenrbrandt/chess
knarrff Jun 1, 2015
9aa8bd9
add sqlite3 support to cmake
knarrff Jun 1, 2015
c5edeed
add sqlite3 support to cmake
knarrff Jun 1, 2015
05aa081
add pgn command (unused so far)
knarrff Jun 1, 2015
3a62f3d
ignore some generated files
knarrff Jun 1, 2015
21bf077
add (empty) output routine for pgn
knarrff Jun 1, 2015
90e230d
fix linking.
stevenrbrandt Jun 1, 2015
0b2a02e
Merge branch 'master' of https://github.com/stevenrbrandt/chess
stevenrbrandt Jun 1, 2015
11a675e
fixing help message
stevenrbrandt Jun 1, 2015
4c67c7a
added white space for test
stevenrbrandt Jun 1, 2015
b9cfa55
testing webhooks
stevenrbrandt Jun 1, 2015
f20d491
test webhook
stevenrbrandt Jun 1, 2015
68bb690
test webhook
stevenrbrandt Jun 1, 2015
61fd8e2
test webhook
stevenrbrandt Jun 1, 2015
08b3785
test webhook
stevenrbrandt Jun 1, 2015
6fc2ee7
test webhook
stevenrbrandt Jun 1, 2015
d514af3
test webhook
stevenrbrandt Jun 1, 2015
34da98e
make perl scripts executable
knarrff Jun 1, 2015
5a1c57f
test webhook
stevenrbrandt Jun 1, 2015
bbf7587
move to member function for printing of moves
knarrff Jun 1, 2015
b2b7ba3
Merge branch 'master' of https://github.com/stevenrbrandt/chess
knarrff Jun 1, 2015
85e9ac0
Merge branch 'master' of https://github.com/stevenrbrandt/chess
knarrff Jun 1, 2015
6825d4e
test webhook
stevenrbrandt Jun 1, 2015
098fd9f
Merge branch 'master' of https://github.com/stevenrbrandt/chess
stevenrbrandt Jun 1, 2015
a5b2204
add shebangs
knarrff Jun 1, 2015
9c5c2ac
Merge branch 'master' of https://github.com/stevenrbrandt/chess
knarrff Jun 1, 2015
7e0e1b4
new database file
Jun 1, 2015
69421dd
testing? Merge branch 'master' of https://github.com/stevenrbrandt/chess
Jun 1, 2015
bf59e02
new database file
Jun 1, 2015
7e0260a
Minor compilation problems.
stevenrbrandt Jun 1, 2015
36ce3d5
test webhook
stevenrbrandt Jun 1, 2015
7cf1677
test webhook
stevenrbrandt Jun 1, 2015
56b9006
updated database
Jun 1, 2015
b1eee75
Use case-sensitive print board.
stevenrbrandt Jun 1, 2015
204d947
trimmed print_board function
Jun 1, 2015
b8b8614
new function
Jun 2, 2015
6e03023
remove unused function
knarrff Jun 2, 2015
09e2889
intruduce new (but still empty) function chess_move::pgn
knarrff Jun 2, 2015
384a732
remove unused function
knarrff Jun 2, 2015
9cdd439
add unused function again, might be useful later
knarrff Jun 2, 2015
fbf6e1a
add a little more towards pgn output
knarrff Jun 2, 2015
747a96e
Merge branch 'master' of https://github.com/stevenrbrandt/chess
knarrff Jun 2, 2015
bb55c4b
towards working pgn
knarrff Jun 2, 2015
62e1ff1
ignore db files
knarrff Jun 2, 2015
bc531fb
for patrick
Jun 3, 2015
7a346b0
uses table function from sqlite3
Jun 4, 2015
684b482
got things closer to working.
stevenrbrandt Jun 4, 2015
e489145
Don't confuse ply and depth.
stevenrbrandt Jun 4, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.bench
CMakeCache.txt
CMakeFiles
Makefile
cmake_install.cmake
test.db*
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ 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(Readline)
find_package(SQLite3)

if(READLINE_FOUND)
message("Readline was found.")
Expand Down
87 changes: 87 additions & 0 deletions cmake/FindSQLite3.cmake
Original file line number Diff line number Diff line change
@@ -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 <mail@cynapses.org>
#
# 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)

1 change: 1 addition & 0 deletions harness_helgrind.pl
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/perl
################################################################################
## Copyright (c) 2011 Steve Brandt and Philip LeBlanc
##
Expand Down
1 change: 1 addition & 0 deletions harness_memcheck.pl
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/perl
################################################################################
## Copyright (c) 2011 Steve Brandt and Philip LeBlanc
##
Expand Down
4 changes: 3 additions & 1 deletion harness_plain.pl
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/perl
################################################################################
## Copyright (c) 2011 Steve Brandt and Philip LeBlanc
##
Expand Down Expand Up @@ -95,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.
Expand Down Expand Up @@ -132,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;
Expand Down
11 changes: 7 additions & 4 deletions headers/chess_move.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#define CHESS_MOVE_HPP_C1BEDE43_B47B_4694_ACF4_F41143D72B97

#include <stdint.h>
#include <string>
/* 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,
Expand Down Expand Up @@ -54,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;
}
Expand Down Expand Up @@ -95,6 +96,8 @@ class chess_move {
ar & this->promote;
ar & this->bits;
}
std::string str() const;
std::string pgn() const;
};

#endif
202 changes: 202 additions & 0 deletions headers/database.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
#ifndef DATABASE_H
#define DATABASE_H
#include <sstream>
#include <iostream>
#include "hash.hpp"
#include "node.hpp"
#include "data.hpp"
#include "defs.hpp"
#include "chess_move.hpp"
#include "sqlite3.h"
#include "main.hpp"

using namespace std;

class database {
public:
sqlite3 *db;
char *zErrMsg=0;
int rc;


database(){
const 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 NUMERIC(20) NOT NULL,"\
"LO NUMERIC(20) 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");
}
// deleteAll();
};

//destructor
~database(){
get_data();
sqlite3_close(db);
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<<zErrMsg<<"/n"; sqlite3_free(zErrMsg);}
}

void add_data(const node_t& board, score_t lo, score_t hi){
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
std::ostringstream bsm;
print_board(board,bsm,true);
std::string bs = bsm.str();

std::ostringstream o;

o<< "INSERT OR REPLACE INTO \"MoveSet\"VALUES ("<<ply<<",'"<<bs<<"',"<<hi<<","<<lo<<","<<hash<<");";
std::string result = o.str();
sql=result.c_str();
//char *sql = "REPLACE INTO \"MOVELIST\"VALUES (69,0);";
//"INSERT INTO \"MOVELIST\"VALUES (66,0);";
//execute SQL statement
rc = sqlite3_exec(db, sql, callback, 0, &zErrMsg);
if ( rc!= SQLITE_OK ){
fprintf(stderr, "SQL error: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
}else{
//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";
rc= sqlite3_exec(db, sql, 0, (void*)data, &zErrMsg);
if (rc!= SQLITE_OK ){
fprintf(stderr, "SQL error: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
}else
fprintf(stdout, "Operation done sucessfully\n");
return 0;
}

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\"=\""<<curr<<"\" AND \"PLY\"="<<board.depth<<";";
std::string result = out.str();
sql=result.c_str();
int nrow, ncolumn;
char ** azResult=NULL;//index:5=ply,6=board, 7=hi, 8=lo
rc= sqlite3_get_table(db, sql, &azResult, &nrow, &ncolumn, &zErrMsg);
if(nrow > 0) {
for (int i=0; i<(nrow+1)*ncolumn;i++)
cout<<"azResult["<<i<<"] ="<<azResult[i]<<"\n";
cout << "nrow=" << nrow << " ncol=" << ncolumn << endl;
stringstream strValue; /*
strValue <<*azResult[5];
//std::string s= *azResult[5];
int num;//= atoi(s.c_str());
strValue>>num;
if (num == board.depth)*/
zlo = atoi(azResult[ncolumn+0]);
zhi = atoi(azResult[ncolumn+1]);
cout << "zlo=" << zlo << " zhi=" << zhi << endl;
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;
char *data= (char *)calloc(1, sizeof (*data));
out<< "SELECT "<<select<<" FROM MoveSet WHERE \""<<value<<"\"=\""<<search<<"\";";
std::string result = out.str();
sql = result.c_str();
rc = sqlite3_exec(db,sql,callback, (void*)data,&zErrMsg);
cout<<data<<"/n";
//cout<<"This is callback"<< callback << "\n";
if (rc!= SQLITE_OK){
fprintf(stderr, "SQL error: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
}else
//fprintf(stdout, "Looked through board successfully\n");
return rc;


}

bool get_transposition_value(const node_t& board, score_t& lower, score_t& upper){
bool gotten = false;
std::ostringstream current;
print_board(board,current,true);
std::string curr = current.str();
const char *hash = "HASH, HI";
const char *b = "BOARD";
std::ostringstream search;
search_board(board,search, hash, b, curr);
std::string buscar = search.str();
//cout<< "Value "<< buscar<<"\n";
//fprintf(stdout, "Value: %s", search);
/*if (z->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<<res<<"test\n";
*res =(char *)calloc(strlen(argv[2]),sizeof(char *));
strcpy(*res, argv[2]);
return 0;
for(i=0; i<argc; i++){
out<< argv[i]<<"\n";
// printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
}
printf("\n");
return 0;
};
int main(){
return 0;
}

};
//extern database dbase;
#endif
5 changes: 3 additions & 2 deletions headers/main.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2011 Steve Brandt and Phillip LeBlanc
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand All @@ -19,13 +19,14 @@
int main(int argc, char *argv[]);
int parse_move(std::vector<chess_move>& 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<chess_move>& workq, node_t& board);
void start_benchmark(std::string filename, int ply_level, int num_runs,bool parallel);
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
Expand Down
Loading