示例#1
0
  private void toString(ObjToIntMap printIds, StringBuffer sb) {
    if (Token.printTrees) {
      sb.append(Token.name(type));
      if (this instanceof StringNode) {
        sb.append(' ');
        sb.append(getString());
      } else if (this instanceof ScriptOrFnNode) {
        ScriptOrFnNode sof = (ScriptOrFnNode) this;
        if (this instanceof FunctionNode) {
          FunctionNode fn = (FunctionNode) this;
          sb.append(' ');
          sb.append(fn.getFunctionName());
        }
        sb.append(" [source name: ");
        sb.append(sof.getSourceName());
        sb.append("] [encoded source length: ");
        sb.append(sof.getEncodedSourceEnd() - sof.getEncodedSourceStart());
        sb.append("] [base line: ");
        sb.append(sof.getBaseLineno());
        sb.append("] [end line: ");
        sb.append(sof.getEndLineno());
        sb.append(']');
      } else if (this instanceof Jump) {
        Jump jump = (Jump) this;
        if (type == Token.BREAK || type == Token.CONTINUE) {
          sb.append(" [label: ");
          appendPrintId(jump.getJumpStatement(), printIds, sb);
          sb.append(']');
        } else if (type == Token.TRY) {
          Node catchNode = jump.target;
          Node finallyTarget = jump.getFinally();
          if (catchNode != null) {
            sb.append(" [catch: ");
            appendPrintId(catchNode, printIds, sb);
            sb.append(']');
          }
          if (finallyTarget != null) {
            sb.append(" [finally: ");
            appendPrintId(finallyTarget, printIds, sb);
            sb.append(']');
          }
        } else if (type == Token.LABEL || type == Token.LOOP || type == Token.SWITCH) {
          sb.append(" [break: ");
          appendPrintId(jump.target, printIds, sb);
          sb.append(']');
          if (type == Token.LOOP) {
            sb.append(" [continue: ");
            appendPrintId(jump.getContinue(), printIds, sb);
            sb.append(']');
          }
        } else {
          sb.append(" [target: ");
          appendPrintId(jump.target, printIds, sb);
          sb.append(']');
        }
      } else if (type == Token.NUMBER) {
        sb.append(' ');
        sb.append(getDouble());
      } else if (type == Token.TARGET) {
        sb.append(' ');
        appendPrintId(this, printIds, sb);
      }
      if (lineno != -1) {
        sb.append(' ');
        sb.append(lineno);
      }

      for (PropListItem x = propListHead; x != null; x = x.next) {
        int type = x.type;
        sb.append(" [");
        sb.append(propToString(type));
        sb.append(": ");
        String value;
        switch (type) {
          case TARGETBLOCK_PROP: // can't add this as it recurses
            value = "target block property";
            break;
          case LOCAL_BLOCK_PROP: // can't add this as it is dull
            value = "last local block";
            break;
          case ISNUMBER_PROP:
            switch (x.intValue) {
              case BOTH:
                value = "both";
                break;
              case RIGHT:
                value = "right";
                break;
              case LEFT:
                value = "left";
                break;
              default:
                throw Kit.codeBug();
            }
            break;
          case SPECIALCALL_PROP:
            switch (x.intValue) {
              case SPECIALCALL_EVAL:
                value = "eval";
                break;
              case SPECIALCALL_WITH:
                value = "with";
                break;
              default:
                // NON_SPECIALCALL should not be stored
                throw Kit.codeBug();
            }
            break;
          default:
            Object obj = x.objectValue;
            if (obj != null) {
              value = obj.toString();
            } else {
              value = String.valueOf(x.intValue);
            }
            break;
        }
        sb.append(value);
        sb.append(']');
      }
    }
  }
  /**
   * Do the Jump, removing the piece from x1, y1 and setting the piece in x2, y2. Remove the piece
   * from captureX, captureY as well. If the piece is now on their "King's Row", then promote the
   * piece should be promoted to a King
   */
  public void execute(final Jump jump) {
    // CHECK IF ALL OF THEM ON BOARD
    if (isOnBoard(jump.getX1(), jump.getX2())
        && isOnBoard(jump.getY1(), jump.getY2())
        && isOnBoard(jump.getCaptureX(), jump.getCaptureY())) {
      // check if landing square is empty
      if (isEmptySquare(jump.getY1(), jump.getY2())) {
        Piece piece = getPiece(jump.getY1(), jump.getX1());
        // check if capture piece is enemy color
        if (getPiece(jump.getCaptureY(), jump.getCaptureX()).isEnemyColor(piece.getColor())) {

          if (Piece.WHITE_MAN.equals(piece)) {
            if (jump.getY2() == 7) {
              piece = Piece.WHITE_KING;
            }
          } else if (Piece.RED_MAN.equals(piece)) {
            if (jump.getY2() == 0) {
              piece = Piece.RED_KING;
            }
          }

          setPiece(jump.getY2(), jump.getX2(), piece);
          removePiece(jump.getCaptureY(), jump.getCaptureX());
          removePiece(jump.getY1(), jump.getX1());
        }
      }
    }
  }