public void GetPresentationBlack()
 {
     var p = new EnglishFENPresentation();
     var pl = new Player(2);
     var o = new ChessPiece { Type = PieceTypes.Rook, Player = pl };
     Assert.AreEqual('r', p.GetPresentation(o));
 }
Ejemplo n.º 2
0
 public static void AddMoves(ChessPiece p)
 {
     switch (p.Type)
     {
         case PieceTypes.Pawn:
             p.PossibleMoves.Add(new Promotion(new PawnMoveTemplate(), new[] { PieceTypes.Knight, PieceTypes.Bishop, PieceTypes.Rook, PieceTypes.Queen }));
             p.PossibleMoves.Add(new Promotion(new PawnCaptureTemplate(), new[] { PieceTypes.Knight, PieceTypes.Bishop, PieceTypes.Rook, PieceTypes.Queen }));
             p.PossibleMoves.Add(new PawnMoveTemplate());
             p.PossibleMoves.Add(new PawnCaptureTemplate());
             p.PossibleMoves.Add(new EnPassantTemplate());
             break;
         case PieceTypes.Knight:
             p.PossibleMoves.Add(new KnightMoveTemplate());
             break;
         case PieceTypes.Bishop:
             p.PossibleMoves.Add(new DiagonalMoveTemplate());
             break;
         case PieceTypes.Rook:
             p.PossibleMoves.Add(new HorizontalMoveTemplate());
             p.PossibleMoves.Add(new VerticalMoveTemplate());
             break;
         case PieceTypes.Queen:
             p.PossibleMoves.Add(new HorizontalMoveTemplate());
             p.PossibleMoves.Add(new VerticalMoveTemplate());
             p.PossibleMoves.Add(new DiagonalMoveTemplate());
             break;
         case PieceTypes.King:
             p.PossibleMoves.Add(new HorizontalMoveTemplate(1));
             p.PossibleMoves.Add(new VerticalMoveTemplate(1));
             p.PossibleMoves.Add(new DiagonalMoveTemplate(1));
             p.PossibleMoves.Add(new CastlingTemplate(CastlingTemplate.CastlingType.Kingside));
             p.PossibleMoves.Add(new CastlingTemplate(CastlingTemplate.CastlingType.Queenside));
             break;
     }
 }
 public void GetEmptyCell()
 {
     var p = new FigurinePresentation();
     var pl = new Player(2);
     var o = new ChessPiece { IsEmpty = true };
     Assert.AreEqual(null, p.GetPresentation(o));
 }
 public void GetPresentationWhite()
 {
     var p = new FigurinePresentation();
     var pl = new Player(1);
     var o = new ChessPiece { Type = PieceTypes.Rook, Player = pl };
     Assert.AreEqual('♖', p.GetPresentation(o));
 }
Ejemplo n.º 5
0
        public void ChessPieceCopyConstructor()
        {
            var p1 = new ChessPiece { Type = PieceTypes.King };
            var p2 = new ChessPiece (p1);

            Assert.AreEqual(p1.Type, p2.Type);
        }
Ejemplo n.º 6
0
 public void KnightCanSkip()
 {
     var from = new Position(3, 3);
     var s = new ChessState();
     s[new Position(3, 4)] = new ChessPiece();
     var m = new KnightMoveTemplate();
     Assert.IsTrue(m.CanApply(from, new Position(4, 5), s));
 }
Ejemplo n.º 7
0
 public void PromotionWrongType()
 {
     var from = new Position("a7");
     var s = new ChessState();
     var piece = new ChessPiece { Player = new Player(1) };
     s[from] = piece;
     var m = new Promotion(new PawnMoveTemplate(), new[] { PieceTypes.Knight, PieceTypes.Bishop, PieceTypes.Rook, PieceTypes.Queen });
     Assert.IsFalse(m.CanApply(from, new Position("a8"), s, PieceTypes.Pawn));
 }
Ejemplo n.º 8
0
        public void CanNotAttack()
        {
            var pos = new Position(1, 1);
            var s = new ChessState();
            var p = new ChessPiece();
            p.Move(new Position(2, 2));
            p.PossibleMoves.Add(new MockTemplate(null, false));

            Assert.IsFalse(p.CanAttack(pos, s));
        }
Ejemplo n.º 9
0
        public void GetPossibleMove()
        {
            var pos = new Position(1, 1);
            var s = new ChessState();
            var p = new ChessPiece();
            p.Move(new Position(2, 2));
            p.PossibleMoves.Add(new MockTemplate());

            Assert.IsNotNull(p.GetPossibleMove(pos, s, PieceTypes.Pawn));
        }
Ejemplo n.º 10
0
        public void EnPassantFar()
        {
            var from = new Position("c5");
            var to = new Position("a3");
            var s = new ChessState();
            s.EnPassant = to;
            s[from] = new ChessPiece { Player = new Player(2) };
            var m = new EnPassantTemplate();

            Assert.IsFalse(m.CanApply(from, to, s));
        }
Ejemplo n.º 11
0
        void CheckButton(object sender, RoutedEventArgs e)
        {
            foreach (var btn in PieceButtons.Where(btn => btn != sender))
                btn.IsChecked = false;

            if (sender is RibbonToggleButton)
            {
                var o = sender as RibbonToggleButton;
                PlacedPiece = (ChessPiece)o.Content;
            }

            Cursor = Cursors.Hand;
        }
Ejemplo n.º 12
0
        public void NoPossibleMoves()
        {
            var s = new ChessState();
            var from = new Position(1, 1);
            var to = new Position(1, 3);
            var p = new ChessPiece();
            s[from] = p;
            s[from].Move(from);

            p.PossibleMoves.Add(new MockTemplate(1));

            Assert.IsNull(p.GetPossibleMove(to, s, PieceTypes.Pawn));
        }
Ejemplo n.º 13
0
        public void PromotionApply()
        {
            var from = new Position("a7");
            var to   = new Position("a8");
            var piece = new ChessPiece { Type = PieceTypes.Pawn, Player = new Player(1) };
            var s = new ChessState();
                s[from] = piece;
            var m = new Promotion(new PawnMoveTemplate(), new[] { PieceTypes.Knight, PieceTypes.Bishop, PieceTypes.Rook, PieceTypes.Queen });
            var concretePromotion = m.Concretize(from, to, PieceTypes.Queen);

            concretePromotion.Apply(s);

            Assert.AreEqual(PieceTypes.Queen, piece.Type);
        }
Ejemplo n.º 14
0
        public void CanAttack()
        {
            var s = new ChessState();
            var from = new Position(1, 1);
            var to   = new Position(2, 2);
            var p = new ChessPiece();
            s[from] = p;
            s[from].Move(from);
            s[to] = new ChessPiece();
            s[to].Move(to);

            s[from].PossibleMoves.Add(new MockTemplate(null, true));

            Assert.IsTrue(p.CanAttack(to, s));
        }
Ejemplo n.º 15
0
        public void CastlingKingside()
        {
            var c = new CastlingTemplate(CastlingTemplate.CastlingType.Kingside);

            var from = new Position(5, 1);
            var to   = new Position(7, 1);
            var rook = new Position(8, 1);

            var s = new ChessState();
            s[rook] = new ChessPiece {Type = PieceTypes.Rook};
            s[rook].Move(rook);
            s[from] = new ChessPiece {Type = PieceTypes.King};
            s[from].Move(from);

            Assert.IsTrue(c.CanApply(from, to, s));
        }
Ejemplo n.º 16
0
        public void EnPassantCapture()
        {
            var enmy = new Position("a4");
            var from = new Position("b4");
            var to = new Position("a3");
            var s = new ChessState();
            s.EnPassant = to;
            s[from] = new ChessPiece { Player = new Player(2) };
            s[from].Move(from);
            s[enmy] = new ChessPiece();
            s[enmy].Move(enmy);
            var m = new EnPassantConcrete(from, to);

            Assert.IsFalse(s[enmy].IsEmpty);
            m.Apply(s);
            Assert.IsTrue(s[enmy].IsEmpty);
        }
Ejemplo n.º 17
0
        public void CastlingBarrierQ()
        {
            var c = new CastlingTemplate(CastlingTemplate.CastlingType.Queenside);

            var from = new Position(5, 1);
            var to = new Position(3, 1);
            var rook = new Position(1, 1);
            var enmy = new Position(2, 1);
            var white = new Player(1);

            var s = new ChessState();
            s[rook] = new ChessPiece { Type = PieceTypes.Rook, Player = white };
            s[rook].Move(rook);
            s[from] = new ChessPiece { Type = PieceTypes.King, Player = white };
            s[from].Move(from);
            s[enmy] = new ChessPiece { Type = PieceTypes.Rook, Player = white };
            s[enmy].Move(enmy);

            Assert.IsFalse(c.CanApply(from, to, s));
        }
Ejemplo n.º 18
0
        public static ChessPiece CreatePiece(Object pieceCode, IChessPresentation presentation, List<Player> players = null)
        {
            if (players == null)
                players = new List<Player> { new Player(1), new Player(2) };

            var p = new ChessPiece();

            if (!presentation.IsEmpty(pieceCode))
            {
                p.Type = presentation.GetPieceType(pieceCode);
                p.Player = players.Find(s => s.Order == presentation.GetPlayer(pieceCode));
                AddMoves(p);
            }
            else
            {
                p.IsEmpty = true;
            }

            return p;
        }
Ejemplo n.º 19
0
 public void GetPresentation()
 {
     var p = new EnglishPresentation();
     var o = new ChessPiece {Type = PieceTypes.Rook};
     Assert.AreEqual('R', p.GetPresentation(o));
 }
Ejemplo n.º 20
0
        void UncheckButton(object sender, RoutedEventArgs e)
        {
            if (sender is RibbonToggleButton)
            {
                var o = sender as RibbonToggleButton;
                if (PlacedPiece == o.Content)
                    PlacedPiece = null;
            }

            Cursor = Cursors.Arrow;
        }
Ejemplo n.º 21
0
        public void EnPassantSetting()
        {
            var from = new Position("a2");
            var to = new Position("a4");
            var s = new ChessState();
            s[from] = new ChessPiece { Player = new Player(1) };
            var m = new PawnConcreteMove(from, to);

            m.Apply(s);

            Assert.AreEqual(new Position("a3"), s.EnPassant);
        }
Ejemplo n.º 22
0
 public void NewEmptyPieceTest()
 {
     var s = new ChessState();
     var pos = new Position(1, 1);
     s[pos] = new ChessPiece();
     s.NewEmptyPiece(pos);
     Assert.IsTrue(s[pos].IsEmpty);
 }
Ejemplo n.º 23
0
 public ChessPiece(ChessPiece copy)
     : base(copy)
 {
     Type = copy.Type;
 }
Ejemplo n.º 24
0
        public void RookPathUnderAttack()
        {
            var c = new CastlingTemplate(CastlingTemplate.CastlingType.Kingside);

            var from = new Position(5, 1);
            var to = new Position(7, 1);
            var rook = new Position(8, 1);
            var enmy = new Position(8, 3);
            var white = new Player(1);

            var s = new ChessState();
            s[rook] = new ChessPiece { Type = PieceTypes.Rook, Player = white };
            s[rook].Move(rook);
            s[from] = new ChessPiece { Type = PieceTypes.King, Player = white };
            s[from].Move(from);
            s[enmy] = new ChessPiece { Type = PieceTypes.Rook, Player = new Player(2) };
            s[enmy].Move(enmy);
            ChessPieceFactory.AddMoves((ChessPiece)s[enmy]);

            Assert.IsTrue(c.CanApply(from, to, s));
        }
Ejemplo n.º 25
0
 public void GetPresentationPawn()
 {
     var p = new EnglishPresentation();
     var o = new ChessPiece { Type = PieceTypes.Pawn };
     Assert.AreEqual(null, p.GetPresentation(o));
 }
Ejemplo n.º 26
0
 public override void NewEmptyPiece(Position pos)
 {
     var p = new ChessPiece { IsEmpty = true };
     this[pos] = p;
     p.Move(pos);
 }
Ejemplo n.º 27
0
        public void PawnUp()
        {
            var from = new Position("a2");
            var to = new Position("a3");
            var s = new ChessState();
            s[from] = new ChessPiece {Player = new Player(1)};
            var m = new PawnMoveTemplate();

            Assert.IsTrue(m.CanApply(from,to,s));
        }
Ejemplo n.º 28
0
        public void PawnTwoCellsNot()
        {
            var from = new Position("a3");
            var to = new Position("a5");
            var s = new ChessState();
            s[from] = new ChessPiece { Player = new Player(1) };
            var m = new PawnMoveTemplate();

            Assert.IsFalse(m.CanApply(from, to, s));
        }
Ejemplo n.º 29
0
        public void PawnTwoCellsBlack()
        {
            var from = new Position("a7");
            var to = new Position("a5");
            var s = new ChessState();
            s[from] = new ChessPiece { Player = new Player(2) };
            var m = new PawnMoveTemplate();

            Assert.IsTrue(m.CanApply(from, to, s));
        }
Ejemplo n.º 30
0
        public void PawnCaptureLeft()
        {
            var from = new Position("b3");
            var to = new Position("a4");
            var s = new ChessState();
            s[from] = new ChessPiece { Player = new Player(1) };
            s[to] = new ChessPiece();
            var m = new PawnCaptureTemplate();

            Assert.IsTrue(m.CanApply(from, to, s));
        }