When n=2018, B has a winning strategy; when n=2019, A has a winning strategy.
First, consider an n×n board where the top and bottom of the board are connected, and the left and right are connected. Since for all 1≤a,b≤n, only one piece can be placed among {(nx+a,ny+b)∣x,y∈Z}, we can replace the coordinate plane with such a board, where the cell (a,b) of the board represents the set of points {(nx+a,ny+b)∣x,y∈Z} in the coordinate plane.
(We adopt the convention that the rows of the board are numbered from 1 to n from bottom to top, and the columns are numbered from 1 to n from left to right)
(1) First we prove that when n is even, B has a winning strategy.
Pair up all the cells of the n×n board: cell (a,2t) is paired with cell (a+2,2t+1) (here the addition and subtraction of coordinates are all taken (mod n)). If, whenever A places a piece, B places a piece at the cell paired with the cell where that piece was placed, then A's piece each time lies in a new pair, and B's piece completes that pair, so B always has a place to move, and hence B has a winning strategy.
(2) Next we prove that when n is odd, A has a winning strategy. Let n=2k+1, and define the following sets:
i) When 2∣k, let S={4r+1,4r+2∣0≤r<2k}, T={4r+3,4r+4∣0≤r<2k}
ii) When 2 does not divide k, let S={4r+2,4r+3∣0≤r<2k−1}∪{2k}, T={4r+4,4r+5∣0≤r<2k−1}∪{1}
It is not hard to see that S∪T contains exactly all the integers from 1 to 2k, and that T is the set formed by adding 2 to every number in S.
Now, pair up the cells of the n×n board: for 1≤a≤n, if a is odd, pair the cell (a,b):b∈S with the cell (a+1,b+2); if a is even, pair the cell (a,b):b∈/T with the cell (a+1,b−2). From the relationship between S and T described above, we see that all cells except (1,n) are exactly paired up one by one. Therefore A has the following strategy: first place a piece at cell (1,n), and whenever B places a piece, A places a piece at the cell paired with the cell where that piece was placed. It is not hard to see that this is a winning strategy for A. This completes the proof.