Test Setup Failed
Push — master ( 7bb22c...828255 )
by Ken M.
01:06
created

safe_pawns()   A

Complexity

Conditions 4

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
c 0
b 0
f 0
dl 0
loc 8
rs 9.2
1
def possible_neighbor(pawn):
2
    # find neighbors can suppor itself
3
    col, row = list(pawn)
4
    result = []
5
    if int(row) > 1:
6
        row = str(int(pawn[1]) - 1)
7
    if col < 'h':
8
        result.append(chr(ord(col) + 1) + row)
9
    if col > 'a':
10
        result.append(chr(ord(col) - 1) + row)
11
    return result
12
13
14
def safe_pawns(pawns):
15
    safe_counter = 0
16
    for i in pawns:
17
        for j in possible_neighbor(i):
18
            if j in pawns:
19
                safe_counter += 1
20
                break
21
    return safe_counter
22
23
24
if __name__ == '__main__':  # pragma: no cover
25
    # These "asserts" using only for self-checking and not necessary for
26
    # auto-testing
27
    assert safe_pawns({"b4", "d4", "f4", "c3", "e3", "g5", "d2"}) == 6
28
    assert safe_pawns({"b4", "c4", "d4", "e4", "f4", "g4", "e5"}) == 1
29