예제 #1
0
def play(A, m, n):
    while generateRandom(A, m, n):
        helper.printGrid(A, m, n)
        move = input()
        while not gameplay.playsucessfulmove(A, m, n, move):
            helper.printGrid(A, m, n)
            move = input()
예제 #2
0
def calculateVisibleSeats(seating):
    newSeats = deepcopy(seating)

    seats = []
    for y in range(1, len(seating) - 1):
        for x in range(1, len(seating[y]) - 1):
            ny, nx = y, x
            neighbours = []
            for c in [(-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, -1),
                      (1, 0), (1, 1)]:
                ny, nx = y, x
                ny += c[0]
                nx += c[1]

                while (0 < ny < len(seating)) and (0 < nx < len(seating[0])):
                    try:
                        if seating[ny][nx] in ['L', '#']:
                            neighbours += seating[ny][nx]
                            break
                    except IndexError:
                        print('WAT', (y, x))
                        printGrid(s, False)
                        raise
                    ny += c[0]
                    nx += c[1]
                else:
                    neighbours.append('.')

            if seating[y][x] == 'L' and emptyNeighbours(neighbours):
                newSeats[y][x] = '#'
            elif seating[y][x] == '#' and busyNeighbours(neighbours, 5):
                newSeats[y][x] = 'L'

    return newSeats
예제 #3
0
파일: 03.py 프로젝트: JohannDickson/aoc2020
def part1(treeGrid, slope_x, slope_y, display=False):
    myGrid = deepcopy(treeGrid)
    posX = 0
    posY = 0
    treeCounter = 0

    grid_width = len(treeGrid[0])
    grid_height = len(treeGrid)

    printGrid(treeGrid, display)

    while posY < grid_height:

        while posX >= len(myGrid[posY]):
            myGrid[posY].extend(treeGrid[posY])

        if myGrid[posY][posX] == '#':
            treeCounter += 1
            myGrid[posY][posX] = 'X'
        else:
            myGrid[posY][posX] = 'O'

        posY += slope_y
        posX += slope_x

        printGrid(myGrid, display)

    return treeCounter
예제 #4
0
def part1(seating, display=False):
    oldSeats = ''
    iterations = 0

    seating = addPadding(seating)

    while printGrid(seating, False) != oldSeats:
        oldSeats = printGrid(seating, False)
        seating = calculateSeats(seating)
        iterations += 1
        printGrid(seating, display)

    return printGrid(seating, False).count('#')