星空网 > 软件开发 > ASP.net

x01.Weiqi.7: 调整重绘

GitHub

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

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

    也许成绝唱,只因鱼心火。

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

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

调整重绘

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

x01.Weiqi.7: 调整重绘x01.Weiqi.7: 调整重绘
 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           else63           {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

显示步数

为了显示步数,在 Chess 类中加了几个属性,然后在 BoardBase 的 DrawChess 方法中也作了相应的调整。代码如下:

x01.Weiqi.7: 调整重绘x01.Weiqi.7: 调整重绘
 1 public string NumberText 2     { 3       get { return m_TxtNumber.Text; } 4       set { m_TxtNumber.Text = value; } 5     } 6  7     public double NumberFontSize 8     { 9       get { return m_TxtNumber.FontSize; }10       set { m_TxtNumber.FontSize = value; }11     }12 13     public System.Windows.Thickness NumberPadding14     {15       get { return m_TxtNumber.Padding; }16       set { m_TxtNumber.Padding = value; }17     }

Chess properties
x01.Weiqi.7: 调整重绘x01.Weiqi.7: 调整重绘
 1   if (Steps[col, row].Chess == null) 2       { 3         Chess chess = new Chess(brush, ChessSize); 4         if (IsShowNumber) 5         { 6           double size = (double)ChessSize; 7           chess.NumberFontSize = (m_StepCount + 1) > 99 8             ? size / 2 : (m_StepCount + 1) > 9 9             ? size / 1.6 : size / 1.2;10           chess.NumberPadding = (m_StepCount + 1) > 9911             ? new Thickness(size/28, size / 5.5, 0, 0) : (m_StepCount + 1) > 912             ? new Thickness(size / 8, size / 8, 0, 0) : new Thickness(size / 4, 0, 0, 0);13           chess.NumberText = (m_StepCount + 1).ToString();14           chess.NumberBrush = (m_StepCount % 2 == 1) ? Brushes.Black : Brushes.White;15         }16         chess.SetShow(IsShowNumber);17         Canvas.SetLeft(chess, left);18         Canvas.SetTop(chess, top);19         m_Canvas.Children.Add(chess);20         Steps[col, row].Chess = chess;21       }

in the DrawChess()

效果图

                               x01.Weiqi.7: 调整重绘

代码下载链接:https://github.com/chinax01/x01.Weiqi




原标题:x01.Weiqi.7: 调整重绘

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

一位eBay老司机梳理几年的运营整体思路!:https://www.ikjzd.com/articles/9246
亚马逊招商经理的隐藏技能大揭秘!:https://www.ikjzd.com/articles/9260
成为eBay大卖家前,你必须有这些运营技能和魄力:https://www.ikjzd.com/articles/9261
亚马逊如何正确选品,找到产品亮点,打造自有品牌产品差异化?:https://www.ikjzd.com/articles/9266
注意!这两大类产品都将被禁售!:https://www.ikjzd.com/articles/9267
亚马逊卖家如何为产品精准引流:https://www.ikjzd.com/articles/9268
去日本入住酒店,东西随意用却有一个特殊“要:https://www.vstour.cn/a/411241.html
中国有哪些著名的酒店品牌。:https://www.vstour.cn/a/411242.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流