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


C# Board.GetColor方法代码示例

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


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

示例1: CreateBoardFromData

		public void CreateBoardFromData()
		{
			board = new Board(CreateBoardData());
			Assert.AreEqual(board.Width, 2);
			Assert.AreEqual(board.Height, 3);
			Assert.AreEqual(board.GetColor(0, 1), Color.Red);
			Assert.AreEqual(board.GetColor(1, 2), Color.Orange);
		}
开发者ID:whztt07,项目名称:DeltaEngine,代码行数:8,代码来源:BoardTests.cs

示例2: EnPassantVictim

        /// <summary>
        /// Returns the tile of the pawn that is killed in an en passant capture
        /// </summary>
        /// <param name="board"></param>
        /// <param name="from"></param>
        /// <param name="to"></param>
        /// <returns></returns>
        public static int EnPassantVictim(Board board, int from, int to)
        {
            var color = board.GetColor(from);

            if (color == Color.White)
                return to - 8;

            if (color == Color.Black)
                return to + 8;

            throw new Exception("Unrecognized color");
        }
开发者ID:adh2050,项目名称:Chess,代码行数:19,代码来源:Moves.cs

示例3: GetBishopAttacks

        private static void GetBishopAttacks(Board board, int square, int[] moves, ref int count)
        {
            int x = Board.X(square);
            int y = Board.Y(square);
            Color color = board.GetColor(square);
            int target = 0;

            // Move up right
            target = square + 9;
            while (target < 64 && Board.X(target) > x)
            {
                moves[count] = target;
                count++;
                if (board.State[target] != 0) // piece
                    break;
                target += 9;
            }

            // Move up left
            target = square + 7;
            while (target < 64 && Board.X(target) < x)
            {
                moves[count] = target;
                count++;
                if (board.State[target] != 0) //  piece
                    break;
                target += 7;
            }

            // Move down right
            target = square - 7;
            while (target >= 0 && Board.X(target) > x)
            {
                moves[count] = target;
                count++;
                if (board.State[target] != 0) // piece
                    break;
                target -= 7;
            }

            // Move down left
            target = square - 9;
            while (target >= 0 && Board.X(target) < x)
            {
                moves[count] = target;
                count++;
                if (board.State[target] != 0) // piece
                    break;
                target -= 9;
            }
        }
开发者ID:adh2050,项目名称:Chess,代码行数:51,代码来源:Attacks.cs

示例4: EnPassantTile

        /// <summary>
        /// Checks if the move is pawn moving 2 tiles, and returns the tile at which it can be captured
        /// (between from and to). Returns 0 if the piece can not be captured in an en passant move
        /// </summary>
        /// <param name="board"></param>
        /// <param name="from"></param>
        /// <param name="to"></param>
        /// <returns></returns>
        public static int EnPassantTile(Board board, int from, int to)
        {
            var color = board.GetColor(from);
            var piece = board.GetPiece(from);
            var y = Board.Y(from);

            if (piece != Piece.Pawn)
                return 0;

            if (color == Color.White && y == 1 && to == (from + 16))
                return from + 8;

            if (color == Color.Black && y == 6 && to == (from - 16))
                return from - 8;

            return 0;
        }
开发者ID:adh2050,项目名称:Chess,代码行数:25,代码来源:Moves.cs

示例5: GetMoves

        /// <summary>
        /// Returns all moves, valid or not, for the current player
        /// </summary>
        /// <param name="board"></param>
        /// <returns></returns>
        public static Move[] GetMoves(Board board)
        {
            var moves = new List<Move>();
            var player = board.PlayerTurn;
            for(int i = 0; i < 64; i++)
            {
                if (board.GetColor(i) != player)
                    continue;

                Piece piece = board.GetPiece(i);

                var dest = GetMoves(board, i);
                for (int j = 0; j < dest.Length; j++)
                {
                    var move = new Move();
                    move.From = i;
                    move.To = dest[j];
                    moves.Add(move);

                    if(CanPromote(move.To, player, piece))
                    {
                        var move2 = move.Copy();
                        var move3 = move.Copy();
                        var move4 = move.Copy();

                        move.Promotion = Piece.Knight;
                        move2.Promotion = Piece.Bishop;
                        move3.Promotion = Piece.Rook;
                        move4.Promotion = Piece.Queen;

                        moves.Add(move2);
                        moves.Add(move3);
                        moves.Add(move4);
                    }
                }
            }

            return moves.ToArray();
        }
开发者ID:adh2050,项目名称:Chess,代码行数:44,代码来源:Moves.cs

示例6: Calculate

        public static ulong Calculate(Board board)
        {
            ulong hash = 0;

            for (int i = 0; i < 64; i++)
            {
                var color = board.GetColor(i);
                if (color == Color.None)
                    continue;

                var piece = board.GetPiece(i);

                hash = hash ^ Keys[Index[Colors.Val(color, piece)], i];
            }

            int castling = board.CastlingRights.Select(x => (int)x).Aggregate((total, x) => total | x);

            hash = hash ^ Keys[IndexPlayerTurn, (int)board.PlayerTurn];
            hash = hash ^ Keys[IndexCastling, castling];
            hash = hash ^ Keys[IndexEnPassant, board.EnPassantTile];

            return hash;
        }
开发者ID:adh2050,项目名称:Chess,代码行数:23,代码来源:Zobrist.cs

示例7: MakeMove

        private PGNMove MakeMove(PGNToken token, Board position)
        {
            var move = token.GetMove(position);

            if (move.Capture && position.State[move.To] == 0 && position.EnPassantTile == 0)
                throw new PGNException("Move is not a capture", token);

            if (move.Color != position.PlayerTurn)
                throw new PGNException("It is not this players turn to move", token);

            if (move.Color != position.GetColor(move.From))
                throw new PGNException("Moving piece is not of the expected color", token);

            if (move.Piece != position.GetPiece(move.From))
                throw new PGNException("Moving piece is not of the expected type", token);

            var ok = position.Move(move.From, move.To, true);

            if (!ok)
                throw new PGNException("Illegal move", token);

            if (move.Promotion != Piece.None)
            {
                ok = position.Promote(move.To, move.Promotion);
                if(!ok)
                    throw new PGNException("Illegal promotion", token);
            }

            if (move.Check && !position.IsChecked(position.PlayerTurn))
                throw new PGNException("Move did not cause a check", token);

            if (move.Mate && !position.IsCheckMate())
                throw new PGNException("Move did not cause a mate", token);

            return move;
        }
开发者ID:adh2050,项目名称:Chess,代码行数:36,代码来源:PGNParser.cs

示例8: GetRookMoves

        private static void GetRookMoves(Board board, int square, int[] moves, ref int count)
        {
            Color color = board.GetColor(square);
            int target = 0;

            // Move up
            target = square + 8;
            while (target < 64 && board.GetColor(target) != color)
            {
                moves[count] = target;
                count++;
                if (board.State[target] != 0) // enemy piece
                    break;
                target += 8;
            }

            // Move down
            target = square - 8;
            while (target >= 0 && board.GetColor(target) != color)
            {
                moves[count] = target;
                count++;
                if (board.State[target] != 0) // enemy piece
                    break;
                target -= 8;
            }

            // Move right
            target = square + 1;
            while (Board.X(target) > Board.X(square) && board.GetColor(target) != color)
            {
                moves[count] = target;
                count++;
                if (board.State[target] != 0) // enemy piece
                    break;
                target++;
            }

            // Move left
            target = square - 1;
            while (Board.X(target) < Board.X(square) && board.GetColor(target) != color)
            {
                moves[count] = target;
                count++;
                if (board.State[target] != 0) // enemy piece
                    break;
                target--;
            }
        }
开发者ID:adh2050,项目名称:Chess,代码行数:49,代码来源:Moves.cs

示例9: GetPawnMoves

        private static void GetPawnMoves(Board board, int square, int[] moves, ref int count)
        {
            int x = Board.X(square);
            int y = Board.Y(square);
            Color color = board.GetColor(square);

            if (y == 0 || y == 7) // cannot ever happen
                return;

            if(color == Color.White)
            {
                // move forward
                int target = square + 8;
                if (target < 64 && board.State[target] == 0)
                {
                    moves[count] = target;
                    count++;

                    target = square + 16;
                    if (y == 1 && board.State[target] == 0)
                    {
                        moves[count] = target;
                        count++;
                    }
                }

                // capture left
                target = square + 7;
                if (x > 0 && y < 7 && board.GetColor(target) == Color.Black)
                {
                    moves[count] = target;
                    count++;
                }

                // capture right
                target = square + 9;
                if (x < 7 && y < 7 && board.GetColor(target) == Color.Black)
                {
                    moves[count] = target;
                    count++;
                }

                // en passant left
                target = square + 7;
                if (y == 4 && x > 0 && board.EnPassantTile == target && board.State[target - 8] == ((int)Piece.Pawn | (int)Color.Black))
                {
                    moves[count] = target;
                    count++;
                }

                // en passant right
                target = square + 9;
                if (y == 4 && x < 7 && board.EnPassantTile == target && board.State[target - 8] == ((int)Piece.Pawn | (int)Color.Black))
                {
                    moves[count] = target;
                    count++;
                }
            }
            else
            {
                int target = square - 8;
                if (target >= 0 && board.State[target] == 0)
                {
                    moves[count] = target;
                    count++;

                    target = square - 16;
                    if (y == 6 && board.State[target] == 0)
                    {
                        moves[count] = target;
                        count++;
                    }
                }

                // capture left
                target = square - 9;
                if (x > 0 && y > 0 && board.GetColor(target) == Color.White)
                {
                    moves[count] = target;
                    count++;
                }

                // capture right
                target = square - 7;
                if (x < 7 && y > 0 && board.GetColor(target) == Color.White)
                {
                    moves[count] = target;
                    count++;
                }

                // en passant left
                target = square - 9;
                if (y == 3 && x > 0 && board.EnPassantTile == target && board.State[target + 8] == Colors.Val(Piece.Pawn, Color.White))
                {
                    moves[count] = target;
                    count++;
                }

                // en passant right
                target = square - 7;
//.........这里部分代码省略.........
开发者ID:adh2050,项目名称:Chess,代码行数:101,代码来源:Moves.cs

示例10: GetKnightMoves

        private static void GetKnightMoves(Board board, int square, int[] moves, ref int count)
        {
            // -x-x-  -0-1-
            // x---x  2---3
            // --O--  --O--
            // x---x  4---5
            // -x-x-  -6-7-

            int target = 0;

            int x = Board.X(square);
            int y = Board.Y(square);
            Color color = board.GetColor(square);

            // 0
            if (x > 0 && y < 6)
            {
                target = square + 15;
                if (board.GetColor(target) != color)
                {
                    moves[count] = target;
                    count++;
                }
            }
            // 1
            if (x < 7 && y < 6)
            {
                target = square + 17;
                if (board.GetColor(target) != color)
                {
                    moves[count] = target;
                    count++;
                }
            }

            // 2
            if (x > 1 && y < 7)
            {
                target = square + 6;
                if (board.GetColor(target) != color)
                {
                    moves[count] = target;
                    count++;
                }
            }
            // 3
            if (x < 6 && y < 7)
            {
                target = square + 10;
                if (board.GetColor(target) != color)
                {
                    moves[count] = target;
                    count++;
                }
            }

            // -x-x-  -0-1-
            // x---x  2---3
            // --O--  --O--
            // x---x  4---5
            // -x-x-  -6-7-

            // 4
            if (x > 1 && y > 0)
            {
                target = square - 10;
                if (board.GetColor(target) != color)
                {
                    moves[count] = target;
                    count++;
                }
            }
            // 5
            if (x < 6 && y > 0)
            {
                target = square - 6;
                if (board.GetColor(target) != color)
                {
                    moves[count] = target;
                    count++;
                }
            }

            // 6
            if (x > 0 && y > 1)
            {
                target = square - 17;
                if (board.GetColor(target) != color)
                {
                    moves[count] = target;
                    count++;
                }
            }
            // 7
            if (x < 7 && y > 1)
            {
                target = square - 15;
                if (board.GetColor(target) != color)
                {
                    moves[count] = target;
//.........这里部分代码省略.........
开发者ID:adh2050,项目名称:Chess,代码行数:101,代码来源:Moves.cs

示例11: GetKingMoves

        private static void GetKingMoves(Board board, int square, int[] moves, ref int count)
        {
            int x = Board.X(square);
            int y = Board.Y(square);
            Color color = board.GetColor(square);
            int target = 0;

            if (y < 7)
            {
                target = square + 7;
                if (x > 0 && board.GetColor(target) != color)
                {
                    moves[count] = target;
                    count++;
                }

                target = square + 8;
                if (board.GetColor(target) != color)
                {
                    moves[count] = target;
                    count++;
                }

                target = square + 9;
                if (x < 7 && board.GetColor(target) != color)
                {
                    moves[count] = target;
                    count++;
                }
            }

            target = square - 1;
            if (x > 0 && board.GetColor(target) != color)
            {
                moves[count] = target;
                count++;
            }

            target = square + 1;
            if (x < 7 && board.GetColor(target) != color)
            {
                moves[count] = target;
                count++;
            }

            if (y > 0)
            {
                target = square - 9;
                if (x > 0 && board.GetColor(target) != color)
                {
                    moves[count] = target;
                    count++;
                }

                target = square - 8;
                if (board.GetColor(target) != color)
                {
                    moves[count] = target;
                    count++;
                }

                target = square - 7;
                if (x < 7 && board.GetColor(target) != color)
                {
                    moves[count] = target;
                    count++;
                }
            }

            // castling
            // no quares between rook and king can be occupied, the king cannot pass through any checked attacked squares
            if (color == Color.White && square == 4)
            {
                if (board.CanCastleKWhite && board.State[5] == 0 && board.State[6] == 0)
                {
                    var attacks = board.GetAttackBoard(Color.Black);
                    if (attacks[4] == 0 && attacks[5] == 0 && attacks[6] == 0)
                    {
                        moves[count] = 6;
                        count++;
                    }
                }
                if (board.CanCastleQWhite && board.State[3] == 0 && board.State[2] == 0 && board.State[1] == 0)
                {
                    var attacks = board.GetAttackBoard(Color.Black);
                    if (attacks[2] == 0 && attacks[3] == 0 && attacks[4] == 0)
                    {
                        moves[count] = 2;
                        count++;
                    }
                }
            }
            else if (color == Color.Black && square == 60)
            {
                if (board.CanCastleKBlack && board.State[61] == 0 && board.State[62] == 0)
                {
                    var attacks = board.GetAttackBoard(Color.White);
                    if (attacks[60] == 0 && attacks[61] == 0 && attacks[62] == 0)
                    {
                        moves[count] = 62;
//.........这里部分代码省略.........
开发者ID:adh2050,项目名称:Chess,代码行数:101,代码来源:Moves.cs

示例12: GetPawnAttacks

        private static void GetPawnAttacks(Board board, int square, int[] moves, ref int count)
        {
            int x = Board.X(square);
            int y = Board.Y(square);
            Color color = board.GetColor(square);

            if (color == Color.White)
            {
                // capture left
                int target = square + 7;
                if (x > 0 && y < 7)
                {
                    moves[count] = target;
                    count++;
                }

                // capture right
                target = square + 9;
                if (x < 7 && y < 7)
                {
                    moves[count] = target;
                    count++;
                }

                // en passant left
                target = square + 7;
                if (y == 4 && x > 0 && board.EnPassantTile == target && board.State[target - 8] == Colors.Val(Piece.Pawn, Color.Black))
                {
                    moves[count] = target - 8; // I'm ATTACKING the pawn at target-8 even though I move to target
                    count++;
                }

                // en passant right
                target = square + 9;
                if (y == 4 && x < 7 && board.EnPassantTile == target && board.State[target - 8] == Colors.Val(Piece.Pawn, Color.Black))
                {
                    moves[count] = target - 8; // I'm ATTACKING the pawn at target-8 even though I move to target
                    count++;
                }
            }
            else
            {
                // capture left
                int target = square - 9;
                if (x > 0 && y > 0)
                {
                    moves[count] = target;
                    count++;
                }

                // capture right
                target = square - 7;
                if (x < 7 && y > 0)
                {
                    moves[count] = target;
                    count++;
                }

                // en passant left
                target = square - 9;
                if (y == 3 && x > 0 && board.EnPassantTile == target && board.State[target + 8] == Colors.Val(Piece.Pawn, Color.White))
                {
                    moves[count] = target+8; // I'm ATTACKING the pawn at target+8 even though I move to target
                    count++;
                }

                // en passant right
                target = square - 7;
                if (y == 3 && x < 7 && board.EnPassantTile == target && board.State[target + 8] == Colors.Val(Piece.Pawn, Color.White))
                {
                    moves[count] = target + 8; // I'm ATTACKING the pawn at target+8 even though I move to target
                    count++;
                }
            }
        }
开发者ID:adh2050,项目名称:Chess,代码行数:75,代码来源:Attacks.cs

示例13: GetKingAttacks

        private static void GetKingAttacks(Board board, int square, int[] moves, ref int count)
        {
            int x = Board.X(square);
            int y = Board.Y(square);
            Color color = board.GetColor(square);
            int target = 0;

            if (y < 7)
            {
                target = square + 7;
                if (x > 0)
                {
                    moves[count] = target;
                    count++;
                }

                target = square + 8;
                moves[count] = target;
                count++;

                target = square + 9;
                if (x < 7)
                {
                    moves[count] = target;
                    count++;
                }
            }

            target = square - 1;
            if (x > 0)
            {
                moves[count] = target;
                count++;
            }

            target = square + 1;
            if (x < 7)
            {
                moves[count] = target;
                count++;
            }

            if (y > 0)
            {
                target = square - 9;
                if (x > 0)
                {
                    moves[count] = target;
                    count++;
                }

                target = square - 8;
                moves[count] = target;
                count++;

                target = square - 7;
                if (x < 7)
                {
                    moves[count] = target;
                    count++;
                }
            }
        }
开发者ID:adh2050,项目名称:Chess,代码行数:63,代码来源:Attacks.cs


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