摘 要
我们采用C++编程语言设计了一个五子棋对弈游戏。它能够做到玩家与计算机按照标准的五子棋规则对弈。这个程序包括一个能够进行人机交互的图形化界面和一个符合五子棋规则的对弈算法。图形界面模块负责在程序窗口中绘制棋盘和棋子,并通过响应鼠标事件进行交互。对弈算法以搜索算法和赋值算法为核心。我们通过遍历棋盘上的位子给不同的棋型赋予相应的值,并通过对弈算法找到当前局面的最优落子点。在每一步落子后程序将会对棋盘进行分析,若发现某方达成了获胜条件,则会结束本局游戏,输出对弈结果。本文描述了这个对弈游戏的实现方法。测试结果表明本游戏可以支持五子棋的人机对弈。
关键词:C++,五子棋,对弈算法
Development of a stand-alone board game based on artificial intelligence
ABSTRACT
We have designed a backgammon game using the C++ programming language. It enables the player and the computer to play according to standard backgammon rules. The program consists of a graphical interface that allows human-computer interaction and a game algorithm that conforms to the rules of futsal. The graphical interface module is responsible for drawing the board and pieces in the program window and interacting with them by responding to mouse events. The game algorithm is based on a search and assignment algorithm. By traversing the board and assigning values to the different types of pieces, we find the optimal move for the current position. After each move the board is analysed and if a winning condition is found, the game ends and the result is output. This paper describes the implementation of this game. Test results show that the game can support human-computer play of five pieces.
Key words: Artificial Intelligence, Gobang, Greedy Algorithm