五子棋是起源于中國古代的傳統黑白棋種之一。現代五子棋日文稱之為“連珠”,英譯為“Renju”,英文稱之為“Gobang”或“FIR”(Five in a Row的縮寫),亦有“連五子”、“五子連”、“串珠”、“五目”、“五目碰”、“五格”等多種稱謂。
本設計采用的是在MyEclipse環境下以Java開發言語為核心所編寫的五子棋。在人機對弈模式中,電腦下棋的算法主要采用的是搜索算法結合估值函數來完成電腦的下棋。在聯機對弈模式中,棋盤狀態的傳輸與同步主要是通過棋盤類與message類的交互來完成的,以此來實現聯機對弈。棋局的勝負是根據最后一個落子的情況來判斷的。需要查看四個方向,即以該棋子為出發點的水平,豎直和兩條分別為45 度角和135 度角的線,看在這四個方向上的其它棋子是否能和最后落子構成連續五個棋子,若有連成5個子的即為勝。再配以Unix系統及Servlet標識語言,最終能夠實現本機人機對弈,以及兩人聯機對弈。
關鍵詞:五子棋,搜索算法,人機對弈,聯機對弈
ABSTRACT
Renju is one kind of the tradition Reversi which is originated in ancient China. Modern backgammon is named as "Pente" in Japanese, translated as "Renju", named as "Gobang" or "FIR" (Five in a Row acronym) in English, also have many. Other names, such as" Wu Lian Zi", "Wu Zi Lian", "bead" , "five head", "five head touch" and "five grid".
This paper develop Cobang game by the language of Java in the MyEclipse environment. In the man-machine chess mode, the computer chess algorithm mainly uses search algorithm with valuation function. In the online chess mode, the transmission of checkerboard’s transfer and synchronization is completed through the interaction of checkerboard and message, to realize online chess. The outcome of the chess game is based of the last piece’s state. We should check four directions, namely, the level line, the vertical line, and the other two lines which have 45-degree angle and 135-degree angle with the starting point of the piece, and we should find whether the last piece can link with other pieces in the four directions to be five pieces in the line continuously. We will win if we connect the five pieces. Local man-machine chess and two on-line chess can be achieved coupling with Unix system and Setvlet markup language.