Beispiel #1
0
        public void Submit(QuantumChessMove move)
        {
            if (move.ActorPlayer != ActivePlayer_)
            {
                MoveProcessException.Throw("Waiting for another player's move");
            }

            if (move is CapitulateMove)
            {
                QuantumChessboard_.RegisterVictory(PlayerUtils.InvertPlayer(ActivePlayer_));
                LastMovePositions_ = new Position[0];
            }
            else if (move is AgreeToTieMove)
            {
                QuantumChessboard_.RegisterTie();
                LastMovePositions_ = new Position[0];
            }
            else if (move is OrdinaryMove)
            {
                var omove = move as OrdinaryMove;
                if (QuantumChessboard_.CheckOrdinaryMoveApplicable(omove))
                {
                    QuantumChessboard_.ApplyOrdinaryMove(omove);
                    ActivePlayer_      = PlayerUtils.InvertPlayer(ActivePlayer_);
                    LastMovePositions_ = new Position[] { omove.Source, omove.Target };
                }
                else
                {
                    MoveProcessException.Throw("Move is inapplicable on all harmonics");
                }
            }
            else if (move is QuantumMove)
            {
                var qmove = move as QuantumMove;
                if (QuantumChessboard_.CheckQuantumMoveApplicable(qmove))
                {
                    QuantumChessboard_.ApplyQuantumMove(qmove);
                    ActivePlayer_ = PlayerUtils.InvertPlayer(ActivePlayer_);
                    if (qmove.Middle.HasValue)
                    {
                        LastMovePositions_ = new Position[] { qmove.Source, qmove.Middle.Value, qmove.Target }
                    }
                    ;
                    else
                    {
                        LastMovePositions_ = new Position[] { qmove.Source, qmove.Target }
                    };
                }
                else
                {
                    MoveProcessException.Throw("Quantum move is inapplicable on all harmonics");
                }
            }
            else if (move is CastleMove)
            {
                var cmove = move as CastleMove;
                if (QuantumChessboard_.CheckCastleMoveApplicable(cmove))
                {
                    QuantumChessboard_.ApplyCastleMove(cmove);
                    ActivePlayer_ = PlayerUtils.InvertPlayer(ActivePlayer_);
                    int c = cmove.ActorPlayer == Player.White ? 0 : 7;
                    LastMovePositions_    = new Position[2];
                    LastMovePositions_[0] = Position.FromCoords(4, c);
                    if (cmove.CastleType == CastleType.Left)
                    {
                        LastMovePositions_[1] = Position.FromCoords(0, c);
                    }
                    else
                    {
                        LastMovePositions_[1] = Position.FromCoords(7, c);
                    }
                }
                else
                {
                    MoveProcessException.Throw("Castle is inapplicable on all harmonics");
                }
            }
            else
            {
                AssertionException.Assert(false, $"Unsupported move type: {move.GetType().Name}");
            }
        }