diff --git a/lib/board/pedax_board.dart b/lib/board/pedax_board.dart index 65b01f1bc..2ee816137 100644 --- a/lib/board/pedax_board.dart +++ b/lib/board/pedax_board.dart @@ -212,9 +212,15 @@ class PedaxBoardState extends State { int? _bestpathCount(final int color, final CountBestpathResultWithMove? countBestpathResultWithMove) { if (countBestpathResultWithMove == null) return null; - return countBestpathResultWithMove.countBestpathList.playerColor == color - ? countBestpathResultWithMove.countBestpathList.position.nPlayerBestpaths - : countBestpathResultWithMove.countBestpathList.position.nOpponentBestpaths; + final currentColor = context.select((final notifier) => notifier.value.currentColor); + final isYourTurn = currentColor == color; + + /// NOTE: + /// Why "when isYourTurn == true, show opponent value" ? + /// -> See: [CountBestpathResponse] class in lib/engine/api/count_bestpath.dart. + return isYourTurn + ? countBestpathResultWithMove.countBestpathList.position.nOpponentBestpaths + : countBestpathResultWithMove.countBestpathList.position.nPlayerBestpaths; } Color? _scoreColor({ diff --git a/lib/engine/api/count_bestpath.dart b/lib/engine/api/count_bestpath.dart index 943e11e8e..1123aa285 100644 --- a/lib/engine/api/count_bestpath.dart +++ b/lib/engine/api/count_bestpath.dart @@ -32,6 +32,9 @@ class CountBestpathResponse implements ResponseSchema { final CountBestpathRequest request; final String rootMove; + /// NOTE: + /// The color of the position in this result is the opposite of that in the request. + /// It's due to executeCountBestpath algorism and book/position structure. final CountBestpathResult countBestpathResult; } @@ -53,20 +56,10 @@ Stream executeCountBestpath( edax.edaxBookStopCountBestpath(); final moves = request.movesAtRequest + move.moveString; final bookMoveListWithPosition = edax.edaxGetBookMoveWithPositionByMoves(moves); - final board = bookMoveListWithPosition.position.board; - - final symetryMoveX = symetryMove(move.x, bookMoveListWithPosition.symetry); - final lastMoveSquarePlayer = edax.edaxBoardGetSquareColor(board, symetryMoveX); - int positionPlayerColor = -1; // empty. - if (lastMoveSquarePlayer == 0) { - positionPlayerColor = edax.edaxGetCurrentPlayer(); - } else if (lastMoveSquarePlayer == 1) { - positionPlayerColor = edax.edaxGetOpponentPlayer(); - } final result = edax.edaxBookCountBoardBestpath( - board, - playerColor: positionPlayerColor, + bookMoveListWithPosition.position.board, + playerColor: edax.edaxGetCurrentPlayer(), playerLowerLimit: request.playerLowerLimit, opponentLowerLimit: request.opponentLowerLimit, );