void PrintQizi(int idx) { if (idx == -1) { ShowTip("无效落子"); return; } GameObject oo = null; string f = "黑棋"; if (wzq.curTurn == Wuziqi.qiType.white) { f = "白棋"; oo = GameObject.Instantiate(whiteQ) as GameObject; } else { oo = GameObject.Instantiate(blackQ) as GameObject; } if (wzq.XiaQi(idx)) { ShowTip(f + "落子成功"); Vector2 p = getDropPointByIndex(idx); oo.transform.SetParent(qiTrans); oo.transform.localScale = Vector3.one; oo.transform.localPosition = p; } else { if (wzq.curState != WZQGame.gState.over) { ShowTip("无效落子"); } } }
/// <summary> /// 1,获取落子点的可赢矩阵 /// 2,获取可赢矩阵中有效落子点 /// 3,计算有效落子点的可赢权值 /// 4,排序 /// 5,取最大权值落子 /// </summary> //分析有效落子点的可赢权值 /* * 1, 试探性落子 * 2,计算这个落子的可赢矩阵 * 3,计算矩阵每个序列上的连续值情况 * 4,统计=5个数;统计=4个数;统计=3个数;统计=2个数 * 5,如果存在统计=5或者=4 */ public int t(Pos p) { #region //计算有效落子点 int[][] matraix = wzq.GetWinMatraix(p); List <int> plist = new List <int>(); for (int i = 0; i < matraix.GetLength(0); i++) { for (int j = 0; j < matraix[i].Length; j++) { byte r = 3; wzq.indexOf(matraix[i][j], ref r); if (r == 0) { plist.Add(matraix[i][j]); } } } #endregion #region 计算有效落子点的所有矩阵 Dictionary <int, int[][]> totalMatriaxDic = new Dictionary <int, int[][]>(); plist.ForEach(_ => { wzq.XiaQi(_, false); //试探性落子矩阵 int[][] tempM = wzq.GetWinMatraix(Wuziqi.indexOf(_)); //获取该点的可赢 totalMatriaxDic.Add(_, tempM); }); #endregion #region byte b = 3; wzq.indexOf(Wuziqi.indexOf(p.x, p.y), ref b); List <KeyValuePair <int, int> > totalPointValueList = new List <KeyValuePair <int, int> >(); foreach (KeyValuePair <int, int[][]> kp in totalMatriaxDic) { if (kp.Key == -1) { continue; } totalPointValueList.Add(new KeyValuePair <int, int>(kp.Key, caculateQ(matraixValue(kp.Value, 1, 5, b)))); wzq.BackQi(kp.Key); //恢复棋子 } #endregion #region 排序权值 totalPointValueList.Sort((x, y) => { if (x.Value < y.Value) { return(1); } else if (x.Value > y.Value) { return(-1); } return(0); }); return(totalPointValueList[0].Key); #endregion }