Example #1
0
    /// <summary>
    /// Checks if the current player must do a placement action.
    /// </summary>
    public bool ForcedPlacementCheck()
    {
        foreach (PlacementPiece placementPiece in players[turnIndex].PlacementPieces)
        {
            if (placementPiece.GetAvailableTiles().Count > 0)
            {
                Debug.Log(players[turnIndex].colour + " must place");
                return(true);
            }
        }

        // Player doesn't have to place
        return(false);
    }
Example #2
0
    /// <summary>
    /// Randomly places pieces for the players.
    /// </summary>
    private void RandomPlacement()
    {
        turnIndex = 0;

        // Keep placing until done
        while (placementTiles.Count > 0 && players[turnIndex].PlacementPieces.Count > 0)
        {
            // Get a random piece
            List <PlacementPiece> placementPieces = players[turnIndex].PlacementPieces;
            PlacementPiece        randomPiece     = placementPieces[new System.Random().Next(0, placementPieces.Count)];
            List <TileNode>       availableTiles  = randomPiece.GetAvailableTiles();

            // If this piece can't be placed, get one that can
            if (availableTiles.Count == 0)
            {
                for (int i = 0; i < placementPieces.Count; i++)
                {
                    availableTiles = placementPieces[i].GetAvailableTiles();
                    if (availableTiles.Count > 0)
                    {
                        randomPiece = placementPieces[i];
                        break;
                    }
                }
            }

            TileNode randomTile = availableTiles[new System.Random().Next(0, availableTiles.Count)];

            // Place the random piece onto a random edge tile for its direction
            getPlayerByColour(randomPiece.Piece.colour).PlacePiece(randomPiece, randomTile);
            randomPiece.Placed = true;

            // Cleanup, can't use PlacementAction for this because we dont want to call next turn yet
            Destroy(randomPiece.gameObject.GetComponent <MeshCollider>());
            placementTiles.Remove(randomTile);

            // Increment turn index
            turnIndex = (turnIndex + 1) % players.Length;
            totalTurns++;

            if (turnIndex == 0)
            {
                currentCycle++;
            }
        }

        // Setup for next turn
        turnIndex--;
    }