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.110 tracks/python/exercises/queen-attack/example.py
trackler-2.2.1.109 tracks/python/exercises/queen-attack/example.py
trackler-2.2.1.108 tracks/python/exercises/queen-attack/example.py
trackler-2.2.1.107 tracks/python/exercises/queen-attack/example.py
trackler-2.2.1.106 tracks/python/exercises/queen-attack/example.py
trackler-2.2.1.105 tracks/python/exercises/queen-attack/example.py
trackler-2.2.1.104 tracks/python/exercises/queen-attack/example.py
trackler-2.2.1.103 tracks/python/exercises/queen-attack/example.py
trackler-2.2.1.102 tracks/python/exercises/queen-attack/example.py
trackler-2.2.1.101 tracks/python/exercises/queen-attack/example.py
trackler-2.2.1.100 tracks/python/exercises/queen-attack/example.py
trackler-2.2.1.99 tracks/python/exercises/queen-attack/example.py
trackler-2.2.1.98 tracks/python/exercises/queen-attack/example.py
trackler-2.2.1.97 tracks/python/exercises/queen-attack/example.py
trackler-2.2.1.96 tracks/python/exercises/queen-attack/example.py
trackler-2.2.1.95 tracks/python/exercises/queen-attack/example.py
trackler-2.2.1.94 tracks/python/exercises/queen-attack/example.py
trackler-2.2.1.93 tracks/python/exercises/queen-attack/example.py
trackler-2.2.1.92 tracks/python/exercises/queen-attack/example.py
trackler-2.2.1.91 tracks/python/exercises/queen-attack/example.py