Exemplo n.º 1
0
        public void MoveBlackTest1()
        {
            var board = MakeBoard1(BWType.Black);

            var move = BoardMove.CreateMove(
                BWType.Black, new Square(8, 3), new Square(8, 2),
                new Piece(PieceType.Kyo, false), true);

            Assert.True(board.CanMove(move));

            // 駒が設定されてないと動けません。
            MethodUtil.SetPropertyValue(move, "MovePiece", new Piece());
            Assert.False(board.CanMove(move));
            MethodUtil.SetPropertyValue(move, "MovePiece", new Piece(PieceType.Kyo, false));

            // 84の駒は移動できません。
            MethodUtil.SetPropertyValue(move, "SrcSquare", new Square(8, 4));
            Assert.False(board.CanMove(move));
            MethodUtil.SetPropertyValue(move, "SrcSquare", new Square(8, 3));

            CanMoveTo(board, move, new List <Tuple <Square, bool> >
            {
                Tuple.Create(new Square(8, 2), false),
                Tuple.Create(new Square(8, 1), true),
            });
        }
Exemplo n.º 2
0
 /// <summary>
 /// ViewModelの状態を元に戻します。
 /// </summary>
 public void RollbackViewModel()
 {
     lock (this.oldPropertyValueDic)
     {
         this.oldPropertyValueDic.ForEach(_ =>
                                          MethodUtil.SetPropertyValue(ViewModel, _.Key, _.Value));
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// 駒の各移動先に対して、その手が指せるのかどうかをチェックします。
        /// </summary>
        private void CanMoveTo(Board board, BoardMove move,
                               List <Tuple <Square, bool> > availables)
        {
            for (var file = 1; file <= Board.BoardSize; ++file)
            {
                for (var rank = 1; rank <= Board.BoardSize; ++rank)
                {
                    var sq    = new Square(file, rank);
                    var avail = availables.FirstOrDefault(_ => _.Item1 == sq);

                    MethodUtil.SetPropertyValue(move, "DstSquare", sq);
                    if (avail != null)
                    {
                        if (avail.Item2)
                        {
                            // 成りが必須の場合
                            move.IsPromote = false;
                            Assert.False(board.CanMove(move));

                            move.IsPromote = true;
                            Assert.True(board.CanMove(move));
                        }
                        else
                        {
                            // 成りが必須でない場合
                            move.IsPromote = false;
                            Assert.True(board.CanMove(move));

                            move.IsPromote = true;
                            Assert.AreEqual(Board.CanPromote(move), board.CanMove(move));
                        }
                    }
                    else
                    {
                        // そもそも移動できる場所ではない
                        move.IsPromote = false;
                        Assert.False(board.CanMove(move));

                        move.IsPromote = true;
                        Assert.False(board.CanMove(move));
                    }
                }
            }
        }
Exemplo n.º 4
0
        public void MoveWhiteTest1()
        {
            var board = MakeBoard1(BWType.White);

            var move = BoardMove.CreateMove(
                BWType.White, new Square(9, 7), new Square(9, 8),
                new Piece(PieceType.Hu, false), true);

            Assert.True(board.CanMove(move));

            // 84の駒は移動できません。
            MethodUtil.SetPropertyValue(move, "SrcSquare", new Square(8, 4));
            Assert.False(board.CanMove(move));
            MethodUtil.SetPropertyValue(move, "SrcSquare", new Square(9, 7));

            CanMoveTo(board, move, new List <Tuple <Square, bool> >
            {
                Tuple.Create(new Square(9, 8), false),
            });
        }