Click here to Skip to main content
Click here to Skip to main content
Go to top

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

, 4 Aug 2004
Rate this:
Please Sign up or sign in to vote.
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

Share

About the Author

George Mamaladze
Software Developer
Germany Germany
Tweeter: @gmamaladze
Google+: gmamaladze
Blog: gmamaladze.wordpress.com
Follow on   Twitter

Comments and Discussions

 
SuggestionThanks. Check out another one Reversi implementation in C# PinmemberMember 471378518-Jun-12 20:09 
GeneralQuestion .atlapp.h Pinmembersima_m29-Dec-08 1:06 
GeneralAn urgent help! PinmemberSmashing_Blizzard23-Jun-07 9:45 
AnswerRe: An urgent help! PinmemberGeorge Mamaladze24-Jun-07 21:57 
Questionhelp Pinmemberkgopa24-Aug-06 0:45 
QuestionRe: help PinmemberGeorge Mamaladze24-Aug-06 1:17 
QuestionRe: help Pinmemberkgopa24-Aug-06 3:29 
here is a question:
 
The board's initial setup contains 2 X's on the bottom corners of the board and
2 circles on the top corners of the board.
Player one will be circles and player two will be X's. Player one begins by
putting a circle in a square adjacent to where there is already a circle. If
there are any X's in adjoining squares to where player 1 puts the circle, those
X's become circles. Then player two does the same with X's. The game is won if
one player eliminates the other player entirely, or by having the most X's or
circles when every square on the board is filled.
GeneralMulti Person Game Pinmemberdvadim27-Apr-06 6:40 
GeneralNice article ! Pinmember Giorgi Moniava10-Jun-05 2:34 
GeneralRe: Nice article ! PinmemberGeorge Mamaladze10-Jun-05 2:42 
QuestionSorry, can help me?? Pinmemberfire8524-May-05 17:19 
AnswerRe: Sorry, can help me?? PinmemberGeorge Mamaladze24-May-05 21:41 
GeneralRe: Sorry, can help me?? Pinmemberfire8529-May-05 15:34 

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

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

| Advertise | Privacy | Mobile
Web02 | 2.8.140905.1 | Last Updated 5 Aug 2004
Article Copyright 2004 by George Mamaladze
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid