GitHub

谁方便谁拍,谁重要拍谁。在这个砖头满天飞的时代,一个好的生态显得尤为重要。

      红颜小头发,要的很简单。

    也许成绝唱,只因鱼断肠。

姚贝福娃的离去,除感叹人生无常外,活着做点有意义的事情,就显得更为重要。

数年前为学习人工智能,写了围棋程序,却发现其难度超出了我的想象。特将其放到 GitHub 上,希望有人斧正。注意,是斧正,而非小修小改。

调整重绘

窗口大小改变时,棋盘也要作相应的重绘。这个比较简单,我的方法是把 BoardBase 类中的 m_sbSteps 字段改成 public,在主窗口 MainWindows 中保存之。具体的操作参考了 StepBoard 类中的办法,复制粘贴,略作修改而已,代码如下:

 1     // For Size Change and Show Number
 2 
 3         List<StepContent> m_steps = new List<StepContent>();
 4         public void FillSteps()
 5         {
 6             m_steps.Clear();
 7             string s = m_sbSteps.ToString();
 8             if (s.Length < 1) return;
 9             string[] steps = s.Substring(0, s.Length - 1).Split(',');
10             StepContent step = new StepContent();
11             for (int i = 0; i < steps.Length; i++)
12             {
13                 if (i % 3 == 0)
14                 {
15                     step = new StepContent();
16                     step.Col = Convert.ToInt32(steps[i]);
17                 }
18                 else if (i % 3 == 1)
19                 {
20                     step.Row = Convert.ToInt32(steps[i]);
21                 }
22                 else if (i % 3 == 2)
23                 {
24                     step.Count = Convert.ToInt32(steps[i]);
25                     m_steps.Add(step);
26                 }
27             }
28         }
29         public void RenderChess()
30         {
31             m_sbSteps.Clear();
32             foreach (var item in m_steps)
33             {
34                 NextOne();
35             }
36         }
37 
38         int m_count = 1;
39         public void NextOne()
40         {
41             if (m_count > m_steps.Count)
42             {
43                 return;
44             }
45 
46             foreach (var item in m_steps)
47             {
48                 if (item.Count == m_count)
49                 {
50                     int col = item.Col;
51                     int row = item.Row;
52 
53                     if (Steps[col, row].Color != ChessColor.Empty)
54                     {
55                         return;
56                     }
57 
58                     if (NotInPos.X == col && NotInPos.Y == row)
59                     {
60                         return;
61                     }
62                     else
63                     {
64                         // If Pos(struct) is property, must use new.
65                         NotInPos = new Pos(-1, -1);
66                     }
67 
68                     DrawChess(col, row);
69 
70                     Eat(col, row);
71                 }
72             }
73             m_count++;
74         }
75 
76         public bool IsShowNumber { get; set; }
for size change

相关文章: