当前位置: 首页>>代码示例>>C#>>正文


C# Board.Move方法代码示例

本文整理汇总了C#中Board.Move方法的典型用法代码示例。如果您正苦于以下问题:C# Board.Move方法的具体用法?C# Board.Move怎么用?C# Board.Move使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Board的用法示例。


在下文中一共展示了Board.Move方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestCastlingNoKingsideWhite

        public void TestCastlingNoKingsideWhite()
        {
            var b = new Board(false);
            b.State[0] = Colors.Val(Piece.Rook, Color.White);
            b.State[7] = Colors.Val(Piece.Rook, Color.White);
            b.State[4] = Colors.Val(Piece.King, Color.White);

            b.State[56] = Colors.Val(Piece.Rook, Color.Black);
            b.State[63] = Colors.Val(Piece.Rook, Color.Black);
            b.State[60] = Colors.Val(Piece.King, Color.Black);

            b.AllowCastlingAll();

            b.PlayerTurn = Color.White;
            b.Move(7, 6);

            Assert.IsTrue(b.CanCastleKBlack);
            Assert.IsFalse(b.CanCastleKWhite);
            Assert.IsTrue(b.CanCastleQBlack);
            Assert.IsTrue(b.CanCastleQWhite);

            // test that we can't just move back
            b.PlayerTurn = Color.White;
            b.Move(6, 7);

            Assert.IsTrue(b.CanCastleKBlack);
            Assert.IsFalse(b.CanCastleKWhite);
            Assert.IsTrue(b.CanCastleQBlack);
            Assert.IsTrue(b.CanCastleQWhite);
        }
开发者ID:adh2050,项目名称:Chess,代码行数:30,代码来源:TestBoard.cs

示例2: TestFEN2

        public void TestFEN2()
        {
            var b1 = new Board(true);
            b1.Move(12, 12 + 16);
            b1.Move(50, 50 - 16);
            b1.Move(12+16, 12 + 16 + 8);

            var str = "rnbqkbnr/pp1ppppp/8/2p1P3/8/8/PPPP1PPP/RNBQKBNR b KQkq";
            var b2 = Notation.ReadFEN(str);

            bool equal = b1.State.SequenceEqual(b2.State);
            Assert.IsTrue(equal);
        }
开发者ID:adh2050,项目名称:Chess,代码行数:13,代码来源:TestNotation.cs

示例3: TestCastleBlackKingsideRookMoved

        public void TestCastleBlackKingsideRookMoved()
        {
            var b = new Board();
            b.InitBoard();
            b.State[61] = 0;
            b.State[62] = 0;
            b.PlayerTurn = Color.Black;
            bool ok = b.Move(63, 62);
            Assert.IsTrue(ok);
            b.PlayerTurn = Color.Black;
            b.Move(62, 63);
            Assert.IsTrue(ok);

            Assert.IsFalse(b.CanCastleKBlack);

            var moves = Moves.GetValidMoves(b, 60);
            Assert.AreEqual(1, moves.Length);
            Assert.IsTrue(moves.Contains(61));
        }
开发者ID:adh2050,项目名称:Chess,代码行数:19,代码来源:TestMovesKing.cs

示例4: Element_Can_Be_Moved

        public void Element_Can_Be_Moved()
        {
            var testElement = new TestBoardElement();
            var board = new Board(10, 20);
            Point position = new Point(5, 12);
            board.AddElement(testElement, position);

            board.Move(testElement, Board.Direction.North);

            var expectedNewPosition = new Point(position.X - 1, position.Y);
            Assert.IsFalse(board.Contents(position).Contains(testElement));
            Assert.IsTrue(board.Contents(expectedNewPosition).Contains(testElement));
        }
开发者ID:hombredequeso,项目名称:Robbie-Robot,代码行数:13,代码来源:BoardTests.cs

示例5: TestIsCaptureMoveEnPassant

        public void TestIsCaptureMoveEnPassant()
        {
            var b = new Board();
            b.PlayerTurn = Color.Black;

            int posWhite = Notation.TextToTile("e5");
            int posBlack = Notation.TextToTile("d7");

            b.State[posWhite] = Colors.Val(Piece.Pawn, Color.White);
            b.State[posBlack] = Colors.Val(Piece.Pawn, Color.Black);

            b.Move(posBlack, posBlack - 16);

            bool capture = Moves.IsCaptureMove(b, posWhite, posWhite + 7);
            Assert.IsTrue(capture);
        }
开发者ID:adh2050,项目名称:Chess,代码行数:16,代码来源:TestMoves.cs

示例6: TestABN2

        public void TestABN2()
        {
            // Tests knights and bishops moving
            var board = new Board(true);
            string data = "1.e4 Nf6 2.Nc3 c6 3.Bc4 d5 ";
            var game = new PGNParser().ParseGame(data);
            var moves = game.GetMainVariation();
            foreach (var move in moves)
            {
                board.Move(move.From, move.To, true);
            }

            var board2 = Notation.ReadFEN("rnbqkb1r/pp2pppp/2p2n2/3p4/2B1P3/2N5/PPPP1PPP/R1BQK1NR w KQkq");

            Assert.IsTrue(board2.State.SequenceEqual(board.State));
            Assert.AreEqual(Color.White, board.PlayerTurn);
        }
开发者ID:adh2050,项目名称:Chess,代码行数:17,代码来源:TestPGNParser1.cs

示例7: TestABN4

        public void TestABN4()
        {
            // Tests castling both kingside
            var board = new Board(true);
            string data = "1.e4 e5 2.Bd3 Bd6 3.Nf3 Nf6 4.O-O O-O ";
            var game = new PGNParser().ParseGame(data);
            var moves = game.GetMainVariation();
            foreach (var move in moves)
            {
                board.Move(move.From, move.To, true);
            }

            var board2 = Notation.ReadFEN("rnbq1rk1/pppp1ppp/3b1n2/4p3/4P3/3B1N2/PPPP1PPP/RNBQ1RK1 w -");

            Assert.IsTrue(board2.State.SequenceEqual(board.State));
            Assert.AreEqual(Color.White, board.PlayerTurn);
        }
开发者ID:adh2050,项目名称:Chess,代码行数:17,代码来源:TestPGNParser1.cs

示例8: TestZobrist1

        public void TestZobrist1()
        {
            var b = new Board(true);
            var zob = Zobrist.Calculate(b);

            b.Move(9, 25);
            var zob2 = Zobrist.Calculate(b);

            ulong expected = zob;
            expected = expected ^ Zobrist.Key.Piece(Color.White, Piece.Pawn, 9);
            expected = expected ^ Zobrist.Key.Piece(Color.White, Piece.Pawn, 25);
            expected = expected ^ Zobrist.Key.PlayerTurn(Color.White);
            expected = expected ^ Zobrist.Key.PlayerTurn(Color.Black);
            expected = expected ^ Zobrist.Key.EnPassant(b.EnPassantTile);

            Assert.AreEqual(expected, zob2);
        }
开发者ID:adh2050,项目名称:Chess,代码行数:17,代码来源:TestZobrist.cs

示例9: TestEnPassantVictimWhiteRight

        public void TestEnPassantVictimWhiteRight()
        {
            var b = new Board();
            b.PlayerTurn = Color.Black;

            int posWhite = Notation.TextToTile("e5");
            int posBlack = Notation.TextToTile("f7");

            b.State[posWhite] = Colors.Val(Piece.Pawn, Color.White);
            b.State[posBlack] = Colors.Val(Piece.Pawn, Color.Black);

            b.Move(posBlack, posBlack - 16);

            bool isEnPassant = Moves.IsEnPassantCapture(b, posWhite, posWhite + 9);
            Assert.IsTrue(isEnPassant);

            int target = Moves.EnPassantVictim(b, posWhite, posWhite + 9);
            Assert.AreEqual(target, posBlack - 16);
        }
开发者ID:adh2050,项目名称:Chess,代码行数:19,代码来源:TestMoves.cs

示例10: TestABNFullgame2

        public void TestABNFullgame2()
        {
            // end results
            var board = new Board(true);
            string data = "1.e4 e5 2.Nf3 Nf6 3.Nxe5 d6 4.Nf3 Nxe4 5.d4 d5 6.Bd3 Nc6 7.O-O Be7 8.c4 Nb4 9.Be2 O-O 10.Nc3 Bf5 11.a3 Nxc3 12.bxc3 Nc6 13.Re1 Re8 14.Bf4 dxc4 15.Bxc4 Bd6 16.Rxe8+ Qxe8 17.Ng5 Bg6 18.Bxd6 cxd6 19.h4 Qe7 20.Qg4 h6 21.Nf3 Qe4 22.Qg3 Rd8 23.Re1 Qf5 24.Ba2 Qf6 25.Nh2 Qf5 26.Ng4 Kf8 27.Bb1 Qh5 28.Qf4 Bxb1 29.Rxb1 Rd7 30.Ne3 Ne7 31.g3 Nd5 32.Nxd5 Qxd5 33.Re1 Re7 34.Rxe7 Kxe7 35.Qe3+ Qe6 1/2";

            var game = new PGNParser().ParseGame(data);
            var moves = game.GetMainVariation();

            foreach (var move in moves)
            {
                board.Move(move.From, move.To, true);
                if (move.Promotion != 0)
                {
                    bool promoted = board.Promote(move.To, move.Promotion);
                    Assert.IsTrue(promoted);
                }
            }

            var board2 = Notation.ReadFEN("8/pp2kpp1/3pq2p/8/3P3P/P1P1Q1P1/5P2/6K1 w - - 0 36");

            Assert.IsTrue(board2.State.SequenceEqual(board.State));
        }
开发者ID:adh2050,项目名称:Chess,代码行数:23,代码来源:TestPGNParser1.cs

示例11: TestCastleWhiteQueensideRookMoved

        public void TestCastleWhiteQueensideRookMoved()
        {
            var b = new Board();
            b.InitBoard();
            b.State[3] = 0;
            b.State[2] = 0;
            b.State[1] = 0;
            bool ok = b.Move(0, 1);
            Assert.IsTrue(ok);
            b.PlayerTurn = Color.White;
            ok = b.Move(1, 0);
            Assert.IsTrue(ok);

            Assert.IsFalse(b.CanCastleQWhite);

            var moves = Moves.GetValidMoves(b, 4);
            Assert.AreEqual(1, moves.Length);
            Assert.IsTrue(moves.Contains(3));
        }
开发者ID:adh2050,项目名称:Chess,代码行数:19,代码来源:TestMovesKing.cs

示例12: TestCastleWhiteKingsideRookMoved

        public void TestCastleWhiteKingsideRookMoved()
        {
            var b = new Board();
            b.InitBoard();
            b.State[5] = 0;
            b.State[6] = 0;

            bool ok = b.Move(7, 6);
            Assert.IsTrue(ok);
            b.PlayerTurn = Color.White;
            ok = b.Move(6, 7);
            Assert.IsTrue(ok);

            Assert.IsFalse(b.CanCastleKWhite);

            var moves = Moves.GetValidMoves(b, 4);
            Assert.AreEqual(1, moves.Length);
            Assert.IsTrue(moves.Contains(5));
        }
开发者ID:adh2050,项目名称:Chess,代码行数:19,代码来源:TestMovesKing.cs

示例13: NextBoard

 static bool NextBoard(Board board)
 {
     // 終了判定
     if (board.CheckEndPattern()) {
         return true;
     } else {
         for (int i = 0; i < board.Pieces.Count(); i++) {
             foreach (Direction d in new Direction[] { Direction.UP, Direction.DOWN, Direction.RIGHT, Direction.LEFT }) {
                 Board[] nextList = board.Move(i, d);
                 foreach (Board next in nextList) {
                     if (next != null && !Checked.Contains(next)) {
                         BoardQueue.Enqueue(next);
                         Checked.Add(next);
                     }
                 }
             }
         }
     }
     return false;
 }
开发者ID:BOZWXJ,项目名称:Puzzle,代码行数:20,代码来源:Program.cs

示例14: OpponentMove

        // perform opponents next move on the board
        private static bool OpponentMove(Board board, bool preComputeMyMove = true)
        {
            // if opponent can't move, i win!
            if (!board.GetOpponentValidMoves().Any())
            {
                return false;
            }

            // start evaluation for my next move on a bunch of new threads

            if (preComputeMyMove)
            {
                Searcher.I.PreComputeNextMove(board);
            }

            // ask for move
            var move = GetOpponentMove();

            // ensure it is valid
            if (!board.GetValidMoves().Any(x => x.Equals(move)))
            {
                Console.WriteLine("Not a valid opponent move! Was it entered correctly? (y/n):");

                // if opponent enters invalid move, they forfeit
                if ("y".Equals(Console.ReadLine(), StringComparison.OrdinalIgnoreCase))
                {
                    return false;
                }

                // otherwise it was a mistake, so let's try again
                return OpponentMove(board, false);
            }

            // confirm move is correct, which is equivalent to rollback functionality
            // a rollback would simply mean asking this question after performing the move instead of before
            Console.WriteLine("Are you sure? 'undo' to rollback, anything else to continue.");
            if ("undo".Equals(Console.ReadLine(), StringComparison.OrdinalIgnoreCase))
            {
                return OpponentMove(board, false);
            }

            // now that we know it's valid, and we've asked if they want to undo, perform move
            board.Move(move);
            return true;
        }
开发者ID:aldenquimby,项目名称:cs4701,代码行数:46,代码来源:GameRunner.cs

示例15: TestEnPassantLeft

        public void TestEnPassantLeft()
        {
            var b = new Board();
            b.PlayerTurn = Color.Black;

            int posWhite = Notation.TextToTile("e5");
            int posBlack = Notation.TextToTile("d7");

            b.State[posWhite] = Colors.Val(Piece.Pawn, Color.White);
            b.State[posBlack] = Colors.Val(Piece.Pawn, Color.Black);

            b.Move(posBlack, posBlack - 16);

            var moves = Attacks.GetAttacks(b, posWhite);
            Assert.AreEqual(3, moves.Length);
            Assert.IsTrue(moves.Contains(Notation.TextToTile("d5")));
        }
开发者ID:adh2050,项目名称:Chess,代码行数:17,代码来源:TestAttacksPawnWhite.cs


注:本文中的Board.Move方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。