コード例 #1
0
 void CancelInteraction()
 {
     if (_interaction != null)
     {
         _interaction.Cancel();
     }
     _interaction = null;
 }
コード例 #2
0
        void PrepareTurn()
        {
            _interaction = null;
            CancelTool();
            int playerID = _game.Ply & 1;

            lblAiLevel.Text  = string.Format("Player {0} AI:", 1 + playerID);
            _aiLevelUpdating = true;
            if (!_aiLevels[playerID].HasValue)
            {
                listAiLevel.SelectedIndex = 0;
            }
            else
            {
                listAiLevel.SelectedItem = listAiLevel.Items.Cast <string>().FirstOrDefault(x => x.EndsWith(_aiLevels[playerID].ToString()));
            }
            _aiLevelUpdating = false;
            UpdateTools();

            int  eval;
            bool gameOver;

            _evaluator.Evaluate(_game, out eval, out gameOver);
            if (gameOver)
            {
                SetResultCode(eval);
                _interaction = null;
                if (eval == 0)
                {
                    lblStatus.Text = "Game over, it's a tie!";
                }
                else
                {
                    lblStatus.Text = string.Format("Game over, player {0} wins!", eval > 0 ? 1 : 2);
                }
                tablePanel.Enabled  = false;
                miMoveEnter.Enabled = false;
            }
            else
            {
                lblStatus.Text = string.Format("Player {0}'s move (turn {1})",
                                               1 + (_game.Ply & 1),
                                               DescribeTurn(_game.Ply));
                tablePanel.Enabled  = true;
                miMoveEnter.Enabled = true;
            }
            UpdateToolbar();
            CheckStartAI();
        }
コード例 #3
0
        void Navigate(int ply)
        {
            if (_aiRunning)
            {
                return;
            }
            if (ply < 0 || ply >= _gameRecord.MoveNotations.Count)
            {
                return;
            }
            _navigating = true;
            CancelTool();
            _interaction = null;
            _game.Clear();
            for (int i = 0; i <= ply; i++)
            {
                var   notation = _gameRecord.MoveNotations[i];
                IMove move;
                if (!_movesOfNotation.TryGetValue(notation, out move))
                {
                    throw new ApplicationException("Critical movement error");
                }
                move.MakeMove(_game);
                _game.Ply++;
            }
            _boardView.InvalidateRender();
            if (_historyForm != null)
            {
                _historyForm.SelectedPly = ply;
            }
            _navigating = false;

            if (_game.Ply < _gameRecord.MoveNotations.Count)
            {
                lblStatus.Text      = string.Concat("Viewing turn ", DescribeTurn(ply));
                listAiLevel.Enabled = false;
                btnUndo.Enabled     = false;
                tablePanel.Enabled  = false;
                miMoveEnter.Enabled = false;
            }
            else
            {
                listAiLevel.Enabled = true;
                PrepareTurn();
            }
        }
コード例 #4
0
        void SetActiveTool(PieceToolInfo tool)
        {
            if (_activeTool != null)
            {
                _activeTool.Btn.BackColor = Color.Transparent;
                _activeTool = null;
            }

            CancelInteraction();

            _activeTool = tool;
            if (_activeTool != null)
            {
                _activeTool.Btn.BackColor = Color.LightCyan;
                _interaction = new InteractiveMove_PlaceFromReserve(_game, _boardView, _activeTool.PieceID);
            }
            else
            {
                _interaction = new InteractiveMove_PickupAndPlace(_game, _boardView);
            }
        }