Click here to Skip to main content
15,893,266 members
Articles / Programming Languages / C#

Simple AI for the Game of Breakthrough

Rate me:
Please Sign up or sign in to vote.
5.00/5 (11 votes)
5 Jun 2009LGPL39 min read 65.6K   3.7K   39  
This article presents an implementation of a simple alpha-beta player for the board game of Breakthrough.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using Breakthrough.Game.Engine;

namespace Breakthrough.Client.Components
{
    public partial class InfoPanel : UserControl
    {
        private ChessBoard board;
        public ChessBoard Board
        {
            get { return board; }
            set { 
                board = value;
                if(board!= null)
                    board.TurnChanged += new ChessBoard.TurnChangedHandler(Board_TurnChanged);
            }
        }

        void Board_TurnChanged(GamePieceColor whosMove)
        {
            var history = board.engine.MoveHistory;
            HistoryList.Items.Clear();
            var array = history.ToArray();
            for (int i = array.Length-1; i >= 0; i--)
                HistoryList.Items.Add(array[i]);
        }

        public InfoPanel()
        {
            InitializeComponent();
        }


        #region Helpers
        internal static string GetColumnFromByte(byte column)
        {
            switch (column)
            {
                case 0:
                    return "a";
                case 1:
                    return "b";
                case 2:
                    return "c";
                case 3:
                    return "d";
                case 4:
                    return "e";
                case 5:
                    return "f";
                case 6:
                    return "g";
                case 7:
                    return "h";
                default:
                    return "a";
            }
        }

        private static byte GetRow(byte position) { return (byte)(7 - (position >> 3)); }
        private static byte GetColumn(byte position) { return (byte)(position % 8); }
        private static int GetPosition(int column, int row) { return ((7 - row) << 3) + column; }
        #endregion
    }
}

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, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)


Written By
Chief Technology Officer Misakai Ltd.
Ireland Ireland
Roman Atachiants, Ph.D. is the architect behind emitter.io service, a real-time, low-latency publish/subscribe service for IoT, Gaming. He is a software engineer and scientist with extensive experience in different computer science domains, programming languages/principles/patterns & frameworks.

His main expertise consists of C# and .NET platform, game technologies, cloud, human-computer interaction, big data and artificial intelligence. He has an extensive programming knowledge and R&D expertise.



Comments and Discussions