野路子實現,完全自己想出來的實現方式,將棋盤轉成一維陣列,尋找橫向、縱向、左斜、右斜元素下標的關係。
橫向:元素之間下標相差1;
縱向:元素之間下標相差棋盤寬度;
右斜:元素之間下標相差寬度+1;
左斜:元素之間下標相差寬度-1;
沒有寫介面,先用測試資料
public static void main(string args)
;int index = 56;//落子位置
bool iswin = check(index, qipanarr);
if (iswin)
win!");
}else
console.readkey();
}//輸出: 黑子 win!
static int width = 8;//可以設定此值,代表棋盤的長寬
static int length = width * width;
static int hengxiangincr = 1;
static int zongxiangincr = width;
static int rigthincr = width + 1;
static int leftincr = width - 1;
static bool check(int index, int qipanarr)
//檢查右斜
if (!iswin)
//檢查左斜
if (!iswin)
return iswin;
}/// /// 檢查橫向
///
///
///
///
static bool checkhengxiang(int index, int qipanarr)
if (indexrownumerdict[index] != orirow)
if (qipanarr[index] != type)
if (++matchcount == 5)
}if (matchcount < 5)
index += hengxiangincr;
if (index < 0 || index >= length)
if (qipanarr[index] != type)
if (++matchcount == 5)}}
return matchcount == 5 ? true : false;
}/// /// 檢查縱向
///
///
///
///
static bool checkzongxiang(int index, int qipanarr)
if (indexrownumerdict[index] + cyclecount != orirow)
if (qipanarr[index] != type)
if (++matchcount == 5)
}if (matchcount < 5)
if (indexrownumerdict[index] - cyclecount != orirow)
if (qipanarr[index] != type)
if (++matchcount == 5)}}
return matchcount == 5 ? true : false;
}/// /// 檢查右斜
///
///
///
///
static bool checkright(int index, int qipanarr)
if (indexrownumerdict[index] + cyclecount != orirow)
if (qipanarr[index] != type)
if (++matchcount == 5)
}if (matchcount < 5)
if (indexrownumerdict[index] - cyclecount != orirow)
if (qipanarr[index] != type)
if (++matchcount == 5)}}
return matchcount == 5 ? true : false;
}/// /// 檢查左斜
///
///
///
///
static bool checkleft(int index, int qipanarr)
if (indexrownumerdict[index] + cyclecount != orirow)
if (qipanarr[index] != type)
if (++matchcount == 5)
}if (matchcount < 5)
if (indexrownumerdict[index] - cyclecount != orirow)
if (qipanarr[index] != type)
if (++matchcount == 5)}}
return matchcount == 5 ? true : false;
}
public enum etype
下五子棋的bot 五子棋演算法
include include include include include include jsoncpp json.h c 編譯時預設包含此庫 define n 7 每個節點的分支數 以下為各棋型的識別碼 權重 define win 1 4000 define lose 2 4000 defi...
五子棋(vb演算法)
for i 1 to 11 for j 1 to 11 if map i,j a and map i 1,j 1 a and map i 2,j 2 a and map i 3,j 3 a and map i 4,j 4 a then gameover a exit function next j ...
五子棋演算法3
這裡設計和實現了乙個人機對下的五子棋程式,採用了博弈樹的方法,應用了剪枝和最大最小樹原理進行搜尋發現最好的下子位置。介紹五子棋程式的資料結構 評分規則 勝負判斷方法和搜尋演算法過程。一 相關的資料結構 關於盤面情況的表示,以鍊錶形式表示當前盤面的情況,目的是可以允許使用者進行悔棋 回退等操作。cli...