예제 #1
0
        public BoardForm(ChessGame game)
        {
            InitializeComponent();

            Game = game;
            BoardImage = new Bitmap(240, 240, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
        }
예제 #2
0
 private void Game_ResultChanged(ChessGame game, GameResult result)
 {
     string s = String.Empty;
     switch (result)
     {
         case GameResult.BlackCheckMate:
             s = "Black check mate";
             break;
         case GameResult.WhiteCheckMate:
             s = "White check mate";
             break;
         case GameResult.BlackKingTaken:
             s = "Black lost";
             break;
         case GameResult.WhiteKingTaken:
             s = "White lost";
             break;
         case GameResult.StaleMate:
             s = "Stale mate";
             break;
         case GameResult.BlackResigned:
             s = "Black resigned";
             break;
         case GameResult.WhiteResigned:
             s = "White resigned";
             break;
         case GameResult.Draw:
             s = "Draw";
             break;
     }
     if (s != String.Empty)
     {
         this.BoardForm.ShowResult(s);
     }
 }
예제 #3
0
        private void StartGameButton_Click(object sender, EventArgs e)
        {
            this.Game = new ChessGame();
            if (!String.IsNullOrEmpty(fileToLoad))
            {
                this.Game.Board.LoadFromFile(fileToLoad);
            }
            ChessPiece computerSuit;
            if (WhiteRadioButton.Checked)
            {
                this.Game.PlayerTypes[ChessPiece.White] = PlayerType.Human;
                this.Game.PlayerTypes[ChessPiece.Black] = PlayerType.Computer;
                computerSuit = ChessPiece.Black;
            }
            else
            {
                this.Game.PlayerTypes[ChessPiece.White] = PlayerType.Computer;
                this.Game.PlayerTypes[ChessPiece.Black] = PlayerType.Human;
                computerSuit = ChessPiece.White;
            }

            this.Visualizer = new BasicVisualizer.BasicVizualizer();
            this.Visualizer.Init(this.Game);
            var engine = new ChessEngines.AlphaBeta();
            engine.LoggingEnabled = true;
            string logFileName = DateTime.Now.ToString("LOG_yyyy-MM-dd_HH-mm-ss") + ".txt";
            engine.LogFilePath = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), logFileName);
            this.ChessEngine = engine;
            this.Game.Engine = this.ChessEngine;
            this.ChessEngine.Init(this.Game.Board, computerSuit, true);

            // Start game
            this.Game.Start();
        }
예제 #4
0
        public void Init(ChessGame game)
        {
            this.Game = game;
            this.BoardForm = new BoardForm(Game);
            this.BoardForm.Show();
            this.BoardForm.DrawGame();

            this.Game.BoardChanged += Game_BoardChanged;
            this.Game.NumberChanged += Game_NumberChanged;
            this.Game.ExecutionTimeUpdated += Game_ExecutionTimeUpdated;
            this.Game.ResultChanged += Game_ResultChanged;
        }
예제 #5
0
 private void Game_BoardChanged(ChessGame game)
 {
     Redraw();
 }