~macaptain/lkdo-chess

ref: 0bf3bc692f7cf1486a36d984db92c580feb6634c lkdo-chess/test/attack.zig -rw-r--r-- 1.9 KiB
0bf3bc69Michael Captain Add pawn attack tables and tests 9 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
usingnamespace @import("attack.zig");

const std = @import("std");
const expectEqual = std.testing.expectEqual;

test "white pawn attacks two squares in front" {
    const side = Side.White;
    const pawn = Square.e2;
    const expected_attacked_squares = [2]Square{ Square.d3, Square.f3 };
    const expected = bitboardFromSquares(expected_attacked_squares[0..]);
    const actual = pawnAttacks(side, pawn);
    expectEqual(expected, actual);
}

test "black pawn attacks two squares in front" {
    const side = Side.Black;
    const pawn = Square.c7;
    const expected_attacked_squares = [2]Square{ Square.b6, Square.d6 };
    const expected = bitboardFromSquares(expected_attacked_squares[0..]);
    const actual = pawnAttacks(side, pawn);
    expectEqual(expected, actual);
}

test "white pawn on a file attacks only one square" {
    const side = Side.White;
    const pawn = Square.a4;
    const expected = bitboardFromSquare(Square.b5);
    const actual = pawnAttacks(side, pawn);
    expectEqual(expected, actual);
}

test "white pawn on h file attacks only one square" {
    const side = Side.White;
    const pawn = Square.h7;
    const expected = bitboardFromSquare(Square.g8);
    const actual = pawnAttacks(side, pawn);
    expectEqual(expected, actual);
}

test "black pawn on a file attacks only one square" {
    const side = Side.Black;
    const pawn = Square.a8;
    const expected = bitboardFromSquare(Square.b7);
    const actual = pawnAttacks(side, pawn);
    expectEqual(expected, actual);
}

test "white pawn on 8th rank attacks nothing" {
    const side = Side.White;
    const pawn = Square.f8;
    const expected = @as(u64, 0);
    const actual = pawnAttacks(side, pawn);
    expectEqual(expected, actual);
}

test "black pawn on 1st rank attacks nothing" {
    const side = Side.Black;
    const pawn = Square.g1;
    const expected = @as(u64, 0);
    const actual = pawnAttacks(side, pawn);
    expectEqual(expected, actual);
}