Skip to content

Commit

Permalink
Support problems where White moves first
Browse files Browse the repository at this point in the history
  • Loading branch information
Tellmarch committed Apr 26, 2024
1 parent d26af67 commit b51a890
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.google.web.bindery.event.shared.EventBus;
import com.google.web.bindery.event.shared.binder.EventBinder;
import com.google.web.bindery.event.shared.binder.EventHandler;
import com.playshogi.library.shogi.models.Player;
import com.playshogi.library.shogi.models.formats.usf.UsfMoveConverter;
import com.playshogi.library.shogi.models.moves.ShogiMove;
import com.playshogi.library.shogi.models.position.ReadOnlyShogiPosition;
Expand All @@ -27,7 +26,6 @@ interface MyEventBinder extends EventBinder<NavigationController> {
private final String activityId;
private final NavigatorConfiguration navigatorConfiguration;
private final GameNavigation gameNavigation = new GameNavigation(new ShogiRulesEngine(), new GameTree());
private final ShogiRulesEngine shogiRulesEngine = new ShogiRulesEngine();

private EventBus eventBus;

Expand Down Expand Up @@ -103,7 +101,8 @@ public void onMovePlayed(final MovePlayedEvent movePlayedEvent) {
eventBus.fireEvent(new EndOfVariationReachedEvent(gameNavigation.getPosition(),
gameNavigation.getCurrentNode().isNew(), gameNavigation.getCurrentNode().isWrongAnswer()));
fireNodeChanged();
} else if (gameNavigation.getPosition().getPlayerToMove() == Player.WHITE && navigatorConfiguration.isProblemMode()) {
} else if (navigatorConfiguration.isProblemMode() &&
gameNavigation.getPosition().getPlayerToMove() != gameNavigation.getGameTree().getInitialPosition().getPlayerToMove()) {
gameNavigation.moveForward();
if (gameNavigation.isEndOfVariation()) {
eventBus.fireEvent(new EndOfVariationReachedEvent(gameNavigation.getPosition(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@
import com.google.web.bindery.event.shared.EventBus;
import com.google.web.bindery.event.shared.binder.EventBinder;
import com.google.web.bindery.event.shared.binder.EventHandler;
import com.playshogi.library.shogi.models.Player;
import com.playshogi.library.shogi.models.position.ShogiPosition;
import com.playshogi.website.gwt.client.SessionInformation;
import com.playshogi.website.gwt.client.controller.NavigationController;
import com.playshogi.website.gwt.client.events.collections.ListCollectionProblemsEvent;
import com.playshogi.website.gwt.client.events.gametree.GameTreeChangedEvent;
import com.playshogi.website.gwt.client.events.gametree.PositionChangedEvent;
import com.playshogi.website.gwt.client.events.kifu.FlipBoardEvent;
import com.playshogi.website.gwt.client.events.puzzles.*;
import com.playshogi.website.gwt.client.util.ElementWidget;
import com.playshogi.website.gwt.client.widget.board.BoardButtons;
Expand Down Expand Up @@ -230,7 +233,7 @@ void onActivityTimerEvent(final ActivityTimerEvent event) {

@EventHandler
public void onPositionChanged(final PositionChangedEvent event) {
GWT.log("ViewKifuView: handle PositionChangedEvent");
GWT.log("ProblemsView: handle PositionChangedEvent");

Optional<String> comment = navigationController.getGameNavigation().getCurrentComment();
if (comment.isPresent()) {
Expand All @@ -242,4 +245,19 @@ public void onPositionChanged(final PositionChangedEvent event) {
}
}

@EventHandler
public void onGameTreeChanged(final GameTreeChangedEvent gameTreeChangedEvent) {
GWT.log("ProblemsView : Handling game tree changed event - move " + gameTreeChangedEvent.getGoToMove());

if (gameTreeChangedEvent.getGameTree().getInitialPosition().getPlayerToMove() == Player.BLACK) {
shogiBoard.getBoardConfiguration().setPlayWhiteMoves(false);
shogiBoard.getBoardConfiguration().setPlayBlackMoves(true);
eventBus.fireEvent(new FlipBoardEvent(false));
} else {
shogiBoard.getBoardConfiguration().setPlayWhiteMoves(true);
shogiBoard.getBoardConfiguration().setPlayBlackMoves(false);
eventBus.fireEvent(new FlipBoardEvent(true));
}

}
}

0 comments on commit b51a890

Please sign in to comment.