welcome: please sign in
location: "解のある配置を作る"の差分
2と6のリビジョン間の差分 (その間の編集: 4回)
2009-12-07 01:04:49時点のリビジョン2
サイズ: 459
編集者: masahiko
コメント:
2009-12-17 07:52:06時点のリビジョン6
サイズ: 453
編集者: masahiko
コメント:
削除された箇所はこのように表示されます。 追加された箇所はこのように表示されます。
行 3: 行 3:
{{{
 int spx, spy;

{{{#!java
 void shokika()
 {
  int x, y, x2, y2, w, cnt;
  ...
  ...
  for (cnt = 0; cnt < (tate*yoko*2); cnt++)
  {
   x = (int)(Math.random() * (yoko-1));
   y = (int)(Math.random() * (tate-1));
   if(Math.random() < 0.5)
   {
    x2 = x;
    y2 = y + 1;
   }
   else
   {
    x2 = x + 1;
    y2 = y;
   }
   w = ban[x][y];
   ban[x][y] = ban[x2][y2];
   ban[x2][y2] = w;
  }
 }
行 6: 行 30:

{{{
  g.setColor(Color.lightGray);
  g.fillRect(spx*haba, spy*haba, haba, haba);
}}}

{{{
  spx = yoko-1;
  spy = tate-1;
  for (cnt = 0; cnt < (tate*yoko*2); ) // 偶数回置換
  {
   x = (int)(Math.random() * yoko);
   y = (int)(Math.random() * tate);
   if(x != spx || y != spy)
   {
    ban[spx][spy] = ban[x][y];
    spx = x;
    spy = y;
    cnt++;
   }
  }
}}}

ばらばらにする

   1         void shokika()
   2         {
   3                 int x, y, x2, y2, w, cnt;
   4                 ...
   5                 ...
   6                 for (cnt = 0; cnt < (tate*yoko*2); cnt++)
   7                 {
   8                         x = (int)(Math.random() * (yoko-1));
   9                         y = (int)(Math.random() * (tate-1));
  10                         if(Math.random() < 0.5)
  11                         {
  12                                 x2 = x;
  13                                 y2 = y + 1;
  14                         }
  15                         else
  16                         {
  17                                 x2 = x + 1;
  18                                 y2 = y;
  19                         }
  20                         w = ban[x][y];
  21                         ban[x][y] = ban[x2][y2];
  22                         ban[x2][y2] = w;
  23                 }
  24         }

解のある配置を作る (最終更新日時 2012-01-25 00:55:25 更新者 masahiko)