예제 #1
0
  public static void main(String[] pArgs) {
    if (pArgs.length < 3) {
      System.out.println("usage: java Client host port boardnum");
      return;
    }

    try {
      Socket lSocket = new Socket(pArgs[0], Integer.parseInt(pArgs[1]));
      PrintWriter lOut = new PrintWriter(lSocket.getOutputStream());
      BufferedReader lIn = new BufferedReader(new InputStreamReader(lSocket.getInputStream()));

      lOut.println(pArgs[2]);
      lOut.flush();

      String lLine = lIn.readLine();

      // read number of rows
      int lNumRows = Integer.parseInt(lLine);

      // now, we should find a path from the player to any goal

      // we've found our solution
      String lMySol =
          SokobanSolver.findSolution(Matrix.tileMatrixFromBufferedReader(lIn, lNumRows));
      // these formats are also valid:
      // String lMySol="URRUULDLLULLDRRRRLDDRURUDLLUR";
      // String lMySol="0 3 3 0 0 2 1 2 2 0 2 2 1 3 3 3 3 2 1 1 3 0 3 0 1 2 2 0 3";

      // send the solution to the server
      lOut.println(lMySol);
      lOut.flush();

      // read answer from the server
      lLine = lIn.readLine();

      System.out.println(lLine);
    } catch (Throwable t) {
      t.printStackTrace();
    }
  }
  /**
   * Indicates the transform matrix applied to this document.
   *
   * @return Transform matrix.
   */
  protected Matrix getMatrix() {
    // If the matrix has already been computed then just return the cached value.
    if (this.matrix != null) return this.matrix;

    Matrix m = Matrix.IDENTITY;

    if (this.heading != null)
      m = m.multiply(Matrix.fromRotationZ(Angle.POS360.subtract(this.heading)));

    if (this.pitch != null) m = m.multiply(Matrix.fromRotationX(this.pitch));

    if (this.roll != null) m = m.multiply(Matrix.fromRotationY(this.roll));

    // Apply scaling factor to convert file units to meters.
    double scale = this.getScale();
    m = m.multiply(Matrix.fromScale(scale));

    if (this.modelScale != null) m = m.multiply(Matrix.fromScale(this.modelScale));

    this.matrix = m;
    return m;
  }