calcitem / Sanmill

Sanmill is an open-source, UCI-like Mill/Morris/Merrills/Mühle/Malom (and its variants) program with CUI, Flutter GUI and Qt GUI, sharing and freely distributing the code, tools and data needed to deliver this mill game. We do this because we are convinced that open software and open data are key ingredients to make rapid progress.
https://play.google.com/store/apps/details?id=com.calcitem.sanmill
GNU General Public License v3.0
145 stars 21 forks source link

After calling stopSearching to send stop to the engine, it hangs because Phase is none #197

Open calcitem opened 3 years ago

calcitem commented 3 years ago

Now configured as Humans go first Thinking time is about 6s Maximum depth 14 9 men morris with slash banned point No Flying

I/flutter ( 7333): Game over, @ win, because of GameOverReason.loseReasonlessThanThree
I/flutter ( 7333): Score: 5 : 15 : 0    total: 20
I/flutter ( 7333): 25.0% : 75.0% : 0.0%
I/flutter ( 7333): Searching...
I/flutter ( 7333): posFenStr: position fen ********/********/******** w p p 0 9 0 9 0 0 1
I/flutter ( 7333): send: position fen ********/********/******** w p p 0 9 0 9 0 0 1
D/MillEngine( 7333): [uci] input: position fen ********/********/******** w p p 0 9 0 9 0 0 1
I/flutter ( 7333): Tap on (1, 3) <10>
I/flutter ( 7333): AI is not thinking. AI is to move.
I/flutter ( 7333): Engine to go
I/flutter ( 7333): Searching...
I/flutter ( 7333): send: go
I/flutter ( 7333): posFenStr: position fen ********/********/******** w p p 0 9 0 9 0 0 1
I/flutter ( 7333): send: position fen ********/********/******** w p p 0 9 0 9 0 0 1
D/MillEngine( 7333): [uci] input: go
D/MillEngine( 7333): println: bestmove (2,2)
I/flutter ( 7333): send: go
I/flutter ( 7333): response: bestmove (2,2)
I/flutter ( 7333): Engine response type: move
I/flutter ( 7333): Computer: (2,2)
I/flutter ( 7333): @ to move.
D/MillEngine( 7333): [uci] input: position fen ********/********/******** w p p 0 9 0 9 0 0 1
D/MillEngine( 7333): [uci] input: go
D/MillEngine( 7333): println: bestmove (2,4)
I/flutter ( 7333): Score: 5 : 15 : 0    total: 20
I/flutter ( 7333): 25.0% : 75.0% : 0.0%
I/flutter ( 7333): Searching...
I/flutter ( 7333): send: stop
I/flutter ( 7333): response: bestmove (2,4)
I/flutter ( 7333): Engine response type: move
I/flutter ( 7333): Computer: (2,4)
D/MillEngine( 7333): [uci] input: stop
I/flutter ( 7333): O to move.
I/flutter ( 7333): Score: 5 : 15 : 0    total: 20
I/flutter ( 7333): 25.0% : 75.0% : 0.0%
I/flutter ( 7333): Searching...
I/flutter ( 7333): posFenStr: position fen ********/********/******** w p p 0 9 0 9 0 0 1 moves (2,2) (2,4)
I/flutter ( 7333): send: position fen ********/********/******** w p p 0 9 0 9 0 0 1 moves (2,2) (2,4)
I/flutter ( 7333): posFenStr: position fen ********/********/******** w p p 0 9 0 9 0 0 1 moves (2,2) (2,4)
I/flutter ( 7333): send: position fen ********/********/******** w p p 0 9 0 9 0 0 1 moves (2,2) (2,4)
D/MillEngine( 7333): [uci] input: position fen ********/********/******** w p p 0 9 0 9 0 0 1 moves (2,2) (2,4)
I/flutter ( 7333): send: go
I/flutter ( 7333): send: go
D/MillEngine( 7333): [uci] input: position fen ********/********/******** w p p 0 9 0 9 0 0 1 moves (2,2) (2,4)
D/MillEngine( 7333): [uci] input: go
D/MillEngine( 7333): [uci] input: go
D/MillEngine( 7333): Search depth: 7
D/MillEngine( 7333): println: bestmove (2,8)
D/MillEngine( 7333): Search depth: 7
D/MillEngine( 7333): println: bestmove (2,8)
I/flutter ( 7333): response: bestmove (2,8)
I/flutter ( 7333): Engine response type: move
I/flutter ( 7333): Computer: (2,8)
I/flutter ( 7333): @ to move.
I/flutter ( 7333): Score: 5 : 15 : 0    total: 20
I/flutter ( 7333): 25.0% : 75.0% : 0.0%
I/flutter ( 7333): Searching...
I/flutter ( 7333): posFenStr: position fen ********/********/******** w p p 0 9 0 9 0 0 1 moves (2,2) (2,4) (2,8)
I/flutter ( 7333): send: position fen ********/********/******** w p p 0 9 0 9 0 0 1 moves (2,2) (2,4) (2,8)
D/MillEngine( 7333): [uci] input: position fen ********/********/******** w p p 0 9 0 9 0 0 1 moves (2,2) (2,4) (2,8)
I/flutter ( 7333): send: go
D/MillEngine( 7333): [uci] input: go
I/flutter ( 7333): response: bestmove (2,8)
D/MillEngine( 7333): Search depth: 9
I/flutter ( 7333): Engine response type: move
I/flutter ( 7333): Computer: (2,8)
I/flutter ( 7333): Searching...
I/flutter ( 7333): posFenStr: position fen ********/********/******** w p p 0 9 0 9 0 0 1 moves (2,2) (2,4) (2,8)
I/flutter ( 7333): send: position fen ********/********/******** w p p 0 9 0 9 0 0 1 moves (2,2) (2,4) (2,8)
I/flutter ( 7333): send: go
D/MillEngine( 7333): [uci] input: position fen ********/********/******** w p p 0 9 0 9 0 0 1 moves (2,2) (2,4) (2,8)
D/MillEngine( 7333): generate(): action = 0
D/MillEngine( 7333): [uci] input: go
F/libc    ( 7333): D:/calcitem/source/repos/calcitem/Sanmill/src/movegen.cpp:142: ExtMove *generate(Position &, ExtMove *): assertion "0" failed
E/memtrack( 7333): Couldn't load memtrack module
D/xCrash  ( 7333): xCrash log path: /storage/emulated/0/Android/data/com.calcitem.sanmill/files/xcrash/tombstone_00001621130371126530_3.0.0__com.calcitem.sanmill.native.xcrash, emergency: (null)
D/xCrash  ( 7333): xCrash log files have been written
F/libc    ( 7333): Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 7513 (alcitem.sanmill), pid 7333 (alcitem.sanmill)
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Build fingerprint: 'Android/aosp_redfin/redfin:11/RQ1A.210205.004/eng.calcit.20210324.230917:eng/test-keys'
Revision: 'MP1.0'
ABI: 'arm64'
Timestamp: 2021-05-16 10:02:34+0800
pid: 7333, tid: 7513, name: alcitem.sanmill  >>> com.calcitem.sanmill <<<
uid: 10193
signal 6 (SIGABRT), code -1 (SI_QUEUE), fault addr --------
Abort message: 'D:/calcitem/source/repos/calcitem/Sanmill/src/movegen.cpp:142: ExtMove *generate(Position &, ExtMove *): assertion "0" failed'
    x0  0000000000000000  x1  0000000000001d59  x2  0000000000000006  x3  000000763e6fc910
    x4  0000000000000000  x5  0000000000000000  x6  0000000000000000  x7  0000000000000038
    x8  00000000000000f0  x9  00000078e10ea7e0  x10 ffffff80fffffbdf  x11 0000000000000001
    x12 0000000000000030  x13 0000000000000120  x14 00000078e10eeae4  x15 0000000000000030
    x16 00000078e1182c80  x17 00000078e1164320  x18 00000075b5824000  x19 0000000000001ca5
    x20 0000000000001d59  x21 00000000ffffffff  x22 b4000077004db170  x23 000000763e6fdb38
    x24 0000000000000000  x25 0000000000000002  x26 000000763e6fe000  x27 000000763e6fcd68
    x28 0000000000000011  x29 000000763e6fc990
    lr  00000078e1118148  sp  000000763e6fc8f0  pc  00000078e1118178  pst 0000000000001000
backtrace:
      #00 pc 000000000004e178  /apex/com.android.runtime/lib64/bionic/libc.so (abort+168) (BuildId: 47a9ba0d54d9614053e13adab1207062)
      #01 pc 000000000004e548  /apex/com.android.runtime/lib64/bionic/libc.so (__assert2+36) (BuildId: 47a9ba0d54d9614053e13adab1207062)
      #02 pc 0000000000052a24  /data/app/~~BPwDoQiSutpgt34VLTSxAw==/com.calcitem.sanmill-9lbsy8rFvnVhvr6lIRZcMg==/lib/arm64/libsanmill.so (ExtMove* generate<(GenType)3>(Position&, ExtMove*)+404) (BuildId: bcf5548c255b7c939e4b2fcae34d6976f6f8b080)
      #03 pc 0000000000052afc  /data/app/~~BPwDoQiSutpgt34VLTSxAw==/com.calcitem.sanmill-9lbsy8rFvnVhvr6lIRZcMg==/lib/arm64/libsanmill.so (MovePicker::next_move()+28) (BuildId: bcf5548c255b7c939e4b2fcae34d6976f6f8b080)
      #04 pc 000000000005b494  /data/app/~~BPwDoQiSutpgt34VLTSxAw==/com.calcitem.sanmill-9lbsy8rFvnVhvr6lIRZcMg==/lib/arm64/libsanmill.so (search(Position*, Sanmill::Stack<Position, 128ul>&, signed char, signed char, Value, Value, Move&)+340) (BuildId: bcf5548c255b7c939e4b2fcae34d6976f6f8b080)
      #05 pc 000000000005b618  /data/app/~~BPwDoQiSutpgt34VLTSxAw==/com.calcitem.sanmill-9lbsy8rFvnVhvr6lIRZcMg==/lib/arm64/libsanmill.so (search(Position*, Sanmill::Stack<Position, 128ul>&, signed char, signed char, Value, Value, Move&)+728) (BuildId: bcf5548c255b7c939e4b2fcae34d6976f6f8b080)
      #06 pc 000000000005b618  /data/app/~~BPwDoQiSutpgt34VLTSxAw==/com.calcitem.sanmill-9lbsy8rFvnVhvr6lIRZcMg==/lib/arm64/libsanmill.so (search(Position*, Sanmill::Stack<Position, 128ul>&, signed char, signed char, Value, Value, Move&)+728) (BuildId: bcf5548c255b7c939e4b2fcae34d6976f6f8b080)
      #07 pc 000000000005b618  /data/app/~~BPwDoQiSutpgt34VLTSxAw==/com.calcitem.sanmill-9lbsy8rFvnVhvr6lIRZcMg==/lib/arm64/libsanmill.so (search(Position*, Sanmill::Stack<Position, 128ul>&, signed char, signed char, Value, Value, Move&)+728) (BuildId: bcf5548c255b7c939e4b2fcae34d6976f6f8b080)
      #08 pc 000000000005b618  /data/app/~~BPwDoQiSutpgt34VLTSxAw==/com.calcitem.sanmill-9lbsy8rFvnVhvr6lIRZcMg==/lib/arm64/libsanmill.so (search(Position*, Sanmill::Stack<Position, 128ul>&, signed char, signed char, Value, Value, Move&)+728) (BuildId: bcf5548c255b7c939e4b2fcae34d6976f6f8b080)
      #09 pc 000000000005b618  /data/app/~~BPwDoQiSutpgt34VLTSxAw==/com.calcitem.sanmill-9lbsy8rFvnVhvr6lIRZcMg==/lib/arm64/libsanmill.so (search(Position*, Sanmill::Stack<Position, 128ul>&, signed char, signed char, Value, Value, Move&)+728) (BuildId: bcf5548c255b7c939e4b2fcae34d6976f6f8b080)
      #10 pc 000000000005b058  /data/app/~~BPwDoQiSutpgt34VLTSxAw==/com.calcitem.sanmill-9lbsy8rFvnVhvr6lIRZcMg==/lib/arm64/libsanmill.so (Thread::search()+820) (BuildId: bcf5548c255b7c939e4b2fcae34d6976f6f8b080)
      #11 pc 000000000005b914  /data/app/~~BPwDoQiSutpgt34VLTSxAw==/com.calcitem.sanmill-9lbsy8rFvnVhvr6lIRZcMg==/lib/arm64/libsanmill.so (Thread::idle_loop()+204) (BuildId: bcf5548c255b7c939e4b2fcae34d6976f6f8b080)
      #12 pc 000000000005dc34  /data/app/~~BPwDoQiSutpgt34VLTSxAw==/com.calcitem.sanmill-9lbsy8rFvnVhvr6lIRZcMg==/lib/arm64/libsanmill.so (void* std::__ndk1::__thread_proxy<std::__ndk1::tuple<std::__ndk1::unique_ptr<std::__ndk1::__thread_struct, std::__ndk1::default_delete<std::__ndk1::__thread_struct> >, void (Thread::*)(), Thread*> >(void*)+64) (BuildId: bcf5548c255b7c939e4b2fcae34d6976f6f8b080)
      #13 pc 00000000000af880  /apex/com.android.runtime/lib64/bionic/libc.so (__pthread_start(void*)+64) (BuildId: 47a9ba0d54d9614053e13adab1207062)
      #14 pc 00000000000500d0  /apex/com.android.runtime/lib64/bionic/libc.so (__start_thread+64) (BuildId: 47a9ba0d54d9614053e13adab1207062)
Lost connection to device.
calcitem commented 3 years ago

场景可能是AI对战刚开始就马上切人机对战然后点击屏幕。依据是前面一段:

I/flutter ( 7333): Game over, @ win, because of GameOverReason.loseReasonlessThanThree
I/flutter ( 7333): Score: 5 : 15 : 0    total: 20
I/flutter ( 7333): 25.0% : 75.0% : 0.0%
I/flutter ( 7333): Waiting for engine's response...
I/flutter ( 7333): posFenStr: position fen ********/********/******** w p p 0 9 0 9 0 0 1
I/flutter ( 7333): send: position fen ********/********/******** w p p 0 9 0 9 0 0 1
D/MillEngine( 7333): [uci] input: position fen ********/********/******** w p p 0 9 0 9 0 0 1
I/flutter ( 7333): Tap on (1, 3) <10>
I/flutter ( 7333): AI is not thinking. AI is to move.
I/flutter ( 7333): Engine to go
I/flutter ( 7333): Waiting for engine's response...
I/flutter ( 7333): send: go
I/flutter ( 7333): posFenStr: position fen ********/********/******** w p p 0 9 0 9 0 0 1
I/flutter ( 7333): send: position fen ********/********/******** w p p 0 9 0 9 0 0 1

因为

  @override
  Future<EngineResponse> search(Position? position) async {
    if (await isThinking()) await stopSearching();

所以发stop

因为

bool MillEngine::isThinking()
{
    return state == EngineState::STATE_THINKING;
}

所以返回真。 向引擎send go 时就回修改状态为thinking:

int MillEngine::send(const char *command)
{
    if (command[0] == 'g' && command[1] == 'o')
        state = EngineState::STATE_THINKING;

    CommandChannel *channel = CommandChannel::getInstance();

    bool success = channel->pushCommand(command);
    if (success) printf(">>> %s\n", command);

    return success ? 0 : -1;
}

但是最近一次打印的是

I/flutter ( 7333): Engine type: EngineType.aiVsAi

奇怪

符合下述条件则改为 ready

    if (strstr(line, "readyok") ||
        strstr(line, "uciok") ||
        strstr(line, "bestmove") ||
        strstr(line, "nobestmove")) {

        state = EngineState::STATE_READY;
    }