Skip to content

Commit

Permalink
add edaxBoardGetSquareColor (#454)
Browse files Browse the repository at this point in the history
* update libedax version

* dart run ffigen --config ffigen.yaml --verbose severe && dart format --fix .

* edaxBoardGetSquareColor

* [Scheduled] `dart pub upgrade && dart pub upgrade --major-versions` (#455)

Co-authored-by: sensuikan1973 <sensuikan1973@users.noreply.github.com>

* fix typo

---------

Co-authored-by: sensuikan1973 <sensuikan1973@users.noreply.github.com>
  • Loading branch information
sensuikan1973 and sensuikan1973 authored Nov 4, 2023
1 parent dea52f0 commit 290df5e
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .libedax-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
dcaf1b19212c07f874378f2f9188a4b374519018
8ecaf4019b336fa357c79397451236bac9af2908
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ packages:
path: ".."
relative: true
source: path
version: "7.13.0"
version: "7.15.0"
lints:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions ffigen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,6 @@ functions:
- 'edax_version'
- 'edax_vmirror'
- 'edax_board_is_pass'
- 'edax_board_get_square_color'
- 'libedax_initialize'
- 'libedax_terminate'
24 changes: 20 additions & 4 deletions lib/src/ffi/bindings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,22 @@ class LibEdaxBindings {

set daylight(int value) => _daylight.value = value;

int edax_board_get_square_color(
ffi.Pointer<Board> arg0,
int arg1,
) {
return _edax_board_get_square_color(
arg0,
arg1,
);
}

late final _edax_board_get_square_colorPtr = _lookup<
ffi.NativeFunction<ffi.Int Function(ffi.Pointer<Board>, ffi.Int)>>(
'edax_board_get_square_color');
late final _edax_board_get_square_color = _edax_board_get_square_colorPtr
.asFunction<int Function(ffi.Pointer<Board>, int)>();

int edax_board_is_pass(
ffi.Pointer<Board> arg0,
) {
Expand Down Expand Up @@ -1550,11 +1566,11 @@ class LibEdaxBindings {
ffi.Pointer<ffi.NativeFunction<ffi.LongLong Function()>> value) =>
_time_clock.value = value;

late final ffi.Pointer<ffi.Long> _timezone = _lookup<ffi.Long>('timezone');
late final ffi.Pointer<ffi.Long> _timezone1 = _lookup<ffi.Long>('timezone');

int get timezone => _timezone.value;
int get timezone1 => _timezone1.value;

set timezone(int value) => _timezone.value = value;
set timezone1(int value) => _timezone1.value = value;

late final ffi.Pointer<ffi.Pointer<ffi.Pointer<ffi.Char>>> _tzname =
_lookup<ffi.Pointer<ffi.Pointer<ffi.Char>>>('tzname');
Expand Down Expand Up @@ -9779,7 +9795,7 @@ final class timeval64 extends ffi.Struct {
external int tv_usec;
}

final class timezone1 extends ffi.Struct {
final class timezone extends ffi.Struct {
@ffi.Int()
external int tz_minuteswest;

Expand Down
12 changes: 12 additions & 0 deletions lib/src/libedax.dart
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ class LibEdax {
void edaxBookVerbose(final int verbosity) =>
_bindings.edax_book_verbose(verbosity);

/// Check if current player should pass.
bool edaxBoardIsPass(final Board board) {
final dstB = calloc<bindings.Board>();
dstB.ref.player = board.player;
Expand All @@ -468,4 +469,15 @@ class LibEdax {
calloc.free(dstB);
return result == 1;
}

/// Get square color.
/// 0 = player, 1 = opponent, 2 = empty.
int edaxBoardGetSquareColor(final Board board, final int x) {
final dstB = calloc<bindings.Board>();
dstB.ref.player = board.player;
dstB.ref.opponent = board.opponent;
final result = _bindings.edax_board_get_square_color(dstB, x);
calloc.free(dstB);
return result;
}
}
21 changes: 21 additions & 0 deletions test/edax_command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,27 @@ void main() {
expect(edax.edaxBoardIsPass(edax.edaxGetBoard()), true);
edax.libedaxTerminate();
});

test('edaxBoardGetSquareColor', () {
const initParams = ['', '-book-file', _testBookFile];
final edax = LibEdax()..libedaxInitialize(initParams);
sleep(const Duration(seconds: 1));

const opening = 'f5f6';
edax
..edaxInit()
..edaxPlay(opening);
final board = edax.edaxGetBoard();
final lastMove = edax.edaxGetLastMove();
expect(lastMove.x, 45);
expect(edax.edaxBoardGetSquareColor(board, lastMove.x), 1); // f6
expect(edax.edaxBoardGetSquareColor(board, 37), 0); // f5
expect(edax.edaxBoardGetSquareColor(board, 36), 1); // e5
expect(edax.edaxBoardGetSquareColor(board, 35), 0); // d5
expect(edax.edaxBoardGetSquareColor(board, 28), 0); // e4
expect(edax.edaxBoardGetSquareColor(board, 27), 1); // d4
edax.libedaxTerminate();
});
});

group('util command', () {
Expand Down

0 comments on commit 290df5e

Please sign in to comment.