Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed row and column cogs from being excluded. #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Drise13
Copy link

@Drise13 Drise13 commented Jun 29, 2022

No description provided.

@Alligamanor
Copy link

Hi,
Are you still playing and using this functionality?
Your "fix" is just a workaround, but does not make the code do what it is intended for. You just allow all coordinates for Row and Col cogs.
However, looking at the function at what it is supposed to do. The function checks whether specific coordinates should be excluded for certain type of cogs, based on the number of out of bound coordinates and the max amount of accepted out of bound coordinates. Coordinates checked are the coordinates the cog influences, with its boosts.

"""
- `excludes_dict[type(cog)]' is a `set' of all coordinates where `cog' should not be placed.
- For example, if `cog' is of type `Up_Cog', then `excludes_dict[type(cog)]' should contain all coords on the top row of
the array.
- This dict is not necessary for the genetic algorithm to find an optimal array. It merely improves the convergence rate. 
"""
def get_excludes_dict(empties_set, cogs):
    cog_array = Cog_Array(empties_set)
    excludes_dict = {}
    for cog in cogs:
        if type(cog) not in excludes_dict and isinstance(cog, Boost_Cog):
            excludes_dict[type(cog)] = set()
            for coords in Coords_Iter(cog_array):
                num_oob_neighbors = sum((adj_coords.is_out_of_bounds()) for adj_coords in cog.get_influence(coords))
                if num_oob_neighbors > cog.get_max_oob_neighbors():
                    excludes_dict[type(cog)].add(coords)
    return excludes_dict

Looking at the original code I am also missing the not yet unlocked coordinates treated as being out of bounds. In my opinion you would do that. So I made the following changes.

num_oob_neighbors = sum((adj_coords.is_out_of_bounds() or adj_coords in empties_set) for adj_coords in cog.get_influence(coords))

Furthermore, we need to address the way Row en Col cogs are calculating their influence. This is done inside "cog_types.py".

class Row_Cog(Boost_Cog):
    def get_influence(self,coords):
        return map(
            lambda t: coords + Coords(t[0],t[1]),
            [(x,0) for x in itertools.chain(range(-NUM_COGS_HORI,0),range(1,NUM_COGS_HORI+1))]
        )

    def get_abbr(self):
        return "-"

    def get_max_oob_neighbors(self):
        return NUM_COGS_HORI


class Col_Cog(Boost_Cog):
    def get_influence(self,coords):
        return map(
            lambda t: coords + Coords(t[0],t[1]),
            [(0,y) for y in itertools.chain(range(-NUM_COGS_VERT,0),range(1,NUM_COGS_VERT+1))]
        )

    def get_abbr(self):
        return "|"

    def get_max_oob_neighbors(self):
        return NUM_COGS_VERT

Here I made the following adjustments.

First, the influence is not calculated correctly. For example, the Col cog has influence on all other cogs in the same column. However, the original code checks "NUM_COGS_VERT" number of coordinates in each direction, but the since the Col cog is also part of the column it has to check "-1". So "-NUM_COGS_VERT+1" and "NUM_COGS_VERT+1-1".

def get_influence(self,coords):
    return map(
        lambda t: coords + Coords(t[0],t[1]),
        [(0,y) for y in itertools.chain(range(-NUM_COGS_VERT+1,0),range(1,NUM_COGS_VERT))]
    )

# and the Row col will be
[(x,0) for x in itertools.chain(range(-NUM_COGS_HORI+1,0),range(1,NUM_COGS_HORI))]

So this fixes the number of coordinates influenced by the Row and Col cogs, but it does not address the number of max allowed out of bounds coordinates.
If you compare it with the simple Plus cog, that cog influences 4 coordinates and allows a max of 2 out of bounds neighbours. Or the Up cog influencing 6 coordinates allows a max of 3 out of bounds neighbours. So the author roughly allows half of the amount to be out of bounds.
However, the Row and Col cogs are different in the way that always half of the influenced coordinates are out of bounds, because we check the influence in both directions for "NUM_COGS_VERT-1". So we would need to allow at least half of the number of influenced coordinates plus we would allow half of the "real" coordinates to be out of bounds (in the case that you did not unlock coordinates yet). "(NUM_COGS_VERT-1) + ((NUM_COGS_VERT-1) / 2)"

def get_max_oob_neighbors(self):
        return (NUM_COGS_VERT-1) + ((NUM_COGS_VERT-1) / 2)

# But this could be a float in the case of odd numbers, so the make sure we have an integer rounded up. (this way you dont need to import the math library, you could also use ceil function of math library)
return (NUM_COGS_VERT-1) + (int(((NUM_COGS_VERT-1) / 2)) + (((NUM_COGS_VERT-1) % 2) > 0))

# And for the Row cog
return (NUM_COGS_HORI-1) + (int(((NUM_COGS_HORI-1) / 2)) + (((NUM_COGS_HORI-1) % 2) > 0))

I was too lazy to fork and commit my code, so I made this write up. If someone has any questions let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants