Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How would you go about implementing the game reversi? (othello)

Tags:

c++

graphics

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.

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

What issues am I likely to run into?

What graphics library would you recommend?

What questions am I not smart enough to ask myself?

like image 492
EvilTeach Avatar asked Oct 14 '08 00:10

EvilTeach


People also ask

What is the strategy for Reversi?

A key Reversi strategy is flanking your opponent's pieces. If you can get a piece at each end of a row or column (straight or diagonally) then every piece in the row between your two pieces is captured. By mastering flanking, you can take multiple rows of pieces per turn.

What is the goal of the game Reversi?

Rules of Reversi Pieces typically appear coin-like, with a light and a dark face, each side representing one player. The goal for each player is to make pieces of their colour constitute a majority of the pieces on the board at the end of the game, by turning over as many of their opponent's pieces as possible.


3 Answers

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!

like image 125
BoltBait Avatar answered Nov 15 '22 07:11

BoltBait


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.

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.

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.

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.

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.

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.

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.

like image 29
Cheery Avatar answered Nov 15 '22 07:11

Cheery


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.

like image 42
milot Avatar answered Nov 15 '22 06:11

milot