你将如何实施游戏逆转? (奥赛罗)

时间:2023-01-27 13:04:31

I have been thinking about starting a side project at home to exercise my brain a bit. Reversi looks like a simply game, where mobility has a profound effect on game play. It is at least a step up from tic tac toe. This would be a single player against an AI of some sort.

我一直在考虑在家开始一个侧面项目来锻炼我的大脑。黑白棋看起来像一个简单的游戏,其中移动性对游戏玩法有深远的影响。这至少比tic tac toe更进了一步。这将是针对某种AI的单一玩家。

I am thinking to try this in C++ on a PC.

我想在PC上用C ++试试这个。

What issues am I likely to run into?

我可能遇到什么问题?

What graphics library would you recommend?

你会推荐什么图形库?

What questions am I not smart enough to ask myself?

我有什么问题不够聪明地问自己?

9 个解决方案

#1


2  

In overall, issues you will end up running onto will depend on you and your approaches. Friend tends to say that complex is simple from different perspective.

总的来说,您最终会遇到的问题将取决于您和您的方法。朋友倾向于从不同的角度说复杂是简单的。

Choice of graphics library depends about what kind of game you are going to write? OpenGL is common choice in this kind of projects, but you could also use some GUI-library or directly just use windows' or xorg's own libraries. If you are going to do fancy, just use OpenGL.

图形库的选择取决于你要写什么样的游戏? OpenGL是这类项目的常见选择,但你也可以使用一些GUI库或直接使用windows'或xorg自己的库。如果你打算花哨,只需使用OpenGL。

Questions you ought ask:

你应该问的问题:

Is C++ sensible choice for this project? Consider C and/or python as well. My answer to this would be that if you just want to write reversi, go python. But if you want to learn a low level language, do C first. C++ is an extension to C, therefore there's more to learn in there than there's in C. And to my judge, the more you have to learn onto C++ is not worth the effort.

C ++是否适合这个项目?考虑C和/或python。我对此的回答是,如果你只想写反转,请转到python。但是如果你想学习低级语言,首先要做C。 C ++是C语言的扩展,因此在C中学习的内容比在C语言中有更多。而且根据我的判断,你学习C ++的次数越多越不值得。

How do you use the graphics library? If you are going to do fancy effects, go to the scene graph. Instead you can just render the reversi grid with buttons on it.

你如何使用图形库?如果您要进行奇特的效果,请转到场景图。相反,您可以使用按钮在其上渲染reversi网格。

How ought you implement the UI, should you use the common UI concepts? Usual UI concepts (windowing, frames, buttons, menubars, dialogs) aren't so good as people think they are, there's lot of work in implementing them properly. Apply the scene graph for interpreting input and try different clever ways onto controlling the game. Avoid intro menus(they are dumb and useless work), use command line arguments for most configuration.

如果您使用常见的UI概念,您应该如何实现UI?通常的UI概念(窗口,框架,按钮,菜单栏,对话框)并不像人们认为的那样好,在正确实现它们方面有很多工作要做。应用场景图解释输入并尝试不同的巧妙方法来控制游戏。避免使用简介菜单(它们是愚蠢无用的工作),对大多数配置使用命令行参数。

I yet give you some ideas to get you started:

我还给你一些想法让你入门:

Othello board is 8x8, 64 cells in overall. You can assign a byte per each cell, that makes it 64 bytes per each board state. It's 8 long ints, not very much at all! You can store the whole progress of the game and the player can't even notice it. Therefore it's advised to implement the othello board as an immutable structure which you copy always when you change a state. It will also help you later with your AI and implementing an 'undo' -feature.

奥赛罗板总体上是8x8,64个单元。您可以为每个单元分配一个字节,使每个单元状态为64字节。这是8个长的整数,根本不是很多!您可以存储游戏的整个进度,玩家甚至无法注意到它。因此,建议将othello板作为不可变结构实现,当您更改状态时,您始终会复制该结构。它还可以帮助您以后使用AI并实现“撤消”功能。

Because one byte can store more information than just three states (EMPTY, BLACK, WHITE), I advice you will also provide two additional states (BLACK_ALLOWED, WHITE_ALLOWED, BOTH_ALLOWED). You can calculate these values while you copy the new state.

因为一个字节可以存储比三个状态(EMPTY,BLACK,WHITE)更多的信息,我建议你还提供两个额外的状态(BLACK_ALLOWED,WHITE_ALLOWED,BOTH_ALLOWED)。您可以在复制新状态时计算这些值。

Algorithm for checking out where you can put a block, could go the board through one by one, then trace from empty cells to every direction for regex-patterns: B+W => W^, W+B => B^ This way you can encapsulate the game rules inside a simple interface that takes care of it all.

用于检查可以放置块的位置的算法,可以一个接一个地通过板,然后从空单元跟踪到正则表达式的每个方向:B + W => W ^,W + B => B ^这种方式您可以将游戏规则封装在一个简单的界面中,该界面可以完成所有操作。

#2


3  

Issues...

Well, just be sure when writing the strategy part of the game, not to simply do the move that gives you the most pieces. You must also give weight to board position. For example, given the opportunity to place a piece in a board corner should take priority over any other move (besides winning the game) as that piece can never be turned back over. And, placing a piece adjacent to a corner spot is just about the worst move you can ever make (if the corner space is open).

好吧,只要确保在编写游戏的策略部分时,不要只是简单地做一些能给你最多的动作。你还必须给予董事会职位权重。例如,如果有机会将棋子置于棋盘角落,则应优先于任何其他动作(除了赢得比赛),因为该棋子永远不会被翻过来。并且,在角落附近放置一块是您可以制作的最糟糕的移动(如果角落空间是打开的)。

Hope this helps!

希望这可以帮助!

#3


2  

As the guys were suggesting my idea of telling you for thinking first for algorithms and the game logic. next answer for me was the graphics library, it depends on your target platform, programming language, framework etc. But as I suggest is using C# with Cairo 2D graphics library which you can achieve this using Mono framework (which then you can target all three major operating systems for your game to work) -> www.mono-project.org. Meanwhile I found this I think that and this kind of resource will help you: http://home.datacomm.ch/t_wolf/tw/misc/reversi/html/index.html. But if you finish this, you can try implementing Sudoku.

正如这些家伙建议我的想法,告诉你首先考虑算法和游戏逻辑。下一个答案对我来说是图形库,它取决于你的目标平台,编程语言,框架等。但正如我建议使用C#与开罗2D图形库,你可以使用Mono框架实现这一点(然后你可以针对所有三个您的游戏的主要操作系统) - > www.mono-project.org。同时我发现了这一点,我认为这种资源可以帮到你:http://home.datacomm.ch/t_wolf/tw/misc/reversi/html/index.html。但如果你完成了这个,你可以尝试实现数独。

#4


2  

As mentioned by others, I would begin by getting a deep understanding of the gameplay and strategies, and the algorithms involved. This link may be useful to you, it describes basic Othello strategy and algorithms:

正如其他人所提到的,我首先要深入了解游戏玩法和策略,以及所涉及的算法。此链接可能对您有用,它描述了基本的奥赛罗策略和算法:

http://www.site-constructor.com/othello/Present/Basic_Strategy.html

#5


2  

You will want to look into minimax with alpha-beta pruning if you write an AI to play against. Your favorite search engine will have much to say on the topic.

如果你编写一个AI来对抗,你会想要用alpha-beta修剪来研究minimax。您最喜欢的搜索引擎将对该主题有很多话要说。

#6


2  

After you've taken a whack at the game logic yourself, go read chapter 18 of Peter Norvig's outstanding book Paradigms of AI Programming. (Source code here.) It has a rather short and extremely readable program that can kick just about any human's butt; you ought to learn a lot by comparing your solution to it.

在你自己对游戏逻辑进行了重击之后,请阅读Peter Norvig出版的“人工智能编程范例”第18章。 (源代码在这里。)它有一个相当简短和极易阅读的程序,可以踢任何人的屁股;你应该通过比较你的解决方案来学到很多东西。

#7


1  

There are tons of libraries out there but as far as I can think your game is going to need event and graphics libraries....and a sound library for more fun! Allegro 5 is a best choice...Its an All in one library. http://liballeg.org/ though It is written in C language you can create Object Oriented programs.

那里有大量的图书馆,但据我所知,你的游戏将需要事件和图形库......以及一个更有趣的声音库! Allegro 5是最佳选择......它是一个多功能的库。 http://liballeg.org/虽然它是用C语言编写的,但您可以创建面向对象的程序。

and A tutorial for this...

和这个教程......

http://fixbyproximity.com/2d-game-development-course/

or you can use low level APIs like.. OpenGL for graphics. OpenAL for sound. glfw for events.

或者您可以使用低级API,例如OpenGL用于图形。 OpenAL声音。 glfw为事件。

but OpenGL is a big deal because you have to create your own sprite sheet handler and all that 2d stuff.

但OpenGL是一个大问题,因为你必须创建自己的精灵表处理程序和所有2d的东西。

Go with allegro...Complete your game and then go for OpenGL!

和allegro一起去...完成你的游戏然后去OpenGL吧!

#8


0  

Reversi should be a very simple game to implement. It is perfect to learn some basic algorithms of games theory (specifically min-max) during the implementation of the AI.

黑白棋应该是一个非常简单的游戏来实现。在AI的实现过程中学习一些基本的游戏理论算法(特别是min-max)是完美的。

One thing to note on the AI is that it is perfectly possible to make a perfect AI for Reversi (one that always wins no matter the moves of its opponent). So on the strategy side, if your AI loses, you still have work to do :)

人工智能有一点需要注意的是,完全可以为黑白棋做一个完美的人工智能(无论对手的动作如何,它都能获胜)。所以在战略方面,如果你的AI输了,你还有工作要做:)

#9


0  

I wrote a reversi game many years ago, when I was still at school. Its strategy was very simple, it just went for the maximum number of pieces, but weighted so it preferred the edges and particularly the corners and didn't like squares that risked giving away the corners.

很多年前,当我还在上学的时候,我写了一个逆转游戏。它的策略非常简单,它只是最大数量的棋子,但加权所以它更喜欢边缘,特别是角落,并不喜欢有可能放弃角落的方格。

This worked fairly well against people who hadn't yet worked out what it was doing, but once you had it was very easy to use its strategy against it. I'm not proud to say, however, that it beat me the first few times even though I'd written it!

这对那些还没有弄清楚它在做什么的人来说效果相当不错,但是一旦你有了它,就很容易使用它的策略。然而,我并不自豪地说,即使我写了它,它在前几次击败了我!

A proper AI with a few moves of lookahead is far more complicated. Should be an interesting problem, but at the time I was more interested in the user interface.

一个适当的人工智能有一些前瞻性的动作要复杂得多。应该是一个有趣的问题,但当时我对用户界面更感兴趣。

#1


2  

In overall, issues you will end up running onto will depend on you and your approaches. Friend tends to say that complex is simple from different perspective.

总的来说,您最终会遇到的问题将取决于您和您的方法。朋友倾向于从不同的角度说复杂是简单的。

Choice of graphics library depends about what kind of game you are going to write? OpenGL is common choice in this kind of projects, but you could also use some GUI-library or directly just use windows' or xorg's own libraries. If you are going to do fancy, just use OpenGL.

图形库的选择取决于你要写什么样的游戏? OpenGL是这类项目的常见选择,但你也可以使用一些GUI库或直接使用windows'或xorg自己的库。如果你打算花哨,只需使用OpenGL。

Questions you ought ask:

你应该问的问题:

Is C++ sensible choice for this project? Consider C and/or python as well. My answer to this would be that if you just want to write reversi, go python. But if you want to learn a low level language, do C first. C++ is an extension to C, therefore there's more to learn in there than there's in C. And to my judge, the more you have to learn onto C++ is not worth the effort.

C ++是否适合这个项目?考虑C和/或python。我对此的回答是,如果你只想写反转,请转到python。但是如果你想学习低级语言,首先要做C。 C ++是C语言的扩展,因此在C中学习的内容比在C语言中有更多。而且根据我的判断,你学习C ++的次数越多越不值得。

How do you use the graphics library? If you are going to do fancy effects, go to the scene graph. Instead you can just render the reversi grid with buttons on it.

你如何使用图形库?如果您要进行奇特的效果,请转到场景图。相反,您可以使用按钮在其上渲染reversi网格。

How ought you implement the UI, should you use the common UI concepts? Usual UI concepts (windowing, frames, buttons, menubars, dialogs) aren't so good as people think they are, there's lot of work in implementing them properly. Apply the scene graph for interpreting input and try different clever ways onto controlling the game. Avoid intro menus(they are dumb and useless work), use command line arguments for most configuration.

如果您使用常见的UI概念,您应该如何实现UI?通常的UI概念(窗口,框架,按钮,菜单栏,对话框)并不像人们认为的那样好,在正确实现它们方面有很多工作要做。应用场景图解释输入并尝试不同的巧妙方法来控制游戏。避免使用简介菜单(它们是愚蠢无用的工作),对大多数配置使用命令行参数。

I yet give you some ideas to get you started:

我还给你一些想法让你入门:

Othello board is 8x8, 64 cells in overall. You can assign a byte per each cell, that makes it 64 bytes per each board state. It's 8 long ints, not very much at all! You can store the whole progress of the game and the player can't even notice it. Therefore it's advised to implement the othello board as an immutable structure which you copy always when you change a state. It will also help you later with your AI and implementing an 'undo' -feature.

奥赛罗板总体上是8x8,64个单元。您可以为每个单元分配一个字节,使每个单元状态为64字节。这是8个长的整数,根本不是很多!您可以存储游戏的整个进度,玩家甚至无法注意到它。因此,建议将othello板作为不可变结构实现,当您更改状态时,您始终会复制该结构。它还可以帮助您以后使用AI并实现“撤消”功能。

Because one byte can store more information than just three states (EMPTY, BLACK, WHITE), I advice you will also provide two additional states (BLACK_ALLOWED, WHITE_ALLOWED, BOTH_ALLOWED). You can calculate these values while you copy the new state.

因为一个字节可以存储比三个状态(EMPTY,BLACK,WHITE)更多的信息,我建议你还提供两个额外的状态(BLACK_ALLOWED,WHITE_ALLOWED,BOTH_ALLOWED)。您可以在复制新状态时计算这些值。

Algorithm for checking out where you can put a block, could go the board through one by one, then trace from empty cells to every direction for regex-patterns: B+W => W^, W+B => B^ This way you can encapsulate the game rules inside a simple interface that takes care of it all.

用于检查可以放置块的位置的算法,可以一个接一个地通过板,然后从空单元跟踪到正则表达式的每个方向:B + W => W ^,W + B => B ^这种方式您可以将游戏规则封装在一个简单的界面中,该界面可以完成所有操作。

#2


3  

Issues...

Well, just be sure when writing the strategy part of the game, not to simply do the move that gives you the most pieces. You must also give weight to board position. For example, given the opportunity to place a piece in a board corner should take priority over any other move (besides winning the game) as that piece can never be turned back over. And, placing a piece adjacent to a corner spot is just about the worst move you can ever make (if the corner space is open).

好吧,只要确保在编写游戏的策略部分时,不要只是简单地做一些能给你最多的动作。你还必须给予董事会职位权重。例如,如果有机会将棋子置于棋盘角落,则应优先于任何其他动作(除了赢得比赛),因为该棋子永远不会被翻过来。并且,在角落附近放置一块是您可以制作的最糟糕的移动(如果角落空间是打开的)。

Hope this helps!

希望这可以帮助!

#3


2  

As the guys were suggesting my idea of telling you for thinking first for algorithms and the game logic. next answer for me was the graphics library, it depends on your target platform, programming language, framework etc. But as I suggest is using C# with Cairo 2D graphics library which you can achieve this using Mono framework (which then you can target all three major operating systems for your game to work) -> www.mono-project.org. Meanwhile I found this I think that and this kind of resource will help you: http://home.datacomm.ch/t_wolf/tw/misc/reversi/html/index.html. But if you finish this, you can try implementing Sudoku.

正如这些家伙建议我的想法,告诉你首先考虑算法和游戏逻辑。下一个答案对我来说是图形库,它取决于你的目标平台,编程语言,框架等。但正如我建议使用C#与开罗2D图形库,你可以使用Mono框架实现这一点(然后你可以针对所有三个您的游戏的主要操作系统) - > www.mono-project.org。同时我发现了这一点,我认为这种资源可以帮到你:http://home.datacomm.ch/t_wolf/tw/misc/reversi/html/index.html。但如果你完成了这个,你可以尝试实现数独。

#4


2  

As mentioned by others, I would begin by getting a deep understanding of the gameplay and strategies, and the algorithms involved. This link may be useful to you, it describes basic Othello strategy and algorithms:

正如其他人所提到的,我首先要深入了解游戏玩法和策略,以及所涉及的算法。此链接可能对您有用,它描述了基本的奥赛罗策略和算法:

http://www.site-constructor.com/othello/Present/Basic_Strategy.html

#5


2  

You will want to look into minimax with alpha-beta pruning if you write an AI to play against. Your favorite search engine will have much to say on the topic.

如果你编写一个AI来对抗,你会想要用alpha-beta修剪来研究minimax。您最喜欢的搜索引擎将对该主题有很多话要说。

#6


2  

After you've taken a whack at the game logic yourself, go read chapter 18 of Peter Norvig's outstanding book Paradigms of AI Programming. (Source code here.) It has a rather short and extremely readable program that can kick just about any human's butt; you ought to learn a lot by comparing your solution to it.

在你自己对游戏逻辑进行了重击之后,请阅读Peter Norvig出版的“人工智能编程范例”第18章。 (源代码在这里。)它有一个相当简短和极易阅读的程序,可以踢任何人的屁股;你应该通过比较你的解决方案来学到很多东西。

#7


1  

There are tons of libraries out there but as far as I can think your game is going to need event and graphics libraries....and a sound library for more fun! Allegro 5 is a best choice...Its an All in one library. http://liballeg.org/ though It is written in C language you can create Object Oriented programs.

那里有大量的图书馆,但据我所知,你的游戏将需要事件和图形库......以及一个更有趣的声音库! Allegro 5是最佳选择......它是一个多功能的库。 http://liballeg.org/虽然它是用C语言编写的,但您可以创建面向对象的程序。

and A tutorial for this...

和这个教程......

http://fixbyproximity.com/2d-game-development-course/

or you can use low level APIs like.. OpenGL for graphics. OpenAL for sound. glfw for events.

或者您可以使用低级API,例如OpenGL用于图形。 OpenAL声音。 glfw为事件。

but OpenGL is a big deal because you have to create your own sprite sheet handler and all that 2d stuff.

但OpenGL是一个大问题,因为你必须创建自己的精灵表处理程序和所有2d的东西。

Go with allegro...Complete your game and then go for OpenGL!

和allegro一起去...完成你的游戏然后去OpenGL吧!

#8


0  

Reversi should be a very simple game to implement. It is perfect to learn some basic algorithms of games theory (specifically min-max) during the implementation of the AI.

黑白棋应该是一个非常简单的游戏来实现。在AI的实现过程中学习一些基本的游戏理论算法(特别是min-max)是完美的。

One thing to note on the AI is that it is perfectly possible to make a perfect AI for Reversi (one that always wins no matter the moves of its opponent). So on the strategy side, if your AI loses, you still have work to do :)

人工智能有一点需要注意的是,完全可以为黑白棋做一个完美的人工智能(无论对手的动作如何,它都能获胜)。所以在战略方面,如果你的AI输了,你还有工作要做:)

#9


0  

I wrote a reversi game many years ago, when I was still at school. Its strategy was very simple, it just went for the maximum number of pieces, but weighted so it preferred the edges and particularly the corners and didn't like squares that risked giving away the corners.

很多年前,当我还在上学的时候,我写了一个逆转游戏。它的策略非常简单,它只是最大数量的棋子,但加权所以它更喜欢边缘,特别是角落,并不喜欢有可能放弃角落的方格。

This worked fairly well against people who hadn't yet worked out what it was doing, but once you had it was very easy to use its strategy against it. I'm not proud to say, however, that it beat me the first few times even though I'd written it!

这对那些还没有弄清楚它在做什么的人来说效果相当不错,但是一旦你有了它,就很容易使用它的策略。然而,我并不自豪地说,即使我写了它,它在前几次击败了我!

A proper AI with a few moves of lookahead is far more complicated. Should be an interesting problem, but at the time I was more interested in the user interface.

一个适当的人工智能有一些前瞻性的动作要复杂得多。应该是一个有趣的问题,但当时我对用户界面更感兴趣。