Click here to Skip to main content
15,867,785 members
Articles / Mobile Apps
Article

A C# implementation of Reversi (Othello) Game for PocketPC and Windows

Rate me:
Please Sign up or sign in to vote.
4.75/5 (13 votes)
4 Aug 20043 min read 91.3K   4.4K   36   13
A C# implementation of Reversi (Othello) Game for PocketPC and Windows.

Sample Image - PocketReversi.jpg

Introduction

My initial goal was to port Reversi in C# By BrainJar 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. There are two different Presentation Layers using the same assembly; the gma.Windows.Reversi for Windows .NET and gam.Mobile.Reversi 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 Players are connected.

Game Theory

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 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, 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 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:

  1. Dominance. It is good to own squares as an opponent.
  2. Mobility. It is good when you have more move alternatives.
  3. Disk-square table. Corners are good and the squares next to corners are bad.
  4. 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.

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


Written By
Software Developer
Germany Germany
Tweeter: @gmamaladze
Google+: gmamaladze
Blog: gmamaladze.wordpress.com

Comments and Discussions

 
GeneralQuestion .atlapp.h Pin
sima_m29-Dec-08 1:06
sima_m29-Dec-08 1:06 
GeneralAn urgent help! Pin
Smashing_Blizzard23-Jun-07 9:45
Smashing_Blizzard23-Jun-07 9:45 
AnswerRe: An urgent help! Pin
George Mamaladze24-Jun-07 21:57
George Mamaladze24-Jun-07 21:57 
Questionhelp Pin
kgopa24-Aug-06 0:45
kgopa24-Aug-06 0:45 
QuestionRe: help Pin
George Mamaladze24-Aug-06 1:17
George Mamaladze24-Aug-06 1:17 
QuestionRe: help Pin
kgopa24-Aug-06 3:29
kgopa24-Aug-06 3:29 
GeneralMulti Person Game Pin
dvadim27-Apr-06 6:40
dvadim27-Apr-06 6:40 
GeneralNice article ! Pin
ddmcr10-Jun-05 2:34
ddmcr10-Jun-05 2:34 
GeneralRe: Nice article ! Pin
George Mamaladze10-Jun-05 2:42
George Mamaladze10-Jun-05 2:42 
QuestionSorry, can help me?? Pin
fire8524-May-05 17:19
fire8524-May-05 17:19 
AnswerRe: Sorry, can help me?? Pin
George Mamaladze24-May-05 21:41
George Mamaladze24-May-05 21:41 
GeneralRe: Sorry, can help me?? Pin
fire8529-May-05 15:34
fire8529-May-05 15:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.