예제 #1
0
    public IEnumerator goFish()
    {
        ResourceTile mostTile = grid.resourceTiles.ElementAt(UnityEngine.Random.Range(0, grid.resourceTiles.Count)).Value;

        int stagger = UnityEngine.Random.Range(5, 30);

        for (int i = 0; i < stagger; i++)
        {
            yield return(null);
        }

        yield return(StartCoroutine(moveBoat(mostTile.tileIndex())));

        mostTile.isHere(gameObject);
        //fish(mostTile.tileIndex());
        mostTile.fishingHere(gameObject);

        yield return(null);

        mostTile.getFish(gameObject);

        currentGrossProfit = currentCatch * fishPrice;
        currentProfit      = currentCatch * fishPrice - costs;

        yield return(null);

        mostTile.leftHere(gameObject);
    }
예제 #2
0
    public IEnumerator goFish()
    {
        Debug.Log("Grid " + grid);
        Debug.Log("ResourceTiles " + grid.resourceTiles.Count);

        ResourceTile mostTile = grid.resourceTiles.ElementAt(UnityEngine.Random.Range(0, grid.resourceTiles.Count)).Value;

        int stagger = UnityEngine.Random.Range(5, 30);

        for (int i = 0; i < stagger; i++)
        {
            yield return(null);
        }

        yield return(StartCoroutine(moveBoat(mostTile.tileIndex())));

        mostTile.isHere(gameObject);
        //fish(mostTile.tileIndex());
        mostTile.fishingHere(gameObject);

        yield return(null);

        entCatch = mostTile.getFish(gameObject);


        yield return(null);

        mostTile.leftHere(gameObject);
    }
예제 #3
0
    IEnumerator toRandomDest()
    {
        if (grid != null)
        {
            ResourceTile mostTile = grid.resourceTiles.ElementAt(Random.Range(0, grid.resourceTiles.Count)).Value;

            moveBoat(mostTile.tileIndex());
            mostTile.isHere(gameObject);
            //fish(mostTile.tileIndex());
            mostTile.fishingHere(gameObject);
            yield return(null);

            mostTile.getFish(gameObject);

            currentGrossProfit = currentCatch * fishPrice;
            currentProfit      = currentCatch * fishPrice - costs;

            yield return(new WaitForSeconds(1f));

            mostTile.leftHere(gameObject);

            keepFishing(mostTile.tileIndex());
        }
    }
예제 #4
0
    ResourceTile bestNeighbor(ResourceTile tile)
    {
        List <Vector3Int> neighbors = getNeighbors(tile.tileIndex());

        float mostResource = tile.currentResource / (tile.boatsHere.Count + 1);

        ResourceTile mostTile = tile;

        for (int i = 0; i < neighbors.Count; i++)
        {
            ResourceTile rtile = grid.getTileAt(neighbors[i]);
            float        bla   = rtile.currentResource / (rtile.boatsHere.Count + 1);

            // Debug.Log(bla);

            if (bla > mostResource)
            {
                mostResource = bla;
                mostTile     = rtile;
            }
        }

        return(mostTile);
    }
예제 #5
0
    IEnumerator toBestNeighborDestQuota(Vector3Int tileIndex)
    {
        float             totalTime = sim.weektime;
        List <Vector3Int> neighbors = getNeighbors(tileIndex);
        //float mostResource = 0;
        ResourceTile mostTile = grid.getTileAt(tileIndex.x, tileIndex.y);

        //stagger
        int framerate = (int)(1f / Time.unscaledDeltaTime);
        int stagger   = 0;

        if (timer.month == 1)
        {
            yearCatch  = 0;
            yearProfit = 0;
        }

        else
        {
            stagger = Random.Range(0, (int)(framerate - framerate * .1f));

            for (int i = 0; i < stagger; i++)
            {
                totalTime -= Time.deltaTime;
                yield return(null);
            }
        }

        totalTime -= Time.deltaTime;

        //bit of an exploration chance, the less profit the more likely the exploration;
        float exploration          = Random.Range(0f, 1f);
        float explorationThreshold = currentGrossProfit / (fishPrice * capacity * efficiency);

        if (exploration > explorationThreshold)
        {
            mostTile = bestNeighbor(grid.resourceTiles.ElementAt(Random.Range(0, grid.resourceTiles.Count)).Value);
        }

        else
        {
            mostTile = bestNeighbor(grid.getTileAt(tileIndex));
        }

        //Debug.Log("Most resource: " + mostResource);
        //Debug.Log("Most tile: [" + mostTile.tileIndex().x + ", " + mostTile.tileIndex().y + "]");
        moveBoat(mostTile.tileIndex());

        mostTile.isHere(gameObject);
        //fish(mostTile.tileIndex());

        mostTile.fishingHere(gameObject);
        yield return(null);

        mostTile.getFish(gameObject, quota);
        quota -= currentCatch;
        //Debug.Log("Quota : " + quota);
        yearCatch += currentCatch;

        currentGrossProfit = currentCatch * fishPrice;
        currentProfit      = currentCatch * fishPrice - costs;
        yearProfit        += currentProfit;
        totalProfit       += currentProfit;

        yield return(new WaitForSeconds(totalTime));

        mostTile.leftHere(gameObject);

        //yearly reckoning

        if (timer.month == 12)
        {
            if (yearProfit < 250)
            {
                die();
            }
            // else keepFishingQuota(mostTile.tileIndex());
        }

        if (quota > 0)
        {
            keepFishingQuota(mostTile.tileIndex());
        }
        else
        {
            moveBoat(homeTileIndex);
            stayHomeAndWait();
        }
    }