@@ -5,41 +5,41 @@ import (
5
5
"math"
6
6
)
7
7
8
- var invalidSquareErr = errors .New ("invalid square" )
8
+ var errInvalidSquare = errors .New ("invalid square" )
9
9
10
10
// Knights can attack when seperated by 2 squares in one direction and 1 square in the other direction.
11
11
// Horizontal axis is called 'file' labelled from 'a' to 'f'
12
12
// Forward axis is called 'rank' labelled from 1 to 8
13
13
func CanKnightAttack (white , black string ) (bool , error ) {
14
14
// square must have 2 characters
15
15
if len (white ) != 2 || len (black ) != 2 {
16
- return true , invalidSquareErr
16
+ return true , errInvalidSquare
17
17
}
18
18
19
19
// cannot be on the same square
20
20
if white == black {
21
- return false , invalidSquareErr
21
+ return false , errInvalidSquare
22
22
}
23
23
24
24
// assign integer values (1 - 8) to file letters and rank digits
25
25
wFile := int (white [0 ] - 'a' + 1 )
26
26
if wFile < 1 || wFile > 8 {
27
- return false , invalidSquareErr
27
+ return false , errInvalidSquare
28
28
}
29
29
30
30
bFile := int (black [0 ] - 'a' + 1 )
31
31
if bFile < 1 || bFile > 8 {
32
- return false , invalidSquareErr
32
+ return false , errInvalidSquare
33
33
}
34
34
35
35
wRank := int (white [1 ] - '1' + 1 )
36
36
if wRank < 1 || wRank > 8 {
37
- return false , invalidSquareErr
37
+ return false , errInvalidSquare
38
38
}
39
39
40
40
bRank := int (black [1 ] - '1' + 1 )
41
41
if bRank < 1 || bRank > 8 {
42
- return false , invalidSquareErr
42
+ return false , errInvalidSquare
43
43
}
44
44
45
45
// check file and rank relative positions
0 commit comments