N:0 Y:0 X:0 N:0 Y:0 X:1 N:0 Y:0 X:2 N:0 Y:1 X:0 N:0 Y:1 X:1 N:1 Y:0 X:0 N:2 Y:2 X:2 N:0 Y:1 X:2 N:0 Y:2 X:0 N:0 Y:2 X:1 N:0 Y:2 X:2 |
前田稔(Maeda Minoru)の超初心者のプログラム入門
![]()
![]()
//★ 三目並べの連鎖構造 前田 稔 ★
using System;
using System.Collections; //ArrayList を使うとき
class Cell
{ public ArrayList AL = null;
public int n; // N 手目
public int y; // Y 座標
public int x; // X 座標
}
class Prog
{
public static void Main()
{
Cell top = new Cell();
Cell wk;
int i;
// top に一手目を登録
top.AL = new ArrayList();
for(i=0; i<9; i++)
{ wk = new Cell();
wk.n = 0;
wk.y = i/3;
wk.x = i%3;
top.AL.Add(wk);
}
for(i=0; i<top.AL.Count; i++)
{ wk = (Cell)top.AL[i];
Console.WriteLine("N:" + wk.n + " Y:" + wk.y + " X:" + wk.x);
}
Console.ReadLine();
}
}
|
class Cell
{ public ArrayList AL = null;
public int n; // N 手目
public int y; // Y 座標
public int x; // X 座標
}
|
public static void Main()
{
Cell top = new Cell();
Cell wk;
int i;
// top に一手目を登録
top.AL = new ArrayList();
for(i=0; i<9; i++)
{ wk = new Cell();
wk.n = 0;
wk.y = i/3;
wk.x = i%3;
top.AL.Add(wk);
}
|
for(i=0; i<top.AL.Count; i++)
{ wk = (Cell)top.AL[i];
Console.WriteLine("N:" + wk.n + " Y:" + wk.y + " X:" + wk.x);
}
Console.ReadLine();
|
![]()
wk = new Cell();
wk.n = 1;
wk.y = 0;
wk.x = 0;
pt = (Cell)top.AL[4];
pt.AL = new ArrayList();
pt.AL.Add(wk);
|
wk = new Cell();
wk.n = 2;
wk.y = 2;
wk.x = 2;
pt = (Cell)pt.AL[0];
pt.AL = new ArrayList();
pt.AL.Add(wk);
|
Print(top);
Console.ReadLine();
}
|
public static void Print(Cell top)
{ Cell wk;
int i;
for (i=0; i<top.AL.Count; i++) // ArrayList(手番で列挙)の印字
{ wk = (Cell)top.AL[i];
Console.WriteLine("N:" + wk.n + " Y:" + wk.y + " X:" + wk.x);
if (wk.AL != null) Print(wk); // AL[i] から Cell にリンク
}
}
|
![]()
[Next Chapter ↓] 三目並べの学習機能
[Previous Chapter ↑] ArrayList の連鎖