五子棋是起源于中国古代的传统黑白棋种之一。现代五子棋日文称之为“連珠”,英译为“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.