Skip to content

Commit

Permalink
revert BestpathCount
Browse files Browse the repository at this point in the history
  • Loading branch information
sensuikan1973 committed Nov 11, 2023
1 parent 3fd050c commit df05ec4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
12 changes: 9 additions & 3 deletions lib/board/pedax_board.dart
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,15 @@ class PedaxBoardState extends State<PedaxBoard> {

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<BoardNotifier, int>((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({
Expand Down
17 changes: 5 additions & 12 deletions lib/engine/api/count_bestpath.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class CountBestpathResponse implements ResponseSchema<CountBestpathRequest> {
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;
}

Expand All @@ -53,20 +56,10 @@ Stream<CountBestpathResponse> 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,
);
Expand Down

0 comments on commit df05ec4

Please sign in to comment.