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


C# Piece.MovePosition方法代码示例

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


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

示例1: IsTheKingPutInCheck

    List<Vector2> IsTheKingPutInCheck(List<Vector2> moves, Piece piece)
    {
        //In this method I am going to simulate the board state and then
        //Move the piece in question to see if its movement will open
        //an attack route to the king, if it does the move will be prohibited.

        List<Vector2> allowedMoves = new List<Vector2>();

        Tile[,] clonedTiles = MakeVirtualTiles(tiles);

        Piece[] clonedPieces = MakeVirtualPieces(pieces);

        Piece pieceClone = new Piece();

        //Deep Clones the Peice so I can move it around.
        foreach (Piece clonedPiece in clonedPieces)
        {
            if (clonedPiece.MyCoordinates() == piece.MyCoordinates())
            {
                pieceClone = clonedPiece;
            }
        }

        Vector2 origin = piece.MyCoordinates();

        foreach (Vector2 move in moves)
        {
            pieceClone.MovePosition(move);

            //These did not help
            clonedTiles[(int)origin.x, (int)origin.y].occupied = false;
            clonedTiles[(int)move.x, (int)move.y].occupied = true;

            ThreatCheck(clonedTiles, clonedPieces);

            if (!CheckCheck(pieceClone.player, clonedPieces, clonedTiles))
            {
                allowedMoves.Add(move);
            }

            pieceClone.MovePosition(origin);

            clonedTiles[(int)origin.x, (int)origin.y].occupied = true;
            clonedTiles[(int)move.x, (int)move.y].occupied = false;
        }

        return allowedMoves;
    }
开发者ID:CharlesVI,项目名称:DoubleBlindChess,代码行数:48,代码来源:Main.cs

示例2: GetOutOfCheck

    List<Vector2> GetOutOfCheck(List<Vector2> moves, Piece piece)
    {
        //NOTE problem with pawns captureing other pawns to remove the king from check
        //By the time I get here I get 6 make Virtual Piece calls gotta fix that. (Should be 4) TODO

        // The way I do this will be horribly inneficent I think. If performance becomes an issue
        //I should head here first. Most notably if I pass a list instead of a single peice when
        //Used to determin checkmate it will reduce the generation of virtual stuff to once
        //Instead of once per piece.

        //TODO we gotta add captures to the equation.

        List<Vector2> allowedMoves = new List<Vector2>();

        Tile[,] virtualTiles = MakeVirtualTiles(tiles);
        Piece[] virtualPieces = MakeVirtualPieces(pieces);
        Piece virtualPiece = new Piece();

        //Clones the piece in question
        foreach (Piece vPiece in virtualPieces)
        {
            if (piece.MyCoordinates() == vPiece.MyCoordinates())
            {
                virtualPiece = vPiece;
            }
        }

        Vector2 origin = virtualPiece.MyCoordinates();

        Debug.Log(moves.Count + " moves to check");
        foreach (Vector2 move in moves)
        {
            foreach (Piece vPiece in virtualPieces)
            {
                if (vPiece.MyCoordinates() == move)
                {
                    Debug.Log("Captured @ " + move);
                    vPiece.captured = true;
                }
            }

            virtualPiece.MovePosition(move);

            UpdateTileOccupation(virtualTiles, virtualPieces);

            ClearThreats(virtualTiles);

            ThreatCheck(virtualTiles, virtualPieces);

            if (!CheckCheck(virtualPiece.player, virtualPieces, virtualTiles))
            {
                allowedMoves.Add(move);
            }

            //Return Peice to location and try next move.
            virtualPiece.MovePosition(origin);
        }

        return allowedMoves;
    }
开发者ID:CharlesVI,项目名称:DoubleBlindChess,代码行数:60,代码来源:Main.cs


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