Skip to content

Commit

Permalink
* potential segfault fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jcarolus committed Oct 21, 2022
1 parent 7fda0a1 commit 6a9c493
Show file tree
Hide file tree
Showing 8 changed files with 7 additions and 58 deletions.
Binary file modified app/src/main/jniLibs/arm64-v8a/libchess-jni.so
Binary file not shown.
Binary file modified app/src/main/jniLibs/armeabi-v7a/libchess-jni.so
Binary file not shown.
Binary file modified app/src/main/jniLibs/x86/libchess-jni.so
Binary file not shown.
Binary file modified app/src/main/jniLibs/x86_64/libchess-jni.so
Binary file not shown.
37 changes: 0 additions & 37 deletions native/project/jni/ChessBoard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ ChessBoard::ChessBoard(void) {
}

ChessBoard::~ChessBoard(void) {
// if(m_parent)
// delete m_parent;
}

#pragma region Attack functions
Expand Down Expand Up @@ -1751,41 +1749,6 @@ void ChessBoard::commitBoard() {
// duplicate/clone the board
void ChessBoard::duplicate(ChessBoard* ret) {
memcpy(ret, this, SIZEOF_BOARD);
/*
ret->m_turn = this->m_turn;
ret->m_o_turn = this->m_o_turn;
ret->m_ep = this->m_ep;
ret->m_state = this->m_state;
ret->m_castlings[BLACK] = this->m_castlings[BLACK];
ret->m_castlings[WHITE] = this->m_castlings[WHITE];
ret->m_50RuleCount = this->m_50RuleCount;
ret->m_hashKey = this->m_hashKey;
ret->m_parent = this->m_parent;
ret->m_myMove = this->m_myMove;
ret->m_numBoard = this->m_numBoard;
ret->m_quality = this->m_quality;
ret->m_o_quality = this->m_o_quality;
ret->m_kingPos = this->m_kingPos;
ret->m_o_kingPos = this->m_o_kingPos;
ret->m_bitbPositions[BLACK] = this->m_bitbPositions[BLACK];
ret->m_bitbPositions[WHITE] = this->m_bitbPositions[WHITE];
ret->m_bitb = this->m_bitb;
ret->m_bitb_45 = this->m_bitb_45;
ret->m_bitb_90 = this->m_bitb_90;
ret->m_bitb_315 = this->m_bitb_315;
ret->m_bitbAttackMoveSquares = this->m_bitbAttackMoveSquares;
for(int i = 0; i < NUM_PIECES; i++)
{
ret->m_bitbPieces[BLACK][i] = this->m_bitbPieces[BLACK][i];
ret->m_bitbPieces[WHITE][i] = this->m_bitbPieces[WHITE][i];
}
ret->m_sizeMoves = this->m_sizeMoves;
for(int i = 0; i < m_sizeMoves; i++)
ret->m_arrMoves[i] = this->m_arrMoves[i];
*/
}

// convinient method to return pointer to first board
Expand Down
23 changes: 6 additions & 17 deletions native/project/jni/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,9 @@ Game::~Game(void) {

delete m_boardRefurbish;

// DEBUG_PRINT("\nDeleting boardFactory\n", 0);
// for (int i = 0; i < MAX_DEPTH; i++) {
// delete m_boardFactory[i];
// DEBUG_PRINT("%d ", i);
// }
for (int i = 0; i < MAX_DEPTH; i++) {
delete m_boardFactory[i];
}
}

void Game::reset() {
Expand Down Expand Up @@ -168,15 +166,6 @@ void Game::search() {
// break; //debug

if (bContinue) {
#if DEBUG_LEVEL & 2
DEBUG_PRINT("\n +-+-+-+-+-+-+-+-PV: ", 0);

for (i = 0; i < m_searchDepth; i++) {
Move::toDbgString(m_arrPVMoves[i], buf);
DEBUG_PRINT(" > %s", buf);
}
DEBUG_PRINT(" {%d}\n", m_bestValue);
#endif
reachedDepth++;
if (m_bestValue == ChessBoard::VALUATION_MATE) {
DEBUG_PRINT("Found checkmate, stopping search\n", 0);
Expand Down Expand Up @@ -211,7 +200,7 @@ void Game::search() {
}

boolean Game::alphaBetaRoot(const int depth, int alpha, const int beta) {
if (m_bInterrupted) {
if (m_bInterrupted || depth >= MAX_DEPTH) {
return false; //
}
int value = 0;
Expand Down Expand Up @@ -290,7 +279,7 @@ int Game::alphaBeta(ChessBoard *board, const int depth, int alpha, const int bet
m_bInterrupted = true;
}
}
if (m_bInterrupted) {
if (m_bInterrupted || depth >= MAX_DEPTH) {
return alpha; //
}
int value = 0;
Expand Down Expand Up @@ -365,7 +354,7 @@ int Game::quiesce(ChessBoard *board, const int depth, int alpha, const int beta)
}
}

if (m_bInterrupted) {
if (m_bInterrupted || depth >= MAX_DEPTH) {
return alpha; //
}

Expand Down
3 changes: 0 additions & 3 deletions native/project/jni/chess-jni.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,11 @@ JNIEXPORT void JNICALL Java_jwtc_chess_JNI_undo(JNIEnv* env, jobject thiz) {

JNIEXPORT void JNICALL Java_jwtc_chess_JNI_reset(JNIEnv* env, jobject thiz) {
stGame->reset();
// DEBUG_PRINT("Reset\n", 0);
}
JNIEXPORT void JNICALL
Java_jwtc_chess_JNI_putPiece(JNIEnv* env, jobject thiz, jint pos, jint piece, jint turn) {
ChessBoard* board = stGame->getBoard();
board->put(pos, piece, turn);

// DEBUG_PRINT("Put [%d, %d, %d]\n", pos, piece, turn);
}

JNIEXPORT void JNICALL Java_jwtc_chess_JNI_searchMove(JNIEnv* env, jobject thiz, jint secs) {
Expand Down
2 changes: 1 addition & 1 deletion native/project/jni/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ bool testGame() {
board->myMoveToString(buf);
DEBUG_PRINT("\n=====> %d, %d, %s\n", board->getNumBoard(), board->getState(), buf);

if (i++ > 20) {
if (i++ > 5) {
break;
}
}
Expand Down

0 comments on commit 6a9c493

Please sign in to comment.