Hexomania-六角形游戏(译文)
By robot-v1.0
本文链接 https://www.kyfws.com/games/hexomania-a-game-for-hexagons-zh/
版权声明 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
- 4 分钟阅读 - 1807 个词 阅读量 0Hexomania-六角形游戏(译文)
原文地址:https://www.codeproject.com/Articles/6684/Hexomania-A-Game-for-Hexagons
原文作者:Bishoy Labib
译文由本站 robot-v1.0 翻译
前言
A strategy game that you can play versus the computer or another player
您可以与计算机或其他玩家一起玩的策略游戏
介绍(Introduction)
Hexomania是我制作并想与您分享的策略游戏.它包含用于计算机游戏的良好AI.我认为这是使用C#可以做的一个很好的例子.编程花了2天时间.(Hexomania is a strategy game that I’ve made and wanted to share with you. It contains a good AI for the computer play. I think this is a good example of what you can do with C#. It took 2 days for programming.)
怎么玩(How to Play)
每个玩家都有许多相同颜色的棋子和一些目标(圆圈).游戏轮流玩.目标每转一圈随机移动一步.如果他的所有目标都被监禁(无法动弹),您将获胜.您可以通过将任意一个棋子移到与另一个棋子相邻的空十六进制进行游戏.(Every player has a lot of pieces and some targets (circles) with the same color. The game is played in turns. Targets move randomly one step, every turn. You win if all his targets are imprisoned (can’t move). You play by moving any of your pieces to an empty hex that is adjacent to another one of your pieces.) 单击一块移动.单击一个空的十六进制以放置该部分.您可以更改电路板的大小(当然也可以更改块数和目标).您可以更改玩家数量.(Click a piece to move. Click an empty hex to put the piece. You can change the board size (and number of pieces and targets of course). You can change the number of players.) 希望您喜欢这款游戏.(I hope you enjoy the game.)
游戏类别包括(The Game Classes Consists Of)
Board
:可以保存几乎所有信息(十六进制单元,(: which saves information about almost everything (hex cells,)ArrayList
团队),并处理董事会的图纸.包含一些功能以帮助计算每个团队的AI成本((of teams), and also handles the drawing of the board. Contains some functions to help AI cost calculations per team ()Form1
包含使用此功能的实际AI).(contains the actual AI that uses this function).)Team
:保存有关玩家名称,控制权(人,CPU)的信息,并保存该玩家的目标位置. (请注意,玩家片段已保存在棋盘阵列中.)(: which saves information about player name, control (human, CPU), and saves the targets positions of this player. (Note that the players pieces are saved in the board array.))Form1
:游戏的主要形式,为用户和一些计算机玩转(AI)处理鼠标单击(: The main form of the game and handles mouse clicks for the users and some of the computer playing turn (AI))
计算机人工智能(The Computer AI)
AI很简单.它由功能组成(The AI is simple enough. It consists of the function) Board.Cost(team)
它计算某个玩家当前棋盘位置的成本.基于玩家每个目标周围的可用空间之和.这意味着当(which calculates the cost for the current position of the board for a certain player. Based on the sum of free spaces around every target of the player. This means that the player wins when the) Cost
退货(returns) 0
.(.)
的(The) Cost
该功能通过创建一个(function works by creating a) tmp
与电路板相同大小的数组,最初包含零.然后搜索玩家的每个目标,并为每个可用空间添加一定数量的(array with the same size of the board, that initially contains zeros. Then search around every target of the player and add for every free space a certain amount of) cost
在里面(in the) tmp
数组.当位置接近目标时,此数量较大,而远离目标时,此数量较小,因为我们希望计算机填充目标周围的可用空间.然后(array. This amount is big when the position is near the target, and small when far from it because we want the computer to fill the free space around the target. Then the) Cost
函数返回所有的和(function returns the sum of all the) tmp
数组.(array.)
为了让计算机发挥作用,它会搜索可拆卸的零件,从而降低成本.然后根据(再次)产生的最低成本,寻找放置该零件的最佳位置.(For the computer to play its turn, it searches for the piece that can be removed producing the minimum cost. Then searches for the best position to put that piece in, based on (again) the minimum cost produced.)
在要删除的所有可用块上进行搜索,然后在与其他块相邻的所有空闲空间上进行搜索,以选择放置位置.(The search is done on all the available pieces to remove, then on all the free spaces that are adjacent to other pieces, to select a place to put on.)
如何在数组中保存十六进制网格(How to Save a Hex Grid in an Array)
它是由一个普通的二维数组完成的.但是y位置在下面每隔一个半格(It is done by a normal 2 dimensional array. But the y positions are spaced by a half grid below, every) Xindex mod 2 = 1
,以创建十六进制形状.下一个形状显示了我们如何计算数组的x,y索引:(, to create the hex shape. The next shape shows how we calculate the x,y index of the array:)
历史(History)
- 14(14)日(th)2004年4月:初始版本(April, 2004: Initial version)
执照(License)
本文没有附带任何明确的许可,但可能在文章文本或下载文件本身中包含使用条款.如有疑问,请通过下面的讨论区与作者联系.可以找到作者可能使用的许可证列表(This article has no explicit license attached to it, but may contain usage terms in the article text or the download files themselves. If in doubt, please contact the author via the discussion board below.A list of licenses authors might use can be found) 这里(here) .(.)
许可
本文以及所有相关的源代码和文件均已获得The Code Project Open License (CPOL)的许可。
C# Windows .NET .NET1.1 Visual-Studio VS.NET2003 Dev 新闻 翻译