Sha256: c90a3f06b50739f14478dd3809f54a9224ef370d63b13f4fe25756bb2a079c49

Contents?: true

Size: 777 Bytes

Versions: 328

Compression:

Stored size: 777 Bytes

Contents

def board(pos1, pos2):
    validate_position(pos1, pos2)
    x1, y1 = pos1
    x2, y2 = pos2
    b = [['_'] * 8 for i in range(8)]
    b[x1][y1] = 'W'
    b[x2][y2] = 'B'
    return [''.join(r) for r in b]


def can_attack(pos1, pos2):
    validate_position(pos1, pos2)
    x1, y1 = pos1
    x2, y2 = pos2
    dx = x1 - x2 if x1 >= x2 else x2 - x1
    dy = y1 - y2 if y1 >= y2 else y2 - y1
    if dx == dy or dx == 0 or dy == 0:
        return True
    return False


def validate_position(pos1, pos2):
    if any(x < 0 or x > 7 for x in pos1 + pos2):
        raise ValueError('Invalid queen position: queen out of the board')
    if pos1 == pos2:
        raise ValueError('Invalid queen position: both queens in the same '
                         'square: {0}'.format(pos1))

Version data entries

328 entries across 328 versions & 1 rubygems

Version Path
trackler-2.2.1.30 tracks/python/exercises/queen-attack/example.py
trackler-2.2.1.29 tracks/python/exercises/queen-attack/example.py
trackler-2.2.1.28 tracks/python/exercises/queen-attack/example.py
trackler-2.2.1.27 tracks/python/exercises/queen-attack/example.py
trackler-2.2.1.26 tracks/python/exercises/queen-attack/example.py
trackler-2.2.1.25 tracks/python/exercises/queen-attack/example.py
trackler-2.2.1.24 tracks/python/exercises/queen-attack/example.py
trackler-2.2.1.23 tracks/python/exercises/queen-attack/example.py
trackler-2.2.1.22 tracks/python/exercises/queen-attack/example.py
trackler-2.2.1.21 tracks/python/exercises/queen-attack/example.py
trackler-2.2.1.20 tracks/python/exercises/queen-attack/example.py
trackler-2.2.1.19 tracks/python/exercises/queen-attack/example.py
trackler-2.2.1.18 tracks/python/exercises/queen-attack/example.py
trackler-2.2.1.17 tracks/python/exercises/queen-attack/example.py
trackler-2.2.1.16 tracks/python/exercises/queen-attack/example.py
trackler-2.2.1.15 tracks/python/exercises/queen-attack/example.py
trackler-2.2.1.14 tracks/python/exercises/queen-attack/example.py
trackler-2.2.1.13 tracks/python/exercises/queen-attack/example.py
trackler-2.2.1.12 tracks/python/exercises/queen-attack/example.py
trackler-2.2.1.11 tracks/python/exercises/queen-attack/example.py