• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# ChessGame类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中ChessGame的典型用法代码示例。如果您正苦于以下问题:C# ChessGame类的具体用法?C# ChessGame怎么用?C# ChessGame使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ChessGame类属于命名空间,在下文中一共展示了ChessGame类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Generate

 public List<String> Generate(ChessGame game)
 {
     var result = game.Info.Select(tag => "[" + tag.Key + " \"" + tag.Value + "\"]").ToList();
     result.Add("");
     result.Add(GenerateMovetext(game));
     return result;
 }
开发者ID:Maniulo,项目名称:GameWarden,代码行数:7,代码来源:PGNParser.cs


示例2: TestAfter1e4

 public static void TestAfter1e4()
 {
     ChessGame game = new ChessGame();
     game.ApplyMove(new Move("E2", "E4", Player.White), true);
     string fen = game.GetFen();
     Assert.AreEqual("rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1", fen);
 }
开发者ID:ProgramFOX,项目名称:Chess.NET,代码行数:7,代码来源:FenConvertTests.cs


示例3: GetValidMoves

 public override ReadOnlyCollection<Move> GetValidMoves(Position from, bool returnIfAny, ChessGame game, Func<Move, bool> gameMoveValidator)
 {
     ChessUtilities.ThrowIfNull(from, "from");
     List<Move> validMoves = new List<Move>();
     Piece piece = game.GetPieceAt(from);
     int l0 = game.BoardHeight;
     int l1 = game.BoardWidth;
     for (int i = -7; i < 8; i++)
     {
         if (i == 0)
             continue;
         if (from.Rank + i > 0 && from.Rank + i <= l0)
         {
             Move move = new Move(from, new Position(from.File, from.Rank + i), piece.Owner);
             if (gameMoveValidator(move))
             {
                 validMoves.Add(move);
                 if (returnIfAny)
                     return new ReadOnlyCollection<Move>(validMoves);
             }
         }
         if ((int)from.File + i > -1 && (int)from.File + i < l1)
         {
             Move move = new Move(from, new Position(from.File + i, from.Rank), piece.Owner);
             if (gameMoveValidator(move))
             {
                 validMoves.Add(move);
                 if (returnIfAny)
                     return new ReadOnlyCollection<Move>(validMoves);
             }
         }
     }
     return new ReadOnlyCollection<Move>(validMoves);
 }
开发者ID:ProgramFOX,项目名称:Chess.NET,代码行数:34,代码来源:Rook.cs


示例4: Set

            public void Set(ChessGame g)
            {
                idx = -1;
                move = null;
                total_moves = 0;

                if (g == null)
                  {
                      player = ChessGamePlayer.
                          CreatePlayer ();
                      return;
                  }
                player = g.HasTag ("FEN") ? ChessGamePlayer.
                    CreateFromFEN (g.
                               GetTagValue ("FEN",
                                    null)) :
                    ChessGamePlayer.CreatePlayer ();

                game = g;

                int n = game.Moves.Count;
                if (n > 0)
                  {
                      total_moves = n;
                  }

                if (total_moves == 0)
                    hasNext = false;
                else
                    hasNext = true;
            }
开发者ID:BackupTheBerlios,项目名称:csboard-svn,代码行数:31,代码来源:GameSession.cs


示例5: TestAfter1c5

 public static void TestAfter1c5()
 {
     ChessGame game = new ChessGame();
     game.ApplyMove(new Move("E2", "E4", Player.White), true);
     game.ApplyMove(new Move("C7", "C5", Player.Black), true);
     string fen = game.GetFen();
     Assert.AreEqual("rnbqkbnr/pp1ppppp/8/2p5/4P3/8/PPPP1PPP/RNBQKBNR w KQkq c6 0 2", fen);
 }
开发者ID:ProgramFOX,项目名称:Chess.NET,代码行数:8,代码来源:FenConvertTests.cs


示例6: GetValidMoves

 public override ReadOnlyCollection<Move> GetValidMoves(Position from, bool returnIfAny, ChessGame game, Func<Move, bool> gameMoveValidator)
 {
     ChessUtilities.ThrowIfNull(from, "from");
     ReadOnlyCollection<Move> horizontalVerticalMoves = new Rook(Owner).GetValidMoves(from, returnIfAny, game, gameMoveValidator);
     if (returnIfAny && horizontalVerticalMoves.Count > 0)
         return horizontalVerticalMoves;
     ReadOnlyCollection<Move> diagonalMoves = new Bishop(Owner).GetValidMoves(from, returnIfAny, game, gameMoveValidator);
     return new ReadOnlyCollection<Move>(horizontalVerticalMoves.Concat(diagonalMoves).ToList());
 }
开发者ID:ProgramFOX,项目名称:Chess.NET,代码行数:9,代码来源:Queen.cs


示例7: TestMovingWhiteKingLosingCastlingRights

 public static void TestMovingWhiteKingLosingCastlingRights()
 {
     ChessGame game = new ChessGame();
     game.ApplyMove(new Move("E2", "E4", Player.White), true);
     game.ApplyMove(new Move("C7", "C5", Player.Black), true);
     game.ApplyMove(new Move("E1", "E2", Player.White), true);
     string fen = game.GetFen();
     Assert.AreEqual("rnbqkbnr/pp1ppppp/8/2p5/4P3/8/PPPPKPPP/RNBQ1BNR b kq - 1 2", fen);
 }
开发者ID:ProgramFOX,项目名称:Chess.NET,代码行数:9,代码来源:FenConvertTests.cs


示例8: TestMovingBlackKingLosingCastlingRights

 public static void TestMovingBlackKingLosingCastlingRights()
 {
     ChessGame game = new ChessGame();
     game.ApplyMove(new Move("E2", "E4", Player.White), true);
     game.ApplyMove(new Move("E7", "E5", Player.Black), true);
     game.ApplyMove(new Move("G1", "F3", Player.White), true);
     game.ApplyMove(new Move("E8", "E7", Player.Black), true);
     string fen = game.GetFen();
     Assert.AreEqual("rnbq1bnr/ppppkppp/8/4p3/4P3/5N2/PPPP1PPP/RNBQKB1R w KQ - 2 3", fen);
 }
开发者ID:ProgramFOX,项目名称:Chess.NET,代码行数:10,代码来源:FenConvertTests.cs


示例9: IsValidMove

        public override bool IsValidMove(Move move, ChessGame game)
        {
            ChessUtilities.ThrowIfNull(move, "move");
            ChessUtilities.ThrowIfNull(game, "game");
            Position origin = move.OriginalPosition;
            Position destination = move.NewPosition;

            PositionDistance posDelta = new PositionDistance(origin, destination);
            if ((posDelta.DistanceX != 2 || posDelta.DistanceY != 1) && (posDelta.DistanceX != 1 || posDelta.DistanceY != 2))
                return false;
            return true;
        }
开发者ID:ProgramFOX,项目名称:Chess.NET,代码行数:12,代码来源:Knight.cs


示例10: Parse

        public ChessGame Parse(IEnumerable<String> pgn, IChessMoveNotation moveNotation)
        {
            var lines = pgn.GetEnumerator();
            var metainfo = ParseTags(lines);
            var movetext = ParseMovetext(lines);
            var game = new ChessGame(metainfo);

            foreach (ChessMove cm in ParseMoves(movetext, moveNotation, game.Players))
                game.AddMove(cm);

            return game;
        }
开发者ID:Maniulo,项目名称:GameWarden,代码行数:12,代码来源:PGNParser.cs


示例11: CanCastle

 protected virtual bool CanCastle(Position origin, Position destination, ChessGame game)
 {
     if (!HasCastlingAbility) return false;
     if (Owner == Player.White)
     {
         if (origin.File != File.E || origin.Rank != 1)
             return false;
         if (game.IsInCheck(Player.White))
             return false;
         if (destination.File == File.C)
         {
             if (!game.CanWhiteCastleQueenSide || game.GetPieceAt(File.D, 1) != null
                 || game.GetPieceAt(File.C, 1) != null
                 || game.GetPieceAt(File.B, 1) != null
                 || game.WouldBeInCheckAfter(new Move(new Position(File.E, 1), new Position(File.D, 1), Player.White), Player.White)
                 || game.WouldBeInCheckAfter(new Move(new Position(File.E, 1), new Position(File.C, 1), Player.White), Player.White))
                 return false;
         }
         else
         {
             if (!game.CanWhiteCastleKingSide || game.GetPieceAt(File.F, 1) != null
                 || game.GetPieceAt(File.G, 1) != null
                 || game.WouldBeInCheckAfter(new Move(new Position(File.E, 1), new Position(File.F, 1), Player.White), Player.White)
                 || game.WouldBeInCheckAfter(new Move(new Position(File.E, 1), new Position(File.G, 1), Player.White), Player.White))
                 return false;
         }
     }
     else
     {
         if (origin.File != File.E || origin.Rank != 8)
             return false;
         if (game.IsInCheck(Player.Black))
             return false;
         if (destination.File == File.C)
         {
             if (!game.CanBlackCastleQueenSide || game.GetPieceAt(File.D, 8) != null
                 || game.GetPieceAt(File.C, 8) != null
                 || game.GetPieceAt(File.B, 8) != null
                 || game.WouldBeInCheckAfter(new Move(new Position(File.E, 8), new Position(File.D, 8), Player.Black), Player.Black)
                 || game.WouldBeInCheckAfter(new Move(new Position(File.E, 8), new Position(File.C, 8), Player.Black), Player.Black))
                 return false;
         }
         else
         {
             if (!game.CanBlackCastleKingSide || game.GetPieceAt(File.F, 8) != null
                 || game.GetPieceAt(File.G, 8) != null
                 || game.WouldBeInCheckAfter(new Move(new Position(File.E, 8), new Position(File.F, 8), Player.Black), Player.Black)
                 || game.WouldBeInCheckAfter(new Move(new Position(File.E, 8), new Position(File.G, 8), Player.Black), Player.Black))
                 return false;
         }
     }
     return true;
 }
开发者ID:ProgramFOX,项目名称:Chess.NET,代码行数:53,代码来源:King.cs


示例12: ChessForm

 public ChessForm()
 {
     InitializeComponent();
     chessPanel.BackColor = Color.Gray;
     GamePoint.SIDE_LENGTH = chessPanel.Height / 8;
     if (chessPanel.Height != chessPanel.Width)
     {
         throw new Exception("Chess game needs a square panel");
     }
     game = new ChessGame(chessPanel.Height);
     Invalidate();
 }
开发者ID:t3dodson,项目名称:chess,代码行数:12,代码来源:Form1.cs


示例13: IsValidMove

 public override bool IsValidMove(Move move, ChessGame game)
 {
     ChessUtilities.ThrowIfNull(move, "move");
     Position origin = move.OriginalPosition;
     Position destination = move.NewPosition;
     PositionDistance distance = new PositionDistance(origin, destination);
     if ((distance.DistanceX != 1 || distance.DistanceY != 1)
                 && (distance.DistanceX != 0 || distance.DistanceY != 1)
                 && (distance.DistanceX != 1 || distance.DistanceY != 0)
                 && (distance.DistanceX != 2 || distance.DistanceY != 0))
         return false;
     if (distance.DistanceX != 2)
         return true;
     return CanCastle(origin, destination, game);
 }
开发者ID:ProgramFOX,项目名称:Chess.NET,代码行数:15,代码来源:King.cs


示例14: IsValidMove

        public override bool IsValidMove(Move move, ChessGame game)
        {
            bool validByStandardRules = base.IsValidMove(move, game);
            if (validByStandardRules) return true;
            if (move.OriginalPosition.Rank == 1 &&
                move.NewPosition.Rank == 3 &&
                move.OriginalPosition.File == move.NewPosition.File &&
                game.GetPieceAt(move.NewPosition) == null &&
                game.GetPieceAt(new Position(move.OriginalPosition.File, move.OriginalPosition.Rank + 1)) == null)
                // Horde pawns at the first rank can also move two squares on their first move. However, these can't be en-passant captured.
            {
                return true;
            }

            return false;
        }
开发者ID:ProgramFOX,项目名称:Chess.NET,代码行数:16,代码来源:HordePawn.cs


示例15: GenerateMovetext

        public String GenerateMovetext(ChessGame game)
        {
            var movetext = new StringBuilder();
            var moveCount = 1;

            foreach (var m in game.Moves)
            {
                if (moveCount % 2 == 1)
                    movetext.Append((moveCount+1)/2 + ". ");
                movetext.Append(m + " ");

                moveCount++;
            }

            if (movetext.Length > 0)
                movetext.Remove(movetext.Length - 1, 1);

            return movetext.ToString();
        }
开发者ID:Maniulo,项目名称:GameWarden,代码行数:19,代码来源:PGNParser.cs


示例16: IsValidMove

        public override bool IsValidMove(Move move, ChessGame game)
        {
            ChessUtilities.ThrowIfNull(move, "move");
            ChessUtilities.ThrowIfNull(game, "game");
            Position origin = move.OriginalPosition;
            Position destination = move.NewPosition;

            PositionDistance posDelta = new PositionDistance(origin, destination);
            if (posDelta.DistanceX != 0 && posDelta.DistanceY != 0)
                return false;
            bool increasingRank = destination.Rank > origin.Rank;
            bool increasingFile = (int)destination.File > (int)origin.File;
            if (posDelta.DistanceX == 0)
            {
                int f = (int)origin.File;
                for (int r = origin.Rank + (increasingRank ? 1 : -1);
                    increasingRank ? r < destination.Rank : r > destination.Rank;
                    r += increasingRank ? 1 : -1)
                {
                    if (game.GetPieceAt((File)f, r) != null)
                    {
                        return false;
                    }
                }
            }
            else // (posDelta.DeltaY == 0)
            {
                int r = origin.Rank;
                for (int f = (int)origin.File + (increasingFile ? 1 : -1);
                    increasingFile ? f < (int)destination.File : f > (int)destination.File;
                    f += increasingFile ? 1 : -1)
                {
                    if (game.GetPieceAt((File)f, r) != null)
                    {
                        return false;
                    }
                }
            }
            return true;
        }
开发者ID:ProgramFOX,项目名称:Chess.NET,代码行数:40,代码来源:Rook.cs


示例17: GetValidMoves

 public override ReadOnlyCollection<Move> GetValidMoves(Position from, bool returnIfAny, ChessGame game, Func<Move, bool> gameMoveValidator)
 {
     List<Move> validMoves = new List<Move>();
     Piece piece = game.GetPieceAt(from);
     int l0 = game.BoardHeight;
     int l1 = game.BoardWidth;
     int[][] directions = new int[][] { new int[] { 2, 1 }, new int[] { -2, -1 }, new int[] { 1, 2 }, new int[] { -1, -2 },
                 new int[] { 1, -2 }, new int[] { -1, 2 }, new int[] { 2, -1 }, new int[] { -2, 1 } };
     foreach (int[] dir in directions)
     {
         if ((int)from.File + dir[0] < 0 || (int)from.File + dir[0] >= l1
             || from.Rank + dir[1] < 1 || from.Rank + dir[1] > l0)
             continue;
         Move move = new Move(from, new Position(from.File + dir[0], from.Rank + dir[1]), piece.Owner);
         if (gameMoveValidator(move))
         {
             validMoves.Add(move);
             if (returnIfAny)
                 return new ReadOnlyCollection<Move>(validMoves);
         }
     }
     return new ReadOnlyCollection<Move>(validMoves);
 }
开发者ID:ProgramFOX,项目名称:Chess.NET,代码行数:23,代码来源:Knight.cs


示例18: SetGame

 public void SetGame(ChessGame game)
 {
     this.game = game;
     curMoveIdx = -1;
     Refresh ();
 }
开发者ID:BackupTheBerlios,项目名称:csboard-svn,代码行数:6,代码来源:ChessGameView.cs


示例19: GameStart_Click

 private void GameStart_Click(object sender, RoutedEventArgs e)
 {
     AI_Information ai_a = AI_Construct(WhiteComboBox);
     AI_Information ai_b = AI_Construct(BlackComboBox);
     ChessGame chessGameWindow = new ChessGame(this, ai_a, ai_b);
     chessGameWindow.Show(); this.Hide();
 }
开发者ID:ZhouLuhan,项目名称:GraduateProject,代码行数:7,代码来源:MainWindow.xaml.cs


示例20: IsValidMove

        public override bool IsValidMove(Move move, ChessGame game)
        {
            ChessUtilities.ThrowIfNull(move, "move");
            ChessUtilities.ThrowIfNull(game, "game");
            Position origin = move.OriginalPosition;
            Position destination = move.NewPosition;

            Piece promotion = null;
            if (move.Promotion.HasValue && ValidPromotionPieces.Contains(move.Promotion.Value))
            {
                promotion = game.MapPgnCharToPiece(char.ToUpper(move.Promotion.Value), move.Player);
            }
            PositionDistance posDelta = new PositionDistance(origin, destination);
            if ((posDelta.DistanceX != 0 || posDelta.DistanceY != 1) && (posDelta.DistanceX != 1 || posDelta.DistanceY != 1)
                        && (posDelta.DistanceX != 0 || posDelta.DistanceY != 2))
                return false;
            if (Owner == Player.White)
            {
                if (origin.Rank > destination.Rank)
                    return false;
                if (destination.Rank == 8)
                {
                    if (promotion == null)
                        return false;
                    if (promotion.Owner != Player.White)
                        return false;
                    if (!ValidPromotionPieces.Contains(promotion.GetFenCharacter()))
                        return false;
                }
            }
            if (Owner == Player.Black)
            {
                if (origin.Rank < destination.Rank)
                    return false;
                if (destination.Rank == 1)
                {
                    if (promotion == null)
                        return false;
                    if (promotion.Owner != Player.Black)
                        return false;
                    if (!ValidPromotionPieces.Contains(promotion.GetFenCharacter()))
                        return false;
                }
            }
            bool checkEnPassant = false;
            if (posDelta.DistanceY == 2)
            {
                if ((origin.Rank != 2 && Owner == Player.White)
                    || (origin.Rank != 7 && Owner == Player.Black))
                    return false;
                if (origin.Rank == 2 && game.GetPieceAt(origin.File, 3) != null)
                    return false;
                if (origin.Rank == 7 && game.GetPieceAt(origin.File, 6) != null)
                    return false;
            }
            Piece pieceAtDestination = game.GetPieceAt(destination);
            if (posDelta.DistanceX == 0 && (posDelta.DistanceY == 1 || posDelta.DistanceY == 2))
            {
                if (pieceAtDestination != null)
                    return false;
            }
            else
            {
                if (pieceAtDestination == null)
                    checkEnPassant = true;
                else if (pieceAtDestination.Owner == Owner)
                    return false;
            }
            if (checkEnPassant)
            {
                ReadOnlyCollection<DetailedMove> _moves = game.Moves;
                if (_moves.Count == 0)
                {
                    return false;
                }
                if ((origin.Rank != 5 && Owner == Player.White)
                    || (origin.Rank != 4 && Owner == Player.Black))
                    return false;
                Move latestMove = _moves[_moves.Count - 1];
                if (latestMove.Player != ChessUtilities.GetOpponentOf(Owner))
                    return false;
                if (!(game.GetPieceAt(latestMove.NewPosition) is Pawn))
                    return false;
                if (game.GetPieceAt(latestMove.NewPosition).Owner == Owner)
                    return false;
                if (Owner == Player.White)
                {
                    if (latestMove.OriginalPosition.Rank != 7 || latestMove.NewPosition.Rank != 5)
                        return false;
                }
                else // (m.Player == Players.Black)
                {
                    if (latestMove.OriginalPosition.Rank != 2 || latestMove.NewPosition.Rank != 4)
                        return false;
                }
                if (destination.File != latestMove.NewPosition.File)
                    return false;
            }
            return true;
        }
开发者ID:ProgramFOX,项目名称:Chess.NET,代码行数:100,代码来源:Pawn.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# ChessPiece类代码示例发布时间:2022-05-24
下一篇:
C# ChessColor类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap