script property

List<List<String>> script
getter/setter pair

Implementation

List<List<String>> script = [
  [
    ":label width     @0",
    ":label height    @1",
    ":label forecolor @2",
    ":label backcolor @3",
    ":ans 0",

    "@@d { # 変位ベクトル",
    "  { 2 0 \\-2 0 } # X方向",
    "  { 0 2 0 \\-2 } # Y方向",
    "}",
    "@@t { # 方向表",
    "  { 0 1 2 3 } { 0 1 3 2 } { 0 2 1 3 } { 0 2 3 1 } { 0 3 1 2 } { 0 3 2 1 }",
    "  { 1 0 2 3 } { 1 0 3 2 } { 1 2 0 3 } { 1 2 3 0 } { 1 3 0 2 } { 1 3 2 0 }",
    "  { 2 0 1 3 } { 2 0 3 1 } { 2 1 0 3 } { 2 1 3 0 } { 2 3 0 1 } { 2 3 1 0 }",
    "  { 3 0 1 2 } { 3 0 2 1 } { 3 1 0 2 } { 3 1 2 0 } { 3 2 0 1 } { 3 2 1 0 }",
    "}",

    "width  = int (width  / 2) * 2 # 偶数にする",
    "height = int (height / 2) * 2 # 偶数にする",
    ":gworld (width + 1) (height + 1) # オフスクリーンを設定する",
    ":srand time # 時刻で乱数を初期化",

    "#",
    "# 地図を初期化",
    "#",
    ":gfill 0 0 (width + 1) (height + 1) forecolor",
    ":gfill 3 3 (width - 5) (height - 5) backcolor",
    ":gput 2 3 backcolor # スタート地点",
    ":gput (width - 2) (height - 3) backcolor # ゴール地点",

    "#",
    "# サイトを加える",
    "#",
    "@s = 0",
    "for @i = 4; @i <= width - 4; @i += 2",
    "  @@x @s = @i; @@y @s = 2;          @s++",
    "  @@x @s = @i; @@y @s = height - 2; @s++",
    "next",
    "for @j = 4; @j <= height - 4; @j += 2",
    "  @@x @s = 2;         @@y @s = @j; @s++",
    "  @@x @s = width - 2; @@y @s = @j; @s++",
    "next",

    "@S = TRUE"
  ],
  [
    "if [!]@S || @s [!=] 0",
    "  do",
    "    if @S",
    "      #",
    "      # サイトを選ぶ",
    "      #",
    "      @s--; @r = int (@s * (rand / (RAND_MAX + 1.0)))",
    "      @i = @@x @r; @@x @r = @@x @s",
    "      @j = @@y @r; @@y @r = @@y @s",
    "      @S = FALSE",
    "    endif",

    "    #",
    "    # そこから延ばしていく",
    "    #",
    "    @T = int (24 * (rand / (RAND_MAX + 1.0)))",
    "    for @d = 3; @d >= 0; @d--",
    "      @t = @@t @T @d; @I = @i + @@d 0 @t; @J = @j + @@d 1 @t",
    "      if gget @I @J == backcolor; break; endif",
    "    next",
    "    if @d < 0; @S = TRUE; endif",
    "  until @S && @s [!=] 0",

    "  if [!]@S",
    "    :gput ((@i + @I) / 2) ((@j + @J) / 2) forecolor",
    "    @i = @I; @j = @J; :gput @i @j forecolor",
    "    @@x @s = @i; @@y @s = @j; @s++",
    "  endif",
    "endif"
  ]
];