Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/zhenxiangba/zhenxiangba.com/public_html/phproxy-improved-master/index.php on line 456
ゲームを記憶
//★ 三目並べの連鎖構造 前田 稔 ★
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 が手を記録する構造体(Class)で、ArrayList AL から Cell を連鎖します。
メンバーとして何手目かを表す n と駒を打つ座標 y, x を定義しています。
ArrayList の連鎖は ArrayList の連鎖 を参照して下さい。
class Cell
{ public ArrayList AL = null;
public int n; // N 手目
public int y; // Y 座標
public int x; // X 座標
}
top が連鎖する構造体のトップポインターです。
wk は作業用で、Cell の連鎖に使用します。
top が指し示す ArrayList AL に一手目(3*3=9個)の Cell を登録します。
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);
}