<commit_before>#! /usr/bin/python3
# author: <NAME>
# apache 2.0
# minesweeper game

import random

class Cell(object):
    """Is a single cell of the minesweeper board"""
    def __init__(self, mine=False, revealed=False, tag=False, tile=0):
        self.mine = mine # Whether or not there is a mine
        self.revealed = revealed # Whether or not the player can see the tile
        self.tag = tag # Whether or not the player marked the tile
        self.tile = tile # The character used to represent the tile

    def show(self):
        self.revealed = True

    def flag(self):
        """toggles flags on a tile"""
        self.tag = not self.tag

    def get_tile(self):
        return self.tile

    def set_tile(self, mine=False, tile=0):
        self.tile = tile
        self.mine = mine

    def increment_tile(self):
        if self.tile != "X":
            self.tile += 1

class Board(list):
    """This Board object contains Cell objects within itself to represent the minesweeper game board"""
    def __init__(self, x_length=10, y_length=10, mine_count=0, revealed_tiles=0):
        self.x_length = x_length # Length of board's x-axis
        self.y_length = y_length # Length of board's y-axis
        self.mine_count = mine_count # Amount of mines on the board
        self.revealed_tiles = revealed_tiles
        for y in range(self.y_length):
            self.append([])
            for x in range(self.x_length):
                self[y].append(Cell())

    def print_brd(self):
        """ Loops through entire array and prints each Cell objects tile variable, if its revealed. Otherwise uses "#" """
        count = self.y_length - 1
        for y in range(self.y_length):
            print (str(count) + " - " , end="")
            for x in range(self.x_length):
                current_cell = self[count][x]
                if current_cell.revealed == True:
                    print (str(current_cell.get_tile()) + " ", end="")
                else:
                    print ("# ", end="")
            count -= 1
            print("")
        count = 0
        print("    ", end="")
        print("| " * self.x_length)
        print("    ", end="")
        for i in range(self.x_length):
            print(str(count) + " ", end="")
            count += 1
        print("")

    def plant_mines(self):
        """Plants exactly the amount of mines according to algorithm"""
        count = self.y_length * self.x_length / ((self.y_length + self.x_length) / 2)
        while count > 0:
            y = random.randint(0, self.y_length -1)
            x = random.randint(0, self.x_length -1)
            cur_cell = self[y][x]
            if cur_cell.get_tile() == "X" or cur_cell.revealed:
                continue
            else:
                cur_cell.set_tile(True, "X")
                self.mine_count += 1
                count -= 1

    def count_surrounding(self):
        """Uses a coordinate list to check surrounding tiles of mines and increments them if there is no mine"""
        coordinates = [[-1, -1], [-1, 0], [-1, 1],
                       [0 , -1],          [0 , 1],
                       [1 , -1], [1 , 0], [1 , 1]]
        for y in range(self.y_length):
            for x in range(self.x_length):
                if self[y][x].get_tile() == "X":
                    for i in range(len(coordinates)):
                        y_offset = y+coordinates[i][0]
                        x_offset = x+coordinates[i][1]
                        if y_offset < 0 or y_offset >= self.y_length or x_offset >= self.x_length or x_offset < 0:
                            continue
                        self[y_offset][x_offset].increment_tile()

    def cell_flip(self, y, x):
        """Reveals the tile according to x,y coordinates. If a mine returns True."""
        y = int(y)
        x = int(x)
        self[y][x].show()
        if self[y][x].get_tile() == "X":
            self.revealed_tiles += 1
            return True
        else:
            self.revealed_tiles += 1
            return False

    def get_cell(self, y=0, x=0):
        return self[y][x]

def main():
    mine_brd = Board()
    mine_brd.print_brd()
    coords = get_coords()
    mine_brd.cell_flip(coords[0], coords[1])
    mine_brd.plant_mines()
    mine_brd.count_surrounding()
    game_over = False
    win = False
    while game_over == False:
        mine_brd.print_brd()
        coords = get_coords()
        game_over =  mine_brd.cell_flip(coords[0], coords[1])
        # If the amount of revealed tiles is the amount of tiles - amount of mines
        if mine_brd.y_length * mine_brd.x_length - mine_brd.mine_count == mine_brd.revealed_tiles:
            game_over = True
            win = True
    mine_brd.print_brd()
    if win == True:
        print ("You win!")
    else:
        print ("You lose...")

def get_coords():
    print("Please enter x-coordinate")
    x = input()
    print("Please enter y-coordinate")
    y = input()
    coords = [y,x]
    return coords

if __name__ == "__main__":
    main()
<commit_msg>changed the print_brd() function to return a concatanated string rather than issue print statements<commit_after>#! /usr/bin/python3
# author: <NAME>
# apache 2.0
# minesweeper game

import random

class Cell(object):
    """Is a single cell of the minesweeper board"""
    def __init__(self, mine=False, revealed=False, tag=False, tile=0):
        self.mine = mine # Whether or not there is a mine
        self.revealed = revealed # Whether or not the player can see the tile
        self.tag = tag # Whether or not the player marked the tile
        self.tile = tile # The character used to represent the tile

    def show(self):
        self.revealed = True

    def flag(self):
        """toggles flags on a tile"""
        self.tag = not self.tag

    def get_tile(self):
        return self.tile

    def set_tile(self, mine=False, tile=0):
        self.tile = tile
        self.mine = mine

    def increment_tile(self):
        if self.tile != "X":
            self.tile += 1

class Board(list):
    """This Board object contains Cell objects within itself to represent the minesweeper game board"""
    def __init__(self, x_length=10, y_length=10, mine_count=0, revealed_tiles=0):
        self.x_length = x_length # Length of board's x-axis
        self.y_length = y_length # Length of board's y-axis
        self.mine_count = mine_count # Amount of mines on the board
        self.revealed_tiles = revealed_tiles
        for y in range(self.y_length):
            self.append([])
            for x in range(self.x_length):
                self[y].append(Cell())

    def print_brd(self):
        """Concatenates the board to a string, the returns the value."""
        brdstr = ""
        count = self.y_length - 1
        for y in range(self.y_length):
            brdstr += str(count) + " - "
            for x in range(self.x_length):
                current_cell = self[count][x]
                if current_cell.revealed == True:
                    brdstr += str(current_cell.get_tile()) + " "
                else:
                    brdstr += "# "
            count -= 1
            brdstr += "\n"
        count = 0
        brdstr += "    "
        brdstr += "| " * self.x_length + "\n"
        brdstr += "    "
        for i in range(self.x_length):
            brdstr += str(count) + " "
            count += 1
        brdstr += "\n"
        return brdstr

    def plant_mines(self):
        """Plants exactly the amount of mines according to algorithm"""
        count = self.y_length * self.x_length / ((self.y_length + self.x_length) / 2)
        while count > 0:
            y = random.randint(0, self.y_length -1)
            x = random.randint(0, self.x_length -1)
            cur_cell = self[y][x]
            if cur_cell.get_tile() == "X" or cur_cell.revealed:
                continue
            else:
                cur_cell.set_tile(True, "X")
                self.mine_count += 1
                count -= 1

    def count_surrounding(self):
        """Uses a coordinate list to check surrounding tiles of mines and increments them if there is no mine"""
        coordinates = [[-1, -1], [-1, 0], [-1, 1],
                       [0 , -1],          [0 , 1],
                       [1 , -1], [1 , 0], [1 , 1]]
        for y in range(self.y_length):
            for x in range(self.x_length):
                if self[y][x].get_tile() == "X":
                    for i in range(len(coordinates)):
                        y_offset = y+coordinates[i][0]
                        x_offset = x+coordinates[i][1]
                        if y_offset < 0 or y_offset >= self.y_length or x_offset >= self.x_length or x_offset < 0:
                            continue
                        self[y_offset][x_offset].increment_tile()

    def cell_flip(self, y, x):
        """Reveals the tile according to x,y coordinates. If a mine returns True."""
        y = int(y)
        x = int(x)
        self[y][x].show()
        if self[y][x].get_tile() == "X":
            self.revealed_tiles += 1
            return True
        else:
            self.revealed_tiles += 1
            return False

    def get_cell(self, y=0, x=0):
        return self[y][x]

def main():
    mine_brd = Board()
    print(mine_brd.print_brd())
    coords = get_coords()
    mine_brd.cell_flip(coords[0], coords[1])
    mine_brd.plant_mines()
    mine_brd.count_surrounding()
    game_over = False
    win = False
    while game_over == False:
        print(mine_brd.print_brd())
        coords = get_coords()
        game_over =  mine_brd.cell_flip(coords[0], coords[1])
        # If the amount of revealed tiles is the amount of tiles - amount of mines
        if mine_brd.y_length * mine_brd.x_length - mine_brd.mine_count == mine_brd.revealed_tiles:
            game_over = True
            win = True
    print_brd(mine_brd.print_brd())
    if win == True:
        print ("You win!")
    else:
        print ("You lose...")

def get_coords():
    print("Please enter x-coordinate")
    x = input()
    print("Please enter y-coordinate")
    y = input()
    coords = [y,x]
    return coords

if __name__ == "__main__":
    main()

{'fraction_non_alphanumeric': 0.11656019656019656, 'fraction_numerical': 0.010221130221130222, 'mean_word_length': 1.8196176226101413, 'pattern_counts': {'":': 8, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1719109', 'n_tokens_mistral': 3246, 'n_tokens_neox': 3117, 'n_words': 898}