@Override
 public boolean handleMessageFromServer(Enum messageType, ByteBuf input) throws IOException {
   if (super.handleMessageFromServer(messageType, input)) {
     return true;
   }
   if (messageType.equals(factorization.net.StandardMessageType.Description)) {
     readStateChange(input);
     front = SpaceUtil.getOrientation(input.readByte());
     setRotation(input.readByte());
     parts.clear();
     ArrayList<Object> args = new ArrayList();
     while (true) {
       try {
         parts.add(new ClayLump().read(input));
       } catch (IOException e) {
         break;
       }
     }
     shouldRenderTesr = getState() == ClayState.WET;
   } else if (messageType.equals(GreenwareMessage.SculptMove)) {
     updateLump(input.readInt(), new ClayLump().read(input));
   } else if (messageType.equals(GreenwareMessage.SculptNew)) {
     addLump();
   } else if (messageType.equals(GreenwareMessage.SculptRemove)) {
     removeLump(input.readInt());
   } else if (messageType.equals(GreenwareMessage.SculptState)) {
     readStateChange(input);
   } else {
     return false;
   }
   cache_dirty = true;
   if (renderEfficient()) {
     getCoord().redraw();
   }
   return true;
 }
Esempio n. 2
0
  @Override
  public boolean validMove() {

    List<Board.Areas> areas_of_interest = new ArrayList<Areas>();
    areas_of_interest.add(Board.Areas.ROW);
    areas_of_interest.add(Board.Areas.COL);
    areas_of_interest.add(Board.Areas.BOX);
    /*
     * for all areas defined in Board.Areas
     */
    for (Enum<Board.Areas> area : areas_of_interest) {
      /*
       * improves performance based on what area we are looking at.
       */
      int vcondition = Board.DIMENSION;
      int hcondition = Board.DIMENSION;
      int inc = 1;
      if (area.equals(Board.Areas.ROW)) {
        vcondition = 1;
      }
      if (area.equals(Board.Areas.COL)) {
        hcondition = 1;
      }
      if (area.equals(Board.Areas.BOX)) {
        inc = Board.TILES_PER_BOX;
      }
      /*
       * run over all possible Coords
       */
      for (int h = 0; h < hcondition; h += inc) {
        for (int v = 0; v < vcondition; v += inc) {
          Coord current_coord = new Coord(v, h);

          Options optionschecklist = new Options();
          List<Integer> valuechecklist = new ArrayList<Integer>();
          for (Coord rowcoord : getAreaAt(area, current_coord).getCoords()) {
            Tile tile = getTileAt(rowcoord);
            if (tile.getValue() != 0) {
              if (!valuechecklist.contains(tile.getValue())) {
                valuechecklist.add(tile.getValue());
                optionschecklist.removeOption(tile.getValue());
              } else {
                // System.out
                // .println("INVALID MOVE - 2X VALUES IN SAME HROW - VALUE "
                // + tile.getValue() + " AT " + rowcoord);
                return false;
              }
            }
            Options to = tile.getOptions();
            optionschecklist.removeOptions(to.copyList());
          }
          if (!optionschecklist.copyList().isEmpty()) {
            // System.out
            // .println("INVALID MOVE - THESE OPTIONS ARE NO LONGER REACHABLE: "
            // + optionschecklist + " AT " + bc);
            return false;
          }
        }
      }
    }

    return true;
  }