Esempio n. 1
0
        public void IsKingOpen()
        {
            var s = new ChessState();
            var players = new List<Player> {new Player(1), new Player(2)};
            var from = new Position(1, 1);
            var to = new Position(3, 3);
            s[from] = ChessPieceFactory.CreatePiece('K', new EnglishFENPresentation(), players);
            s[to] = ChessPieceFactory.CreatePiece('q', new EnglishFENPresentation(), players);
            s[from].Move(from);
            s[to].Move(to);

            Assert.IsTrue(s.IsKingOpen(players[0]));
        }
Esempio n. 2
0
        protected virtual IConcreteMove Solve(ChessState state)
        {
            if (CastlingKingside)
            {
                From = new Position(5, Player.Order == 1 ? 1 : 8);
                To = new Position(7, Player.Order == 1 ? 1 : 8);
            }

            if (CastlingQueenside)
            {
                From = new Position(5, Player.Order == 1 ? 1 : 8);
                To = new Position(3, Player.Order == 1 ? 1 : 8);
            }

            Position from = null;
            var possibleMoves = new List<IConcreteMove>();
            foreach (ChessPiece p in state)
                if (!p.IsEmpty &&
                    p.Type == PieceType &&
                    p.Player == Player &&
                    From.Equals(p.Pos))
                {
                    var mv = p.GetPossibleMove(To, state, PromotionTo);

                    if (mv != null)
                    {
                        mv.Apply(state);
                        if (!state.IsKingOpen(Player))
                        {
                            from = p.Pos;
                            possibleMoves.Add(mv);
                        }

                        mv.Rollback(state);
                    }
                }

            if (possibleMoves.Count != 1)
            {
                throw new Exception("Ambiguous move.");
            }
            else
            {
                From = from;
                return possibleMoves[0];
            }
        }