dketov
3/21/2017 - 12:18 PM

checkship.py

ship = 'd3d9'
badship = 'd3e7'

def check(ship):
    x1, y1, x2, y2 = map(lambda (x,y): y(x), zip(ship, (ord,int,ord,int)))

    return (
            check_diagonal(x1, y1, x2, y2)
        and check_border(x1, y1)
        and check_border(x2, y2)
    )

def check_border(x, y):
    if ord('a') <= x <= ord('h') and 0 <= y <= 9:
        return True
    return False

def check_diagonal(x1, y1, x2, y2):
   
    if x1 - x2 and y1 - y2:
        print 'No diagonal placing allowed'
        return False

    return True

print check(ship)
print check(badship)