Beispiel #1
0
    async def setup(self, args):
        self.__words = []
        self.__word_list = set(word.strip().lower()
                               for word in Language.dictionary.split('\n'))
        self.__current_turn_index = 0

        logger.info('Setting up a TicTacToe game...')
        if len(args) != 0 or (len(args) == 1 and args[0].lower() == 'help'):
            logger.debug(
                'Could not setup game, invalid arguments or user requested help'
            )
            return SetupFailure(
                f'**Command \'play {self.get_game_short_name()}\' Usage: **`>play {self.get_game_short_name()} [user-to-play]`'
            )
        elif len(self.players) < 2:
            logger.debug(
                'Could not setup game, user provided too few users to play')
            return SetupFailure('You must play with at least one opponent.')
        logger.debug('Passed standard checks setting up turn...')
        random.shuffle(self.players)
        self.__current_turn_index = 0
        await self.show()

        pidx = 0
        for player in self.players:
            if pidx == self.__current_turn_index:
                await self.channel.send(
                    f'{player.mention}, you\'ll go first! Give us a word to play!'
                )
            else:
                await self.channel.send(
                    f'{player.mention}, please wait for the first word.')
            pidx += 1

        return SetupSuccess(self)
Beispiel #2
0
    async def setup(self, args):
        logger.info('Setting up a Minesweeper game...')
        print(args)
        if len(args) != 3 or (len(args) == 1 and args[0].lower() == 'help'):
            logger.debug(
                'Could not setup game, invalid arguments or user requested help'
            )
            return SetupFailure(
                f'**Command \'play {self.get_game_short_name()}\' Usage: **`>play {self.get_game_short_name()} [board-size, amount-of-bombs]`'
            )
        elif len(self.players) > 1:
            logger.debug(
                'Could not setup game, user provided too many users to play')
            return SetupFailure(
                'You can\'t play Minesweeper with other people.')
        elif type(args[1]) != int or args[1] > 9 or args[1] < 2:
            logger.debug(
                'Could not setup game, user provided too big/small playfield')
            return SetupFailure(
                'Board size cannot be less than 2 or greater than 9')
        elif type(args[2]) != int or args[2] < 1 or args[2] >= (args[1]**2):
            logger.debug(
                'Could not setup game, user provided too many/few bombs')
            return SetupFailure(
                'Bomb count cannot be less than 1 or greater than the size of the board.'
            )
        logger.debug('Passed standard checks setting up turn...')

        self.__board = MineSweeperBoard(args[1], args[2]), MineSweeperBoard(
            args[1], args[2])
        amount = args[2]
        solved = self.__board[0]
        nbombs = 0
        while nbombs != amount:
            for x in range(len(solved.board)):
                if nbombs == amount:
                    break
                t = random.randint(0, len(solved.board) - 1)
                t2 = random.randint(0, len(solved.board) - 1)
                if math.floor(random.random() * len(solved.board)) % 2 == 0:
                    if not solved.is_mine(t, t2):
                        solved.board[t][t2] = '\N{BOMB}'
                        nbombs += 1

        for row in range(len(solved.board)):
            for col in range(len(solved.board[row])):
                if solved.is_mine(row, col):
                    continue
                solved.board[row][col] = str(solved.count_mines(row, col))

        await self.channel.send(
            f'{self.players[0].mention}, you are good to start! Just don\'t blow up :)'
        )
        await self.show()
        return SetupSuccess(self)
Beispiel #3
0
    async def setup(self, args):
        self.__board = [['⬛', '⬛', '⬛'], ['⬛', '⬛', '⬛'], ['⬛', '⬛', '⬛']]
        self.__p1 = '❌'
        self.__p2 = '⭕'
        self.__turns = 0
        self.__current_turn_index = 0

        logger.info('Setting up a TicTacToe game...')
        if len(args) > 0 or (len(args) == 1 and args[0].lower() == 'help'):
            logger.debug(
                'Could not setup game, invalid arguments or user requested help'
            )
            return SetupFailure(
                f'**Command \'play {self.get_game_short_name()}\' Usage: **`>play {self.get_game_short_name()} [user-to-play]`'
            )
        elif len(self.players) > 2:
            logger.debug(
                'Could not setup game, user provided too many users to play')
            return SetupFailure(
                'Why are you trying to play TicTacToe with more than 1 person? That\'s not how this works...'
            )
        elif len(self.players) < 2:
            logger.debug(
                'Could not setup game, user provided too few users to play')
            return SetupFailure('You can\'t play TicTacToe by yourself.')
        logger.debug('Passed standard checks setting up turn...')
        random.shuffle(self.players)
        self.__current_turn_index = 0
        await self.show()

        pidx = 0
        for player in self.players:
            if pidx == self.__current_turn_index:
                await self.channel.send(
                    f'{player.mention}, you go first! Good luck!')
            else:
                await self.channel.send(
                    f'{player.mention}, waiting for your turn...')
            pidx += 1

        return SetupSuccess(self)
Beispiel #4
0
    async def setup(self, args):
        if len(self.players) == 1:
            pass  # Singleplayer
        else:
            pass  # Multiplayer

        if len(args) == 0:
            pass  # No args were given
        else:
            if isinstance(args[0], int):  # Is the first arg an int?
                pass
            # ...

        if True:  # Some game conditions were met...
            # Setup who's turn it is
            # Show the initial state of the game
            await self.show()
            # Tell the game manager the setup was a success
            return SetupSuccess(self)
        else:  # Some game conditions were not met, thus the game cannot be setup...
            return SetupFailure(
                "The game can not be setup because of some default reason!")
Beispiel #5
0
    async def setup(self, args):
        self.__moves = 0
        self.__board = """
:black_circle::black_circle::black_circle::black_circle::black_circle::black_circle::black_circle::black_circle::black_circle::black_circle:
:black_circle::black_circle::black_circle::black_circle::black_circle::black_circle::black_circle::black_circle::black_circle::black_circle:
:black_circle::black_circle::black_circle::black_circle::black_circle::black_circle::black_circle::black_circle::black_circle::black_circle:
:black_circle::black_circle::black_circle::black_circle::black_circle::black_circle::black_circle::black_circle::black_circle::black_circle:
:black_circle::black_circle::black_circle::black_circle::black_circle::black_circle::black_circle::black_circle::black_circle::black_circle:
:black_circle::black_circle::black_circle::black_circle::black_circle::black_circle::black_circle::black_circle::black_circle::black_circle:
:black_circle::black_circle::black_circle::black_circle::black_circle::black_circle::black_circle::black_circle::black_circle::black_circle:
:black_circle::black_circle::black_circle::black_circle::black_circle::black_circle::black_circle::black_circle::black_circle::black_circle:
:black_circle::black_circle::black_circle::black_circle::black_circle::black_circle::black_circle::black_circle::black_circle::black_circle:
:black_circle::black_circle::black_circle::black_circle::black_circle::black_circle::black_circle::black_circle::black_circle::black_circle:
    """
        self.__current_turn_index = 0
        self._tokens = {
            "blue": ":blue_circle:",
            "red": ":red_circle:",
            "green": ":green_circle:",
            "orange": ":orange_circle:",
            "purple": ":purple_circle:",
            "yellow": ":yellow_circle:",
            "white": ":white_circle:",
            "brown": ":brown_circle:",
        }
        self._player_tokens = []

        logger.info('Setting up a Gomoku game...')

        if len(args) == 1 and args[0].lower() == 'help':
            logger.debug(
                'Could not setup game, invalid arguments or user requested help'
            )
            return SetupFailure(
                f'**Command \'play {self.get_game_short_name()}\' Usage: **`>play {self.get_game_short_name()} [users-to-play] (tokens-colors-player)`'
            )
        elif len(self.players) < 2:
            logger.debug(
                'Could not setup game, user provided too few users to play')
            return SetupFailure('You can\'t play Gomoku by yourself.')
        elif len(args) == len(self.players) and all(
                type(arg) == str and arg in self._tokens for arg in args):
            for arg in args:
                self._player_tokens.append(self._tokens[arg])
        elif len(args) == 0:
            self._player_tokens = [self._tokens[k]
                                   for k in self._tokens][:len(self.players)]
        else:
            logger.debug(
                'Could not setup game, invalid arguments or user requested help'
            )
            return SetupFailure(
                f'**Command \'play {self.get_game_short_name()}\' Usage: **`>play {self.get_game_short_name()} [users-to-play] (tokens-colors-player)`'
            )

        logger.debug('Passed standard checks setting up turn...')

        c = list(zip(self.players, self._player_tokens))
        random.shuffle(c)
        self.players, self._player_tokens = zip(*c)
        self.players = list(self.players)
        self._player_tokens = list(self._player_tokens)

        self.__current_turn_index = 0
        await self.show()

        pidx = 0
        for player in self.players:
            if pidx == self.__current_turn_index:
                await self.channel.send(
                    f'{player.mention} your token is {self._player_tokens[pidx]}, you go first! Good luck!'
                )
            else:
                await self.channel.send(
                    f'{player.mention} your token is {self._player_tokens[pidx]}, waiting for your turn...'
                )
            pidx += 1

        return SetupSuccess(self)
Beispiel #6
0
    async def setup(self, args):
        self.__shots = 0
        self.__gun = 6
        self.__last_man_standing = True
        self.__current_turn_index = 0

        logger.info('Setting up a RussianRoulette game...')
        if len(args) == 2:
            if (type(args[0]) == bool
                    and type(args[1]) == int) or (type(args[0]) == int
                                                  and type(args[1]) == bool):
                if type(args[0]) == bool:
                    self.__last_man_standing = args[0]
                else:
                    self.__gun = args[0]
                if type(args[1]) == bool:
                    self.__last_man_standing = args[1]
                else:
                    self.__gun = args[1]
            else:
                logger.debug('Could not setup game, invalid arguments')
                return SetupFailure(
                    f'**Command \'play {self.get_game_short_name()}\' Usage: **`>play {self.get_game_short_name()} [users-to-play, ...] (number_of_empty_chambers=5 (int)) (last_man_standing=false (boolean))`'
                )
        elif len(args) == 1:
            if type(args[0]) == bool or type(args) == int:
                if type(args[0]) == bool:
                    self.__last_man_standing = args[0]
                else:
                    self.__gun = args[0]
            else:
                logger.debug('Could not setup game, invalid arguments')
                return SetupFailure(
                    f'**Command \'play {self.get_game_short_name()}\' Usage: **`>play {self.get_game_short_name()} [users-to-play, ...] (number_of_empty_chambers=5 (int)) (last_man_standing=false (boolean))`'
                )
        elif len(args) > 0 and (len(args) == 1 and args[0].lower() == 'help'):
            logger.debug(
                'Could not setup game, invalid arguments or user requested help'
            )
            return SetupFailure(
                f'**Command \'play {self.get_game_short_name()}\' Usage: **`>play {self.get_game_short_name()} [users-to-play, ...] (number_of_empty_chambers=5) (last_man_standing=False)`'
            )
        elif len(self.players) < 2:
            logger.debug(
                'Could not setup game, user provided too few users to play')
            return SetupFailure('You can\'t play RussianRoulette by yourself.')
        if self.__gun < 1 or self.__gun > 1000:
            logger.debug(
                'Could not setup game, user provided too big playfield')
            return SetupFailure('Invalid gun size.')
        logger.debug('Passed standard checks setting up turn...')
        random.shuffle(self.players)
        self.__current_turn_index = 0
        await self.channel.send(
            "Playing with a gun with {} chambers, {}.".format(
                self.__gun, "last man standing"
                if self.__last_man_standing else "one bullet"))

        pidx = 0
        for player in self.players:
            if pidx == self.__current_turn_index:
                await self.channel.send(
                    "<@{0}>, you go first! Good luck!".format(player.id))
            else:
                await self.channel.send(
                    "<@{0}>, let\'s see what happens...".format(player.id))
            pidx += 1

        await self.show()
        return SetupSuccess(self)