Esempio n. 1
0
    //TODO: BUG, CHANGE ALGORITHM
    bool IWallVerifier.HasVerticalWall(Safe2DArray fields, TileField currentField, bool isWhiteTurn)
    {
        var currentPieceType = isWhiteTurn ? ColorType.WHITE : ColorType.BLACK;

        for (int i = 0; i < 5; i++)
        {
            int positiveIndex = currentField.Coordinates.x + i;
            if (positiveIndex <= 4)
            {
                if (!(currentPieceType == fields[positiveIndex, currentField.Coordinates.y].Piece?.type))
                {
                    return(false);
                }
            }

            int negativeIndex = currentField.Coordinates.x - i;
            if (negativeIndex >= 0)
            {
                if (!(currentPieceType == fields[negativeIndex, currentField.Coordinates.y].Piece?.type))
                {
                    return(false);
                }
            }
        }

        return(true);
    }
Esempio n. 2
0
    bool ICaptureVerifier.VerifyCapture(Safe2DArray fields, TileField currentField, ColorType allyColor)
    {
        var coordinates = new Coordinates(currentField);

        Coordinates[] coordsToVerify = { coordinates.up, coordinates.right, coordinates.down, coordinates.left };

        for (int i = 0; i < coordsToVerify.Length; i++)
        {
            //Verifying the piece adjacent to the currentField
            //[farTile][inBetweenTile][currentTile]
            var farCoordinates = coordsToVerify[i];
            var inBetweenTile  = fields[coordsToVerify[i]];

            if (currentField.Coordinates.x > coordsToVerify[i].x)
            {
                farCoordinates.x--;
            }
            else if (currentField.Coordinates.x < coordsToVerify[i].x)
            {
                farCoordinates.x++;
            }
            else if (currentField.Coordinates.y < coordsToVerify[i].y)
            {
                farCoordinates.y++;
            }
            else if (currentField.Coordinates.y > coordsToVerify[i].y)
            {
                farCoordinates.y--;
            }

            var farTile = fields[farCoordinates];

            //Verifying the adjacent tile is an enemy
            if (inBetweenTile != null &&
                inBetweenTile.Piece != null &&
                inBetweenTile.Piece.type != allyColor)
            {
                //Veryfying if the far tile is an ally
                if (farTile != null &&
                    farTile.Piece != null &&
                    farTile.Piece.type == allyColor)
                {
                    //if the inBetweenPiece is on the middle, it can't be captured
                    if (inBetweenTile.Coordinates.x != 2 ||
                        inBetweenTile.Coordinates.y != 2)
                    {
                        inBetweenTile.Capture();
                        return(true);
                    }
                }
            }
        }

        return(false);
    }
Esempio n. 3
0
    private void CreateField()
    {
        var row     = 0;
        var column  = 0;
        var isWhite = true;

        _fields = new Safe2DArray(5, 5);
        foreach (Transform field in tileFieldParent)
        {
            if (row == 5)
            {
                column++;
                row = 0;
            }

            _fields[row, column] = field.GetComponent <TileField> ().Initialize(row, column, isWhite);
            isWhite = !isWhite;
            row++;
        }
    }