I built a 3D Chess game which works flawlessly. But I would like to make some changes to the movement.
The piece is supposed to walk a number of tiles. For example with a range of 3 it can either move 3 to one direction (left for example), or 2 left 1 up/down, or 1 left 2 up/down.
Which minor change do I have to implement in my code for it to work?
private Vector2Int[] directions = new Vector2Int[]
{
Vector2Int.left,
Vector2Int.up,
Vector2Int.right,
Vector2Int.down,
new Vector2Int(1, 1),
new Vector2Int(1, -1),
new Vector2Int(-1, 1),
new Vector2Int(-1,- 1),
};
public override List<Vector2Int> SelectAvaliableSquares()
{
avaliableMoves.Clear();
float range = Board.BOARD_SIZE;
foreach (var direction in directions)
{
for (int i = 1; i <= range; i++)
{
Vector2Int nextCoords = occupiedSquare + direction * i;
Piece piece = board.GetPieceOnSquare(nextCoords);
if (!board.CheckIfCoordinatesAreOnBoard(nextCoords))
break;
if (piece == null)
TryToAddMove(nextCoords);
else if (!piece.IsFromSameTeam(this))
{
TryToAddMove(nextCoords);
break;
}
else if (piece.IsFromSameTeam(this))
break;
}
}
return avaliableMoves;
}
The given code is an example of the movement of an ordinary queen.
Added a picture to demonstrate the movement.
enter image description here
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…