用于PocketPC和Windows的Reversi(Othello)游戏的C#实现(译文)
By robot-v1.0
本文链接 https://www.kyfws.com/games/a-c-implementation-of-reversi-othello-game-for-poc-zh/
版权声明 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
- 4 分钟阅读 - 1968 个词 阅读量 0用于PocketPC和Windows的Reversi(Othello)游戏的C#实现(译文)
原文地址:https://www.codeproject.com/Articles/7892/A-C-implementation-of-Reversi-Othello-Game-for-Poc
原文作者:George Mamaladze
译文由本站 robot-v1.0 翻译
前言
A C# implementation of Reversi (Othello) Game for PocketPC and Windows.
用于PocketPC和Windows的Reversi(Othello)游戏的C#实现.
- 下载源文件-77.6 Kb(Download source files - 77.6 Kb)
- 下载适用于Windows的增强型可执行文件和程序集-19.5 Kb(Download compieled Executable and Assembly for Windows - 19.5 Kb)
- 下载PocketPC的安装程序-40.5 Kb(Download setup for PocketPC - 40.5 Kb)
介绍(Introduction)
我最初的目标是移植(My initial goal was to port)C#中的黑白棋作者:BrainJar(Reversi in C# By BrainJar)程序到Pocket PC.一段时间后,我意识到,如果不了解它的发生方式和发生方式,就没有机会利用现有程序.所以,我自己写的.我试图使其尽可能简单.(program to Pocket PC. After some time, I realized that without understanding what and how it happens, there is no chance to make use of the existing program. So, I wrote it myself. I have tried to make it as simple as possible.)
整个游戏功能集中在独立的程序集中(The whole game functionality is concentrated in the independent assembly)gma.Reversi.dll(gma.Reversi.dll).使用同一程序集的有两个不同的表示层.的(. There are two different Presentation Layers using the same assembly; the) gma.Windows.Reversi
对于Windows .NET和(for Windows .NET and) gam.Mobile.Reversi
用于PocketPCCF.(for PocketPC CF.)
的(The) Board
类用于存储游戏信息,维护评估所需的统计信息并保证游戏规则.的(class is used to store game information, maintain statistics which are necessary for evaluation, and guarantees game rules. The) VirtualPlayer
类是(class is a descendant of the) Player
类,并包括评估和搜索算法.这是一个实现此程序"智能"的类.的(class and includes evaluation and search algorithms. This is a class that implements “intelligence” to this program. The) GUIPlayer
班级也是(class is also descendant of) Player
并实现与表示层的交互.两名参与者都使用相同的方法和事件与董事会互动,因此两者之间没有区别(and implements interaction with the presentation layer. Both players are interacting with board using same Methods and Events, so there is no difference for) Board
关于哪个(about which) Player
已连接.(s are connected.)
博弈论(Game Theory)
理解Reversi游戏编程的一个很好的页面是"(Very good page to understand programming a Reversi game is “) 编写奥赛罗程序(Writing an Othello program) “.只有您熟悉战略游戏编程的基础知识,以下信息才会变得有趣.(” by Gunnar Andersson. Following information will be interesting only if you are familiar with the basics of strategic game programming.)
正在搜寻(Searching)
游戏的核心是(The core of a game is)*α-β(alpha-beta)*修剪算法.我的实现方式相对通用,因此也可以在其他一些棋盘游戏中使用.我将在当前正在使用的GO游戏中使用它.最初,我实施了残酷的(pruning algorithm. My implementation is relatively universal, so it can be used in some other board games as well. I am going to use it in my GO game I am working on currently. Initially, I have implemented brutal)极小值(minimax)搜索,并将其重写为(search, and after rewriting it into)α-β(alpha-beta),我的性能提高了70%.启发式执行(, I had a 70% increase of performance. A heuristic to perform)*浅(shallow)*搜索仅在(searches was implemented only in) VirtualPlayerComplex
类,这基本上是唯一的区别(class, it is basically the only difference between) VirtualPlayer
和(and) VirtualPlayerComplex
类.它仅在Windows版本中使用,并没有带来任何实际的性能改进.(classes. It is used only in Windows version and does not bring any real performance improvements.)
职位评估(Position evaluation)
此描述仅使您了解其工作方式.在某些情况下,这有点复杂.我的评估功能((This description gives you only an idea of how it works; in some cases, it is a little bit complicated. My evaluation function () Score
)基于以下条件:() is based on the following criteria:)
- 支配地位.拥有正方形作为对手是很好的.(Dominance. It is good to own squares as an opponent.)
- 流动性.当您有更多移动选择时,这很好.(Mobility. It is good when you have more move alternatives.)
- 磁盘平方表.角好,角旁的方块不好.(Disk-square table. Corners are good and the squares next to corners are bad.)
- 稳定性.捕获无法转换的正方形是很好的.(Stability. It is good to capture squares which cannot be converted.) 我为这些标准分配了一些权重,但是我敢肯定,验证它们可以增加程序的"智能”.(I have assigned some weights to these criteria, but I am sure that verifying them can increase the program’s “intelligence”.) 为了提高性能(并因此提高搜索深度),需要做很多事情,但是您需要在性能和代码透明性之间做出折衷.这个程序不是为赢得奥赛罗世界杯而编写的,因此有很多方法可以改善它.例如,背景分析(一个程序在等待人类玩家输入时计算下一步动作的线程),游戏开头的知识库和模式评估.(There are a lot of things to do in order to increase performance (and accordingly search depth), but then you need to make a compromise between performance and code transparency. This program was not written to win Othello world cup, so there are many ways to improve it. For example, Background Analysis (a thread that calculates next moves when a program is waiting for an input from the human player), Knowledge Base for game openings, and Pattern evaluation.)
许可
本文以及所有相关的源代码和文件均已获得The Code Project Open License (CPOL)的许可。
C# .NET1.1 Windows .NETCF .NET .NET1.0 Visual-Studio VS.NET2003 Dev 新闻 翻译