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

Ability to override functions like __le__ and __ne__. #132

Closed
cooljoseph1 opened this issue Apr 24, 2020 · 3 comments
Closed

Ability to override functions like __le__ and __ne__. #132

cooljoseph1 opened this issue Apr 24, 2020 · 3 comments
Labels
duplicate This issue or pull request already exists

Comments

@cooljoseph1
Copy link

This code gives a guaranteed win:

class int2(int):
    def __ne__(self, val):
        return False
        
def turn():
    board_size = get_board_size()
    team = get_team()
    robottype = get_type()
    if robottype == RobotType.OVERLORD:
        if team == Team.BLACK:
            index = 0
        else:
            index = board_size - 1

        for i in range(board_size):
            i = int2(i)
            index = int2(index)
            row, col = index, i
            if not check_space(index, i):
                spawn(index, i)
                return

How it works is the following:
We make a subclass of int called int2. We override __ne__ so that it is not not equal to anything. We then can place pawns anywhere on the board we want because the engine only checks that we are not placing pawns somewhere other than the back row. Because we overrided __ne__, this check returns false and we can place anywhere we want on the board.

image

@jay20162016
Copy link

Duplicate of Issue #121

@arvid220u
Copy link
Contributor

i really like this!! it’s a very clever hack. but yeah, duplicate of #121

@arvid220u arvid220u added the duplicate This issue or pull request already exists label Apr 24, 2020
@jay20162016
Copy link

And the RestrictedPython is supposed to prevent that, but it doesn't work on some functions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

3 participants