Esempio n. 1
0
        public static void Main(string[] args)
        {
            int cols = 8;

            if (args.Length >= 1)
            {
                cols = Convert.ToInt32(args[0]);
            }

            var engine = new QuantumChessEngine();

            for (;;)
            {
                Output.DisplayQuantumChessboard(engine.QuantumChessboard, cols);
                Console.WriteLine();

                for (;;)
                {
                    try {
                        QuantumChessMove move = Input.ReadMoveRepeated(engine);
                        engine.Submit(move);
                        break;
                    } catch (MoveParseException e) {
                        Console.WriteLine(e.Message);
                    } catch (MoveProcessException e) {
                        Console.WriteLine(e.Message);
                    }
                }

                switch (engine.GameState)
                {
                case GameState.WhiteVictory:
                    Console.WriteLine();
                    Console.WriteLine("White victory!");
                    return;

                case GameState.BlackVictory:
                    Console.WriteLine();
                    Console.WriteLine("Black victory!");
                    return;

                case GameState.Tie:
                    Console.WriteLine();
                    Console.WriteLine("Players are tied!");
                    return;
                }
            }
        }
Esempio n. 2
0
        private async Task <dynamic> SubmitMove(dynamic args, CancellationToken cancellation_token)
        {
            Model.MoveRequest request = this.Bind <Model.MoveRequest>();
            try {
                QuantumChessEngine engine = await WebAppManagers.DatabaseManager.RequestEngine(request.GameId);

                QuantumChessMove move = request.Parse(engine);
                engine.Submit(move);
                await WebAppManagers.DatabaseManager.UpdateEngine(request.GameId, engine);

                return(new {
                    Success = true
                });
            } catch (QuantumChessException e) {
                return(new {
                    Success = false,
                    Message = e.Message
                });
            }
        }
Esempio n. 3
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}");
            }
        }