示例#1
0
  /**
   * Paints the graphic component
   *
   * @param g Graphic component
   */
  public void paint(Graphics g) {
    if (environment != null) {
      Sudoku env = (Sudoku) environment;
      Board board = env.getBoard();

      int n = SudokuLanguage.DIGITS;
      int sqrt_n = (int) (Math.sqrt(n) + 0.1);

      g.setColor(Color.lightGray);
      Font font = g.getFont();
      g.setFont(new Font(font.getName(), font.getStyle(), 20));
      for (int i = 0; i < n; i++) {
        int ci = getCanvasValue(i);
        if (i % sqrt_n == 0) {
          g.drawLine(ci, DRAW_AREA_SIZE + MARGIN, ci, MARGIN);
          g.drawLine(DRAW_AREA_SIZE + MARGIN, ci, MARGIN, ci);
        }

        for (int j = 0; j < n; j++) {
          int cj = getCanvasValue(j);
          int value = board.get(i, j);
          if (value > 0) {
            g.setColor(Color.black);
            g.drawString("" + value, cj + CELL_SIZE / 5, ci + CELL_SIZE);
            g.setColor(Color.lightGray);
          }
        }
      }
      g.drawLine(DRAW_AREA_SIZE + MARGIN, DRAW_AREA_SIZE + MARGIN, DRAW_AREA_SIZE + MARGIN, MARGIN);
      g.drawLine(DRAW_AREA_SIZE + MARGIN, DRAW_AREA_SIZE + MARGIN, MARGIN, DRAW_AREA_SIZE + MARGIN);
    }
  }
 /*constructor called by world canvas */
 public WorldTemperaturesOneStepPheromoneImpl(Vector<Agent> agents, int w, int h) {
   super(agents, w, h);
   width = w;
   System.out.println("w" + w);
   height = h;
   GaussianGenerator g = new GaussianGenerator(0.5, 0.4);
   System.out.println("h" + h);
   states = new StateProps[w][h];
   for (int i = 0; i < width; i++) {
     for (int j = 0; j < height; j++) {
       states[i][j] = new StateProps((float) 0.5, (float) Math.abs(g.next()));
     }
   }
   seconds = 0;
   ds = new GenerateIntegerDataSet(100);
   int n = this.getAgents().size();
   seekers = 0;
   carriers = 0;
 }