
前田稔(Maeda Minoru)の超初心者のプログラム入門
![]()
![]()
( ;FF[3]GM[1]AP[PocketGoban Ver 0.999] SZ[19]DT[2014-02-13] KM[5.5] AB[bc][cc][db]AW[cd][dc][ec][eb][de][cf] ;B[ca];W[ab];B[bb];W[ea];B[aa];W[ba];B[ac];W[da];B[cb] ) |
碁盤の左上端から縦軸、横軸へそれぞれa、b、c・・・とします。 a b c d e f g h i j k l m n o p q r s 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
string m_SGF; // SGF FILE Source
int m_P; // m_SGF Position
short m_Ishi = 0; // 黒&白
Point m_Pos;
string wk;
|
private void Form_Load(object sender, EventArgs e)
{
m_Width = this.Width;
m_Height = this.Height;
m_Ban.Initialize();
LoadSGF("C:\\DATA\\Pocket囲碁\\test1.sgf");
}
|
private void LoadSGF(string file_name)
{
if (!File.Exists(file_name)) return;
StreamReader reader = new StreamReader(file_name,Encoding.GetEncoding("Shift_JIS"));
m_SGF= reader.ReadToEnd();
Console.WriteLine(m_SGF);
reader.Close();
m_P = 0;
m_Ishi = 0;
Token(); // (
m_P++;
Token(); // ;
m_P++;
while(true)
{
wk = "*";
switch(Token())
{
case '(':
case ')':
case ';':
return;
case '*': // プロパティ
if (wk=="AW") m_Ishi= -1;
else if (wk=="AB") m_Ishi= 1;
else m_Ishi = 0;
break;
case '[':
Console.WriteLine("[" + wk + "] 黒白" + m_Ishi);
if (m_Ishi!=0 && Convt())
m_Ban[m_Pos.X, m_Pos.Y] = m_Ishi;
break;
}
}
}
|
private char Token()
{ int i;
while(true)
{ switch(m_SGF[m_P])
{ case '(':
case ')':
case ';':
return m_SGF[m_P];
case '[':
m_P++;
for(i=m_P; m_SGF[i]!=']'; i++);
wk = m_SGF.Substring(m_P, i-m_P);
m_P = i+1;
return '[';
default:
if (m_SGF[m_P]>='A' && m_SGF[m_P]<='Z')
{
GetKey();
return '*';
}
m_P++;
break;
}
}
}
|
private void GetKey()
{ int i;
for(; m_SGF[m_P]<'A' || m_SGF[m_P]>'Z'; m_P++);
for(i=m_P; m_SGF[i]>='A' && m_SGF[i]<='Z'; i++);
wk = m_SGF.Substring(m_P, i-m_P);
m_P = i;
}
|
string alph = "abcdefghijklmnopqrs";
private bool Convt()
{
m_Pos.X = alph.IndexOf(wk[0]);
m_Pos.Y = alph.IndexOf(wk[1]);
if (m_Pos.X==-1 || m_Pos.Y==-1) return false;
return true;
}
|
![]()