diff --git a/disgames/__main__.py b/disgames/__main__.py index b28ee1f..c118827 100644 --- a/disgames/__main__.py +++ b/disgames/__main__.py @@ -9,12 +9,16 @@ VersionInfo = disgames.VersionInfo def version() -> None: - entries = [] + entries = [ + '- Python v{0.major}.{0.minor}.{0.micro}-{0.releaselevel}'.format( + sys.version_info + ) + ] + - entries.append('- Python v{0.major}.{0.minor}.{0.micro}-{0.releaselevel}'.format(sys.version_info)) version_info: VersionInfo = VersionInfo(major=2, minor=0, micro=1) entries.append('- Disgames v{0.major}.{0.minor}.{0.micro}'.format(version_info)) - entries.append(f'- aiohttp v{aiohttp.__version__}') + entries.append(f'- aiohttp v{aiohttp.__version__}') entries.append(f'- Chess v{chess.__version__}') uname = platform.uname() diff --git a/disgames/mixins/battleship.py b/disgames/mixins/battleship.py index a74b968..e4dc452 100644 --- a/disgames/mixins/battleship.py +++ b/disgames/mixins/battleship.py @@ -42,9 +42,11 @@ async def on_reaction_add(self, reaction, userr): def format_battleships_board(self, board): """Format the battleship board""" lst = ["⏹1️⃣2️⃣3️⃣4️⃣5️⃣6️⃣7️⃣8️⃣"] - dct = {} - for i in range(1, 10): - dct[i] = f"{i}\N{variation selector-16}\N{combining enclosing keycap}" + dct = { + i: f"{i}\N{variation selector-16}\N{combining enclosing keycap}" + for i in range(1, 10) + } + for num, row in enumerate(board, start=1): scn_lst = [dct[num]] for column in row: @@ -56,8 +58,7 @@ def has_won_battleship(self, board): """Checks if either players died""" for x in board: for y in x: - if y != "🌊" or y != "🔥": - return False + return False return True @commands.command() diff --git a/disgames/mixins/checkers.py b/disgames/mixins/checkers.py index 8dc4c20..d250daf 100644 --- a/disgames/mixins/checkers.py +++ b/disgames/mixins/checkers.py @@ -14,7 +14,7 @@ def format_checkers_board(self, board): lst = ["⏹️" + "".join([dct[str(i + 1)] for i in range(len(board[0]))])] for x, row in enumerate(board): scn_lst = [dct[str(x + 1)]] - for y, column in enumerate(row): + for column in row: scn_lst.append(dct[column]) lst.append("".join(scn_lst)) return "\n".join(lst) @@ -80,15 +80,17 @@ async def checkers(self, ctx, member: discord.Member): continue if direction not in opts: await ctx.send( - f"Invalid syntax: Correct directions ul (up left), dl (down left), ur (up right), dr (down right)", + 'Invalid syntax: Correct directions ul (up left), dl (down left), ur (up right), dr (down right)', delete_after=5, ) + continue - elif not len(coors) == 2: + elif len(coors) != 2: await ctx.send( - f"Invalid syntax: The coordinates entered are invalid", + 'Invalid syntax: The coordinates entered are invalid', delete_after=5, ) + continue try: await inp.delete() @@ -97,11 +99,11 @@ async def checkers(self, ctx, member: discord.Member): direction = opts[direction] if direction == 1: inc = (-1, -1) - if direction == 2: + elif direction == 2: inc = (1, -1) - if direction == 3: + elif direction == 3: inc = (-1, 1) - if direction == 4: + elif direction == 4: inc = (1, 1) try: x, y = int(coors[0]) - 1, int(coors[1]) - 1 diff --git a/disgames/mixins/chess.py b/disgames/mixins/chess.py index e69a638..fdf3102 100644 --- a/disgames/mixins/chess.py +++ b/disgames/mixins/chess.py @@ -51,10 +51,11 @@ def create_chess_board(self, board, turn, member): ) e.add_field(name="Turn", value=turn.mention, inline=False) e.add_field( - name=f"Legal moves", - value=", ".join([f"`{str(i)}`" for i in board.legal_moves]), + name='Legal moves', + value=", ".join([f'`{i}`' for i in board.legal_moves]), inline=False, ) + e.add_field(name="Check", value=board.is_check(), inline=False) if board.halfmove_clock >= 45: e.add_field(name="Half move clock", value=board.halfmove_clock) @@ -82,7 +83,7 @@ def get_best_chess_move(self, board, smort_level): @commands.command("chess") async def chess(self, ctx, member: discord.Member = None): """a board game of strategic skill for two players, played on a chequered board on which each playing piece is moved according to precise rules. The object is to put the opponent's king under a direct attack from which escape is impossible""" - if member == None: + if member is None: if not self.stockfish_path: raise PathNotFound await ctx.send("Please enter a a difficulty level from 0-20") @@ -174,19 +175,18 @@ async def chess(self, ctx, member: discord.Member = None): await ctx.send("Can't go back", delete_after=5) continue else: - if inp.author == turn: - try: - move = chess.Move.from_uci(inp.content.lower()) - board.push(move) - except ValueError: - await ctx.send("Invalid move", delete_after=5) - continue - try: - await inp.delete() - except discord.Forbidden: - pass - else: + if inp.author != turn: continue + try: + move = chess.Move.from_uci(inp.content.lower()) + board.push(move) + except ValueError: + await ctx.send("Invalid move", delete_after=5) + continue + try: + await inp.delete() + except discord.Forbidden: + pass turn = member if turn == ctx.author else ctx.author won = self.has_won_chess( board, member if turn == ctx.author else ctx.author diff --git a/disgames/mixins/connect4.py b/disgames/mixins/connect4.py index 2c95566..372873b 100644 --- a/disgames/mixins/connect4.py +++ b/disgames/mixins/connect4.py @@ -141,7 +141,6 @@ def minimax_connect4(self, board, depth, isMaximizing): board[x][y] = " " if score > bestScore: bestScore = score - return bestScore else: bestScore = 800 for x, y in self.get_empty_connect4(board): @@ -150,14 +149,14 @@ def minimax_connect4(self, board, depth, isMaximizing): board[x][y] = " " if score < bestScore: bestScore = score - return bestScore + + return bestScore def make_bot_move_connect4(self, board, difficulty): """Returns the best move the bot can take""" if difficulty == 1: - x, y = random.choice([move for move in self.get_empty_connect4(board)]) + x, y = random.choice(list(self.get_empty_connect4(board))) board[x][y] = 'b' - return board else: bestScore = -800 bestMove = 0 @@ -169,7 +168,8 @@ def make_bot_move_connect4(self, board, difficulty): bestScore = score bestMove = x, y board[bestMove[0]][bestMove[1]] = 'b' - return board + + return board @commands.command() async def connect4(self, ctx, member: discord.Member = None): @@ -205,14 +205,14 @@ async def connect4(self, ctx, member: discord.Member = None): ) if inp.content.lower() in ["stop", "end", "cancel"]: return await ctx.send("Ended the game") - if not len(inp.content) == 1: + if len(inp.content) != 1: continue try: x = int(inp.content) - 1 except ValueError: await ctx.send(f"Invalid Syntax: {inp.content} is not a number") continue - if not x in range(7): + if x not in range(7): await ctx.send( f"Invalid syntax: {inp.content} isnt a valid place on the board" ) @@ -276,7 +276,7 @@ async def connect4(self, ctx, member: discord.Member = None): ) if inp.content.lower() in ["stop", "end", "cancel"]: return await ctx.send("Ended the game") - if not len(inp.content) == 1: + if len(inp.content) != 1: continue try: x = int(inp.content) - 1 diff --git a/disgames/mixins/madlib.py b/disgames/mixins/madlib.py index 3da094f..ebd1525 100644 --- a/disgames/mixins/madlib.py +++ b/disgames/mixins/madlib.py @@ -47,4 +47,4 @@ async def madlib(self, ctx, min: int = 5, max: int = 25): await ctx.send(string) except KeyError: - return await ctx.send(f"Invalid syntax: invalid arguments entered") + return await ctx.send('Invalid syntax: invalid arguments entered') diff --git a/disgames/mixins/minesweeper.py b/disgames/mixins/minesweeper.py index 0b5ab5d..8151ed3 100644 --- a/disgames/mixins/minesweeper.py +++ b/disgames/mixins/minesweeper.py @@ -52,7 +52,7 @@ def get_coors(self, coordinate): x = int(digit) - 1 y = ord(letter) - ord("a") - if (not x in range(10)) or (not y in range(10)): + if x not in range(10) or y not in range(10): raise commands.BadArgument( "Invalid syntax: Entered coordinates aren't on the board" ) @@ -64,8 +64,9 @@ def format_minesweeper_board(self, board): for i in range(1, 10): dct[str(i)] = f"{i}\N{variation selector-16}\N{combining enclosing keycap}" lst = [ - f":stop_button::regional_indicator_a::regional_indicator_b::regional_indicator_c::regional_indicator_d::regional_indicator_e::regional_indicator_f::regional_indicator_g::regional_indicator_h::regional_indicator_i::regional_indicator_j:" + ':stop_button::regional_indicator_a::regional_indicator_b::regional_indicator_c::regional_indicator_d::regional_indicator_e::regional_indicator_f::regional_indicator_g::regional_indicator_h::regional_indicator_i::regional_indicator_j:' ] + for num, row in enumerate(board, start=1): lst.append(dct[str(num)]+''.join([dct[str(column)] for column in row])) return "\n".join(lst) @@ -110,10 +111,7 @@ def has_won_minesweeper(self, visible_board, board): if num == ((len(board) * len(board[0])) - len(bombs)): return True - for bomb in bombs: - if not visible_board[int(bomb[0])][int(bomb[1])] == "f": - return False - return True + return all(visible_board[int(bomb[0])][int(bomb[1])] == "f" for bomb in bombs) def reveal_all(self, visible_board, board): for x in range(len(visible_board)): @@ -121,7 +119,7 @@ def reveal_all(self, visible_board, board): if visible_board[x][y] == " ": visible_board[x][y] = board[x][y] elif visible_board[x][y] == 'f': - if not board[x][y] == 'b': + if board[x][y] != 'b': visible_board[x][y] = 'x' return visible_board @@ -170,16 +168,15 @@ async def minesweeper(self, ctx): color=discord.Color.blurple(), ), ) - else: - if visible_board[x][y] not in [" ","f"]: - await ctx.send( - f"Invalid Syntax: {coors} is already revealed", - delete_after=5, - ) - continue - visible_board[x][y] = str(grid[x][y]) - if visible_board[x][y] == "0": - visible_board = self.reveal_zeros(visible_board, grid, x, y) + if visible_board[x][y] not in [" ","f"]: + await ctx.send( + f"Invalid Syntax: {coors} is already revealed", + delete_after=5, + ) + continue + visible_board[x][y] = str(grid[x][y]) + if visible_board[x][y] == "0": + visible_board = self.reveal_zeros(visible_board, grid, x, y) elif type_.lower() in ["flag", "f"]: if visible_board[x][y] != " ": await ctx.send( diff --git a/disgames/mixins/snake.py b/disgames/mixins/snake.py index f1e8d5d..1d841af 100644 --- a/disgames/mixins/snake.py +++ b/disgames/mixins/snake.py @@ -21,10 +21,8 @@ def get_head_position(self): return self.snake[0] def point(self, pt): - if self.length > 1 and (pt[0] * -1, pt[1] * -1) == self.direction: - pass - else: - self.direction = pt + if self.length <= 1 or (pt[0] * -1, pt[1] * -1) != self.direction: + self.direction = pt def move(self): cur = self.snake[0] diff --git a/disgames/mixins/snl.py b/disgames/mixins/snl.py index 8c8c881..c4078a0 100644 --- a/disgames/mixins/snl.py +++ b/disgames/mixins/snl.py @@ -9,9 +9,7 @@ def __init__(self, bot): def format_snl_board(self, board): dct = {' ':'⬛', 's':'🐍', 'l':'🪜', 'p1':'🔴', 'p2':'🟡', 'p3':'🟢', 'p4':'🔵'} - lst = [] - for row in board: - lst.append(''.join([dct[column] for column in row])) + lst = [''.join([dct[column] for column in row]) for row in board] return '\n'.join(lst) def create_board(self): @@ -33,11 +31,12 @@ async def snl(self, ctx, players: commands.Greedy[discord.Member]=[]): if len(players) > 4: return await ctx.send("Can't have more than 4 people playing") tokens = {'p1':'🔴', 'p2':'🟡', 'p3':'🟢', 'p4':'🔵'} - indexes = {} - for player in players: - indexes[player] = [9,0] + indexes = {player: [9,0] for player in players} board = self.create_board() - player_string = f' '.join([f"{player.mention}: {tokens['p'+str(num)]}" for num, player in enumerate(players, start=1)]) + player_string = ' '.join([ + f"{player.mention}: {tokens['p'+str(num)]}" + for num, player in enumerate(players, start=1) + ]) embed = discord.Embed(title='Snakes and Ladders', description=f"React to '🎲' to roll your dice\n\n{player_string}\n{self.format_snl_board(board)}", color=discord.Color.blurple()) msg = await ctx.send(embed=embed) await msg.add_reaction('🎲') @@ -61,19 +60,15 @@ async def snl(self, ctx, players: commands.Greedy[discord.Member]=[]): if str(reaction) == '🏳️': players.remove(user) await ctx.send(f"{user.mention} leaves") - else: - if user != player: - continue + elif user != player: + continue await ctx.send(f'{player.mention} rolled a {number}', delete_after=5) board[index[0]][index[1]] = ' ' past_number = index[1] if index[0]%2: index[1] += number - else: - if index[0] == 0 and (index[1] - number) < 0: - pass - else: - index[1] -= number + elif index[0] != 0 or index[1] - number >= 0: + index[1] -= number if (index[1]) > 9 or (index[1]) < 0 and index[1] != 0: index[0] -= 1 if index[0]%2: diff --git a/disgames/mixins/soko.py b/disgames/mixins/soko.py index ca43323..cc61bc3 100644 --- a/disgames/mixins/soko.py +++ b/disgames/mixins/soko.py @@ -26,9 +26,7 @@ def format_soko_board(self, board): } lst = [] for i in board: - scn_lst = [] - for thing in i: - scn_lst.append(dct[thing]) + scn_lst = [dct[thing] for thing in i] lst.append("".join(scn_lst)) return "\n".join(lst) @@ -40,8 +38,7 @@ def create_soko_board(self, difficulty_level): num1 = random.randint(5, 9) num2 = random.randint(5, 9) num3 = 1 + difficulty_level // 5 - if num3 > 7: - num3 = 7 + num3 = min(num3, 7) board = [[" " for i in range(num1)] for i in range(num2)] x, y = random.randint(0, len(board) - 1), random.randint(0, len(board[0]) - 1) board[x][y] = "p" @@ -71,14 +68,14 @@ def get_player(self, board): """Returnes the x,y coordinates of the player""" for x, i in enumerate(board): for y, thing in enumerate(i): - if thing == "p" or thing == "tp": + if thing in ["p", "tp"]: return x, y def has_won_soko(self, board): """Checks if there are no more t on the board""" for x in board: for y in x: - if y == "t" or y == "tp": + if y in ["t", "tp"]: return False return True diff --git a/disgames/mixins/sudoko.py b/disgames/mixins/sudoko.py index 2e13fdd..0208bdc 100644 --- a/disgames/mixins/sudoko.py +++ b/disgames/mixins/sudoko.py @@ -36,11 +36,7 @@ def create_sudoko_board(self, difficulty): y = random.randint(0, 8) while num in board[x]: num = str(random.randint(1, 9)) - h = False - for i in range(9): - if num in board[i][y]: - h = True - break + h = any(num in board[i][y] for i in range(9)) while h: num = str(random.randint(1, 9)) h = False @@ -182,21 +178,19 @@ async def sudoko(self, ctx): continue elif str(num) in board[x]: await ctx.send( - f"Invalid syntax: There is a another {str(num)} on the same row", + f'Invalid syntax: There is a another {num} on the same row', delete_after=5, ) + continue else: - h = False - for i in range(9): - if str(num) in board[i][y]: - h = True - break + h = any(str(num) in board[i][y] for i in range(9)) if h: await ctx.send( - f"Invalid syntax: There is a another {str(num)} on the same column", + f'Invalid syntax: There is a another {num} on the same column', delete_after=5, ) + continue if x in range(3): x_ = 0 @@ -223,9 +217,10 @@ async def sudoko(self, ctx): ] if str(num) in lst: await ctx.send( - f"Invalid syntax: There is a another {str(num)} on the same 3x3", + f'Invalid syntax: There is a another {num} on the same 3x3', delete_after=5, ) + continue board[x][y] = str(num) if self.has_won_sudoko(board): diff --git a/disgames/mixins/ttt.py b/disgames/mixins/ttt.py index f8d6a8e..9e82489 100644 --- a/disgames/mixins/ttt.py +++ b/disgames/mixins/ttt.py @@ -43,7 +43,6 @@ def minimax_ttt(self, board, depth, isMaximizing): board[x][y] = " " if score > bestScore: bestScore = score - return bestScore else: bestScore = 800 for x, y in self.get_empty_ttt(board): @@ -52,7 +51,8 @@ def minimax_ttt(self, board, depth, isMaximizing): board[x][y] = " " if score < bestScore: bestScore = score - return bestScore + + return bestScore def make_bot_move_ttt(self, board, difficulty): """Returns the best move the bot can take""" @@ -60,17 +60,16 @@ def make_bot_move_ttt(self, board, difficulty): return random.choice( [str(x) + str(y) for x, y in self.get_empty_ttt(board)] ) - else: - bestScore = -800 - bestMove = 0 - for x, y in self.get_empty_ttt(board): - board[x][y] = "o" - score = self.minimax_ttt(board, 0, False) - board[x][y] = " " - if score > bestScore: - bestScore = score - bestMove = str(x), str(y) - return bestMove + bestScore = -800 + bestMove = 0 + for x, y in self.get_empty_ttt(board): + board[x][y] = "o" + score = self.minimax_ttt(board, 0, False) + board[x][y] = " " + if score > bestScore: + bestScore = score + bestMove = str(x), str(y) + return bestMove def make_ttt_move(self, move, board, turn): """Checks if `move` is a valid move or not""" @@ -89,15 +88,13 @@ def make_ttt_move(self, move, board, turn): False, f"Invalid Syntax: {move} isn't a valid place on the board, Please try again", ) - else: - if board[int(move[0]) - 1][int(move[1]) - 1] != " ": - return ( - False, - f"Invalid Syntax: {move} has already been chosen, Please try again", - ) - else: - board[int(move[0]) - 1][int(move[1]) - 1] = turn - return True, board + if board[int(move[0]) - 1][int(move[1]) - 1] != " ": + return ( + False, + f"Invalid Syntax: {move} has already been chosen, Please try again", + ) + board[int(move[0]) - 1][int(move[1]) - 1] = turn + return True, board def has_won_ttt(self, board): """Checks if someone won, returns True and the winner if someone won, returns False and "tie" if it was a tie""" @@ -114,14 +111,14 @@ def has_won_ttt(self, board): if (board[0][2] == board[1][1] == board[2][0]) and board[0][2] != BLANK: return (True, board[0][2]) - if sum([i.count(BLANK) for i in board]) == 0: + if sum(i.count(BLANK) for i in board) == 0: return (False, "tie") return (None, "h") @commands.command(aliases=["ttt"]) async def tictactoe(self, ctx: commands.Context, member: discord.Member = None): """two players take turns marking the spaces in a three-by-three grid with X or O. The player who succeeds in placing three of their marks in a horizontal, vertical, or diagonal row is the winner""" - if member == None: + if member is None: turn = ctx.author board = [[" " for i in range(3)] for i in range(3)] await ctx.send("Choose ai difficulty, easy/hard:") diff --git a/disgames/mixins/ttt_reactions.py b/disgames/mixins/ttt_reactions.py index 7090cf0..fcac10f 100644 --- a/disgames/mixins/ttt_reactions.py +++ b/disgames/mixins/ttt_reactions.py @@ -43,7 +43,6 @@ def minimax_ttt_reactions(self, board, depth, isMaximizing): board[x][y] = " " if score > bestScore: bestScore = score - return bestScore else: bestScore = 800 for x, y in self.get_empty_ttt_reactions(board): @@ -52,7 +51,8 @@ def minimax_ttt_reactions(self, board, depth, isMaximizing): board[x][y] = " " if score < bestScore: bestScore = score - return bestScore + + return bestScore def make_bot_move_ttt_reactions(self, board, difficulty): """Returns the best move the bot can take""" @@ -60,17 +60,16 @@ def make_bot_move_ttt_reactions(self, board, difficulty): return random.choice( [str(x) + str(y) for x, y in self.get_empty_ttt_reactions(board)] ) - else: - bestScore = -800 - bestMove = 0 - for x, y in self.get_empty_ttt_reactions(board): - board[x][y] = "o" - score = self.minimax_ttt_reactions(board, 0, False) - board[x][y] = " " - if score > bestScore: - bestScore = score - bestMove = str(x) + str(y) - return bestMove + bestScore = -800 + bestMove = 0 + for x, y in self.get_empty_ttt_reactions(board): + board[x][y] = "o" + score = self.minimax_ttt_reactions(board, 0, False) + board[x][y] = " " + if score > bestScore: + bestScore = score + bestMove = str(x) + str(y) + return bestMove def has_won_ttt_reactions(self, board): """Checks if someone won, returns True and the winner if someone won, returns False and "tie" if it was a tie""" @@ -87,7 +86,7 @@ def has_won_ttt_reactions(self, board): if (board[0][2] == board[1][1] == board[2][0]) and board[0][2] != BLANK: return (True, board[0][2]) - if sum([i.count(BLANK) for i in board]) == 0: + if sum(i.count(BLANK) for i in board) == 0: return (False, "tie") return (None, "h") @@ -107,7 +106,7 @@ async def tictactoe(self, ctx: commands.Context, member: discord.Member = None): "🏳": "end", } emojis = ["↖", "⬆", "↗", "⬅", "⏺️", "➡", "↙", "⬇", "↘", "🏳"] - if member == None: + if member is None: turn = ctx.author board = [[" " for i in range(3)] for i in range(3)] await ctx.send("Choose ai difficulty, easy/hard:") diff --git a/disgames/mixins/two048.py b/disgames/mixins/two048.py index 5e4cd76..c2b837e 100644 --- a/disgames/mixins/two048.py +++ b/disgames/mixins/two048.py @@ -8,17 +8,15 @@ def __init__(self, bot): def format_2048_board(self, board): """Format the 2048 board""" - h = [] - for row in board: - h.append("".join(str(row))) + h = ["".join(str(row)) for row in board] h = "\n".join(h) return f"```\n{h}\n```" def go_up(self, board): """Move all the numbers on the board upwards""" moved = False - for x in range(0, 4): - for y in range(0, 4): + for x in range(4): + for y in range(4): if board[y][x] != 0 and y < 3: for yprime in range(y + 1, 4): if board[yprime][x] != 0: @@ -26,10 +24,8 @@ def go_up(self, board): board[y][x] = 2 * board[y][x] moved = True board[yprime][x] = 0 - break - else: - break - for y in range(0, 4): + break + for y in range(4): if board[y][x] == 0 and y < 3: for yprime in range(y + 1, 4): if board[yprime][x] != 0: @@ -42,7 +38,7 @@ def go_up(self, board): def go_down(self, board): """Move all the numbers on the board downwards""" moved = False - for x in range(0, 4): + for x in range(4): for y in range(3, -1, -1): if board[y][x] != 0 and y > 0: for yprime in range(y - 1, -1, -1): @@ -51,9 +47,7 @@ def go_down(self, board): board[y][x] = board[y][x] * 2 moved = True board[yprime][x] = 0 - break - else: - break + break for y in range(3, -1, -1): if board[y][x] == 0 and y > 0: for yprime in range(y - 1, -1, -1): @@ -67,7 +61,7 @@ def go_down(self, board): def go_right(self, board): """Move all the numbers on the board right""" moved = False - for y in range(0, 4): + for y in range(4): for x in range(3, -1, -1): if board[y][x] != 0 and x > 0: for xprime in range(x - 1, -1, -1): @@ -76,9 +70,7 @@ def go_right(self, board): board[y][x] = 2 * board[y][x] moved = True board[y][xprime] = 0 - break - else: - break + break for x in range(3, -1, -1): if board[y][x] == 0 and x > 0: for xprime in range(x - 1, -1, -1): @@ -92,8 +84,8 @@ def go_right(self, board): def go_left(self, board): """Move all the numbers on the board left""" moved = False - for y in range(0, 4): - for x in range(0, 4): + for y in range(4): + for x in range(4): if board[y][x] != 0 and x < 3: for xprime in range(x + 1, 4): if board[y][xprime] != 0: @@ -101,10 +93,8 @@ def go_left(self, board): board[y][x] = 2 * board[y][x] moved = True board[y][xprime] = 0 - break - else: - break - for x in range(0, 4): + break + for x in range(4): if board[y][x] == 0 and x < 3: for xprime in range(x + 1, 4): if board[y][xprime] != 0: @@ -122,11 +112,7 @@ def add_number(self, board): y = random.randint(0, 3) pickanumber = random.randint(0, 9) - if pickanumber < 1: - num = 4 - else: - num = 2 - + num = 4 if pickanumber < 1 else 2 if board[x][y] == 0: board[x][y] = num break @@ -140,21 +126,21 @@ def get_result(self, board): for y in range(len(board[x])): if board[x][y] == 2048: return True - for y in range(0, 4): + for y in range(4): zeroes += board[y].count(0) if zeroes > 0: break - for x in range(0, 4): + for x in range(4): if x < 3 and board[y][x + 1] == board[y][x]: playsleft = True break if y < 3 and board[y + 1][x] == board[y][x]: playsleft = True break - if playsleft == True: + if playsleft: break - if zeroes == 0 and playsleft == False: + if zeroes == 0 and not playsleft: return False def create_2048_board(self): diff --git a/disgames/utils/board.py b/disgames/utils/board.py index ced23b9..aa24335 100644 --- a/disgames/utils/board.py +++ b/disgames/utils/board.py @@ -12,9 +12,8 @@ def __init__( self.test = test def __str__(self): - lst = [] g = [f"{self.seperator}{i}" for i in range(self.x + 1)] - lst.append(g) + lst = [g] for i in range(self.x): lst.append([f"{self.seperator}{i+1}"]) for _ in range(self.y):