Exemplo n.º 1
0
 public short[] getNextShortMoves() {
   short[] moves = new short[m_moves.getNumOfNextMoves(m_cur)];
   for (int i = 0; i < moves.length; i++) {
     moves[i] = m_moves.getMove(m_moves.goForward(m_cur, i));
   }
   return moves;
 }
Exemplo n.º 2
0
 public int getNumOfPlies() {
   int num = 0;
   int index = 0;
   while (m_moves.hasNextMove(index)) {
     index = m_moves.goForward(index);
     num++;
   }
   return num;
 }
Exemplo n.º 3
0
 public void deleteCurrentLine(boolean silent) {
   int index = m_cur;
   if (goBack(silent)) {
     m_moves.deleteCurrentLine(index);
     fireMoveModelChanged();
   }
 }
Exemplo n.º 4
0
  public void notifyMoveUndone(ImmutablePosition position) {
    if (DEBUG) System.out.println("ChGame: move taken back in position");

    if (!m_ignoreNotifications) {
      m_cur = m_moves.goBack(m_cur, true);
    }
  }
Exemplo n.º 5
0
 public Move getNextMove(int whichLine) {
   short shortMove = m_moves.getMove(m_moves.goForward(m_cur, whichLine));
   if (shortMove == GameMoveModel.NO_MOVE) return null; // =====>
   try {
     m_position.setNotifyListeners(false);
     m_position.doMove(shortMove);
     //            ChMove move = m_position.getLastMove(shortMove);
     Move move = m_position.getLastMove();
     m_position.undoMove();
     m_position.setNotifyListeners(true);
     return move;
   } catch (IllegalMoveException ex) {
     ex.printStackTrace();
     return null;
   }
 }
Exemplo n.º 6
0
 private int getNumOfPliesToRoot(int node) {
   int plies = 0;
   while (node > 0) {
     node = m_moves.goBack(node, true);
     plies++;
   }
   return plies;
 }
Exemplo n.º 7
0
  public void notifyMoveDone(ImmutablePosition position, short move) {
    if (DEBUG) System.out.println("ChGame: move made in position " + move);

    if (!m_ignoreNotifications) {
      if (!m_alwaysAddLine) {
        short[] moves = getNextShortMoves();
        for (int i = 0; i < moves.length; i++) {
          if (moves[i] == move) {
            m_cur = m_moves.goForward(m_cur, i);
            return; // =====>
          }
        }
      }
      m_cur = m_moves.appendAsRightMostLine(m_cur, move);
      fireMoveModelChanged();
    }
  }
Exemplo n.º 8
0
 public Move[] getNextMoves() {
   m_position.setNotifyListeners(false);
   Move[] moves = new Move[m_moves.getNumOfNextMoves(m_cur)];
   for (int i = 0; i < moves.length; i++) {
     short move = m_moves.getMove(m_moves.goForward(m_cur, i));
     try {
       m_position.doMove(move);
       //                moves[i] = m_position.getLastMove(move);
       moves[i] = m_position.getLastMove();
       m_position.undoMove();
     } catch (IllegalMoveException ex) {
       m_moves.write(System.out);
       System.out.println("cur = " + m_cur + " move=" + GameMoveModel.valueToString(move));
       ex.printStackTrace();
     }
   }
   m_position.setNotifyListeners(true);
   return moves;
 }
Exemplo n.º 9
0
  public Move[] getMainLine() {
    int num = 0;
    int index = m_cur;
    while (m_moves.hasNextMove(index)) {
      index = m_moves.goForward(index);
      num++;
    }

    Move[] moves = new Move[num];
    for (int i = 0; i < num; i++) {
      moves[i] = goForwardAndGetMove(true);
    }

    m_position.setNotifyListeners(false);
    for (int i = 0; i < moves.length; i++) m_position.undoMove();
    m_position.setNotifyListeners(true);

    return moves;
  }
Exemplo n.º 10
0
 private int[] getNodesToRoot(int node) {
   int[] nodes;
   int i = 0;
   if (m_moves.getMove(node) != GameMoveModel.NO_MOVE) {
     nodes = new int[getNumOfPliesToRoot(node) + 1];
     nodes[0] = node;
     i = 1;
   } else {
     nodes =
         new int
             [getNumOfPliesToRoot(
                 node)]; // if we stand on a line end, don't include node in nodes to root
     i = 0;
   }
   for (; i < nodes.length; i++) {
     node = m_moves.goBack(node, true);
     nodes[i] = node;
   }
   return nodes;
 }
Exemplo n.º 11
0
  private boolean goForward(int whichLine, boolean silent) {
    if (DEBUG) System.out.println("goForward " + whichLine);

    int index = m_moves.goForward(m_cur, whichLine);
    short shortMove = m_moves.getMove(index);
    if (DEBUG) System.out.println("  move = " + Move.getString(shortMove));
    if (shortMove != GameMoveModel.NO_MOVE) {
      try {
        m_cur = index;
        m_ignoreNotifications = true;
        if (silent) m_position.setNotifyListeners(false);
        m_position.doMove(shortMove);
        if (silent) m_position.setNotifyListeners(true);
        m_ignoreNotifications = false;
        return true;
      } catch (IllegalMoveException ex) {
        ex.printStackTrace();
      }
    } else {
      //            new Exception("Forward at end of line").printStackTrace();
    }
    return false;
  }
Exemplo n.º 12
0
  public void gotoNode(int node, boolean silent) {
    int[] nodeNodes = getNodesToRoot(node);

    gotoStart(silent);
    for (int i = nodeNodes.length - 2; i >= 0; i--) {
      int nextMoveIndex = 0;
      for (int j = 1; j < getNumOfNextMoves(); j++) {
        if (m_moves.goForward(m_cur, j) == nodeNodes[i]) {
          nextMoveIndex = j;
          break;
        }
      }
      goForward(nextMoveIndex, silent);
    }
    m_cur = node; // now that we have made all the moves, set cur to node
  }
Exemplo n.º 13
0
  private boolean goBackInLine(boolean silent) {
    if (DEBUG) System.out.println("goBackInLine");

    int index = m_moves.goBack(m_cur, false);
    if (index != -1) {
      m_cur =
          index; // needs to be set before undoing the move to allow listeners to check for curNode
      m_ignoreNotifications = true;
      if (silent) m_position.setNotifyListeners(false);
      m_position.undoMove();
      if (silent) m_position.setNotifyListeners(true);
      m_ignoreNotifications = false;
      return true;
    } else {
      return false;
    }
  }
Exemplo n.º 14
0
  private boolean goBack(boolean silent) {
    if (DEBUG) System.out.println("goBack");

    int index = m_moves.goBack(m_cur, true);
    if (index != -1) {
      //        if (m_position.canUndoMove()) {  // do not rely on position since in silent mode it
      // is not updated
      //            m_cur = m_moves.goBack(m_cur, true);
      m_cur = index;
      m_ignoreNotifications = true;
      if (silent) m_position.setNotifyListeners(false);
      m_position.undoMove();
      if (silent) m_position.setNotifyListeners(true);
      m_ignoreNotifications = false;
      return true;
    } else {
      return false;
    }
  }
Exemplo n.º 15
0
 public short getNextShortMove(int whichLine) {
   return m_moves.getMove(m_moves.goForward(m_cur, whichLine));
 }
Exemplo n.º 16
0
 public boolean hasNag(short nag) {
   return m_moves.hasNag(m_cur, nag);
 }
Exemplo n.º 17
0
 public short[] getNags() {
   return m_cur == 0 ? null : m_moves.getNags(m_cur);
 }
Exemplo n.º 18
0
 public void addNag(short nag) {
   m_moves.addNag(m_cur, nag);
   fireMoveModelChanged();
 }
Exemplo n.º 19
0
 public void removeNag(short nag) {
   if (m_moves.removeNag(m_cur, nag)) fireMoveModelChanged();
 }
Exemplo n.º 20
0
 public String getComment() {
   return m_moves.getComment(m_cur);
 }
Exemplo n.º 21
0
 public void setComment(String comment) {
   if (m_moves.setComment(m_cur, comment)) fireMoveModelChanged();
 }
Exemplo n.º 22
0
 public int getNumOfNextMoves() {
   return m_moves.getNumOfNextMoves(m_cur);
 }
Exemplo n.º 23
0
 public void removeComment() {
   if (m_moves.removeComment(m_cur)) fireMoveModelChanged();
 }
Exemplo n.º 24
0
 public int getTotalNumOfPlies() {
   return m_moves.getTotalNumOfPlies();
 }
Exemplo n.º 25
0
 public void pack() {
   m_cur = m_moves.pack(m_cur); // TODO pack headers?
 }
Exemplo n.º 26
0
 public boolean hasNextMove() {
   return m_moves.hasNextMove(m_cur);
 }