Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some changes needed for android compilation #5 #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.idea/
11 changes: 11 additions & 0 deletions game.c
Original file line number Diff line number Diff line change
Expand Up @@ -1574,3 +1574,14 @@ get_pv( int *destin ) {
return pv_depth[0] + 1;
}
}

void clear_endgame_performed() {
endgame_performed[BLACKSQ] = endgame_performed[WHITESQ] = FALSE;
}

void clear_evaluated(void) {
game_evaluated_count = 0;
}



7 changes: 6 additions & 1 deletion game.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ void
game_init( const char *file_name,
int *side_to_move );

void
clear_endgame_performed( void );

void
set_komi( int in_komi );

Expand Down Expand Up @@ -90,6 +93,9 @@ get_evaluated_count( void );
EvaluatedMove
get_evaluated( int index );

void
clear_evaluated( void );

int
compute_move( int side_to_move,
int update_all,
Expand All @@ -111,7 +117,6 @@ int
get_pv( int *destin );



#ifdef __cplusplus
}
#endif
Expand Down
17 changes: 11 additions & 6 deletions getcoeff.c
Original file line number Diff line number Diff line change
Expand Up @@ -929,16 +929,17 @@ init_coeffs( void ) {
/* Special hack for CE. */
getcwd(sPatternFile, sizeof(sPatternFile));
strcat(sPatternFile, PATTERN_FILE);
#elif defined(ANDROID)
sprintf(sPatternFile, "%s/%s", android_files_dir, PATTERN_FILE);
#elif defined( __linux__ )
/* Linux don't support current directory. */
strcpy( sPatternFile, PATTERN_FILE );
#else
getcwd(sPatternFile, sizeof(sPatternFile));
strcat(sPatternFile, "/" PATTERN_FILE);
#endif
char* env_coeffs = getenv("COEFFS_PATH");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to keep this, It's used in snapshot tests and fuzzer. Did you have problems with getenv on android?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't think so. cant remember why i removed this, possible in a diff or something


coeff_stream = gzopen(env_coeffs ? env_coeffs : sPatternFile, "rb" );
coeff_stream = gzopen( sPatternFile, "rb" );
if ( coeff_stream == NULL )
fatal_error( "%s '%s'\n", FILE_ERROR, sPatternFile );

Expand Down Expand Up @@ -1046,10 +1047,14 @@ init_coeffs( void ) {

static long long int
rdtsc( void ) {
#if defined(__GNUC__)
long long a;
asm volatile("rdtsc":"=A" (a));
return a;
#ifdef _X64_
#if defined(__GNUC__)
long long a;
asm volatile("rdtsc":"=A" (a));
return a;
#else
return 0;
#endif
#else
return 0;
#endif
Expand Down
4 changes: 4 additions & 0 deletions globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,9 @@ extern int white_moves[60];
but all updates must be reversed when the search stops. */
extern Board board;

#ifdef ANDROID
int droidzebra_message_debug(const char* format, ...);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not the nicest thing in the world but what can we do 🤷‍♂️

Ideally this project should not depend on droidzebra like this, so the function should be somehow injected from the outside, but we got no time for that business

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe this could just be a standard debug function like message_debug ...

#define printf(format, args...) droidzebra_message_debug(format , ## args)
#endif

#endif /* GLOBALS_H */
11 changes: 11 additions & 0 deletions learn.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ clear_stored_game( void ) {
game_move[i] = ILLEGAL;
}

/*
GET_STORED_MOVE
get stored move
*/

int
get_stored_move( int index ) {
if(index>60) return ILLEGAL;
return game_move[index];
}



/*
Expand Down
4 changes: 4 additions & 0 deletions learn.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ extern "C" {
void
clear_stored_game( void );

int
get_stored_move( int index );


void
store_move( int disks_played, int move );

Expand Down
18 changes: 11 additions & 7 deletions macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,18 @@ extern "C" {


/* Define function attributes directive when available */
#if __GNUC__ >= 3
#define REGPARM(num) __attribute__((regparm(num)))
#ifdef _X64_
#if __GNUC__ >= 3
#define REGPARM(num) __attribute__((regparm(num)))
#else
#if defined (_MSC_VER) || defined(__BORLANDC__)
#define REGPARM(num) __fastcall
#else
#define REGPARM(num)
#endif
#endif
#else
#if defined (_MSC_VER) || defined(__BORLANDC__)
#define REGPARM(num) __fastcall
#else
#define REGPARM(num)
#endif
#define REGPARM(num)
#endif


Expand Down
111 changes: 111 additions & 0 deletions osfbook.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <zlib.h>
#include <errno.h>

#ifndef _WIN32_WCE
#include <time.h>
Expand Down Expand Up @@ -3436,6 +3438,115 @@ unpack_compressed_database( const char *in_name, const char *out_name ) {
#endif
}

void
unpack_compressed_database_gz( const char *in_name, const char *out_name ) {
int i;
int dummy;
int node_count, child_list_size;
int node_index, child_index;
short magic;
short *child_count, *child;
short *black_score, *white_score;
short *alt_move, *alt_score;
time_t start_time, stop_time;
unsigned short *flags;
gzFile *zstream;
FILE * stream;
int zerror;

#ifdef TEXT_BASED
printf( "Uncompressing compressed database... " );
fflush( stdout );
#endif

#define CHECK_READ(op, size) if((op)!=(size)) fatal_error("error reading compressed database: %s", gzerror(zstream, &zerror));

time( &start_time );

/* Read the compressed database */

zstream = gzopen( in_name, "rb" );
if ( zstream == NULL )
fatal_error( "%s '%s'\n", NO_DB_FILE_ERROR, in_name );

CHECK_READ( gzread( zstream, &node_count, sizeof( int ) ), sizeof(int) );

CHECK_READ( gzread( zstream, &child_list_size, sizeof( int ) ), sizeof( int ) );

child_count = (short *) safe_malloc( node_count * sizeof( short ) );
child = (short *) safe_malloc( child_list_size * sizeof( short ) );

CHECK_READ( gzread( zstream, child_count, sizeof( short ) * node_count ), sizeof( short ) * node_count );

CHECK_READ( gzread( zstream, child, sizeof( short ) * child_list_size ), sizeof( short ) * child_list_size );

black_score = (short *) safe_malloc( node_count * sizeof( short ) );
white_score = (short *) safe_malloc( node_count * sizeof( short ) );
alt_move = (short *) safe_malloc( node_count * sizeof( short ) );
alt_score = (short *) safe_malloc( node_count * sizeof( short ) );
flags =
(unsigned short *) safe_malloc( node_count * sizeof( unsigned short ) );

for ( i = 0; i < node_count; i++ ) {
CHECK_READ( gzread( zstream, &black_score[i], sizeof( short ) ), sizeof( short ) );
CHECK_READ( gzread( zstream, &white_score[i], sizeof( short ) ), sizeof( short ) );
}

CHECK_READ( gzread( zstream, alt_move, sizeof( short ) * node_count ), sizeof( short ) * node_count );

CHECK_READ( gzread( zstream, alt_score, sizeof( short ) * node_count ), sizeof( short ) * node_count );

CHECK_READ( gzread( zstream, flags, sizeof( unsigned short ) * node_count ), sizeof( unsigned short ) * node_count );

gzclose( zstream );
#undef CHECK_READ

/* Traverse the tree described by the database and create the .bin file */

stream = fopen( out_name, "wb" );
if ( stream == NULL )
fatal_error( "%s '%s'\n", DB_WRITE_ERROR, out_name );

toggle_experimental( 0 );
game_init( NULL, &dummy );
toggle_midgame_hash_usage( TRUE, TRUE );
toggle_abort_check( FALSE );
toggle_midgame_abort_check( FALSE );

magic = BOOK_MAGIC1;
fwrite( &magic, sizeof( short ), 1, stream);
magic = BOOK_MAGIC2;
fwrite( &magic, sizeof( short ), 1, stream);

fwrite( &node_count, sizeof( int ), 1, stream);

node_index = 0;
child_index = 0;
do_uncompress( 0, stream, &node_index, &child_index, child_count, child,
black_score, white_score, alt_move, alt_score, flags );

fclose( stream );

/* Free tables */

free( child_count );
free( child );

free( black_score );
free( white_score );
free( alt_move );
free( alt_score );
free( flags );

time( &stop_time );

#ifdef TEXT_BASED
printf( "done (took %d s)\n", (int) (stop_time - start_time) );
puts( "" );
#endif
}




/*
Expand Down
4 changes: 3 additions & 1 deletion porting.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#ifndef PORTING_H
#define PORTING_H


#ifdef ANDROID
extern char android_files_dir[];
#endif

#endif