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 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 方法中也作了相應的調整。代碼如下:
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
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()
效果圖
代碼下載鏈接:https://github.com/chinax01/x01.Weiqi
1.使用 Code First 來操作數據庫。但窗口大小改變時,StepBoard 仍是個問題。2.使用 GitHub for windows,Sync 時 VS 老跑出來 debug。改用 shell:git init => git push 后問題解決。
1.改正了 StepBoard 重繪時的問題。2.git 時出現 fast-forward 問題,采用移除本地倉庫,Clone 遠程倉庫,修改后重新 git push 解決,可謂笨也!
1.為在 Windows xp 上運行,只能采取 .Net 4.0,安裝 Sql Express 2008,故作了些調整。
2.開發過程,可參見:http://www.49028c.com/china_x01/category/685502.html
1.為操作的方便,作了些調整,如中文顯示菜單,快捷鍵等。
2.刪除 StepService 類,因為數據操作很少,沒有必要加個中間層。
1.Go 大約是 Game 加一個圈,表示圍棋的意思。但在表音的語言里,添加象形的東西,多少有些奇怪。圍棋術語,大都采用日語的音譯,如:aji,不知何云?名不正則言不順,在圍棋這一特定場景下,統一術語,是有必要的。當然,有些術語是不需要,如見合等,因為在程序中尚無具體實現。簡化術語如下: 圍棋:weiqi; 棋盤:board;棋子:stone;棋局:record;棋步(邏輯棋子):step;吃:eat;飛:fly;跳:jump;尖:sharp;長:grow;征:levy;
2.牽一發而動全身,小作修改,也能導致許多問題,一動不如一靜也。
1.解決 BackOne() 時死子不能顯示數字的問題。2.添加刪除棋譜功能,完善數字顯示。
新聞熱點
疑難解答