Exemple #1
0
 @Override
 public boolean isKeep(TridentTuple tuple) {
   GameState gameState = (GameState) tuple.get(0);
   boolean keep = (gameState.getBoard().isEndState());
   if (keep) {
     LOG.info("END GAME [" + gameState + "]");
   }
   return keep;
 }
  @Override
  public void execute(TridentTuple tuple, TridentCollector collector) {
    GameState gameState = (GameState) tuple.get(0);
    Board currentBoard = gameState.getBoard();
    List<Board> history = new ArrayList<Board>();
    history.addAll(gameState.getHistory());
    history.add(currentBoard);

    if (!currentBoard.isEndState()) {
      String nextPlayer = Player.next(gameState.getPlayer());
      List<Board> boards = gameState.getBoard().nextBoards(nextPlayer);
      Log.debug(
          "Generated [" + boards.size() + "] children boards for [" + gameState.toString() + "]");
      for (Board b : boards) {
        GameState newGameState = new GameState(b, history, nextPlayer);
        List<Object> values = new ArrayList<Object>();
        values.add(newGameState);
        collector.emit(values);
      }
    } else {
      Log.debug("End game found! [" + currentBoard + "]");
    }
  }