Click here to Skip to main content
15,891,253 members
Articles / Mobile Apps

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.7K   4.4K   36  
A C# implementation of Reversi (Othello) Game for PocketPC and Windows.
using System;
using System.Collections;	
using System.Collections.Specialized;
using System.Windows.Forms;


namespace gma.Reversi 
{
	/// <summary>
	/// Zusammenfassung f�r VirtualPlayerComplex.
	/// </summary>
		public class VirtualPlayerComplex: VirtualPlayer
	{
		public VirtualPlayerComplex(BoardComplex aBoard):base(aBoard)
		{

		}


		private const int SHALLOW_DEPTH=2;
		protected IList ShallowSearchMiniMaxAB(Board aBoard)
		{
			SortedList  sortedAvailableMoves = new SortedList();
			IList Points_list = aBoard.GetAvailableMoves(PlayerColor);
			if (Points_list.Count > 0)
			{
				int currentScore;
				Point aPoint = gma.Reversi.Board.NOMOVE;
				
				foreach (Point aMove in Points_list)
				{
					Application.DoEvents();
					Board new_board = aBoard.Clone();
					new_board.Play(aMove, aBoard.CurrentPlayer,false);
					currentScore = -MiniMaxAB(new_board, this.MAX_DEPTH-SHALLOW_DEPTH , int.MinValue, int.MaxValue);
					while (sortedAvailableMoves.ContainsKey(currentScore))
						currentScore--;
						
					sortedAvailableMoves.Add(currentScore, aMove);
				}
			}
			return sortedAvailableMoves.GetValueList();
		}

		protected override Point MiniMaxAB(BoardComplex aBoard)
		{
			IList  sortedAvailableMoves=ShallowSearchMiniMaxAB(aBoard);
			return MiniMaxAB(aBoard, sortedAvailableMoves);
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

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