black and white grid Some squares of a $n \times n$ table ($n>2$) are black, the rest are white. In every white square, we write the number of the black squares having at least one vertex with it. Find the max possible sum of these numbers.
What I did until now was just trying for small n and did not catch anything generalizable.
 A: The asymmetric formulation somewhat conceals the symmetry of the problem. We're counting pairs of white and black squares that share at least one vertex.
Consider each internal vertex and the set of four squares adjacent to it. Two of them that share an edge are also together in the square set of another vertex, whereas those that are diagonally opposed are only together in the square set of this vertex. Thus, award half a point to the vertex for each pair of opposite-coloured squares that share an edge, and one point for each pair of opposite-coloured squares that are diagonally opposed. Then summing over all vertices will reproduce the desired score (if we treat the margins properly).
There are only four inequivalent configurations for the square set of a vertex:


*

*All squares are the same colour: score $0$.

*One square is a different colour than the other three: score $2$.

*Two squares of each colour are diagonally opposed: score $2$.

*Two squares of each colour share an edge: score $3$.


Thus, we should expect the optimal configuration to ideally have score $3$ at all internal vertices, with two squares of each colour sharing an edge. This is realized by alternating monochromatic rows or columns.
To turn this into a rigorous proof, you'll have to deal with the margins, but the fact that we can maximize the score in the bulk strongly suggests that the alternating row or column pattern should be optimal, at least for large $n$ where the bulk dominates the margins.
The total count from this solution is
$$
\frac{8+(3+3+4+4)(n-2)+6(n-2)^2}2=3n^2-5n+2\;.
$$
This is OEIS sequence A049451 with an offset of $1$. The entry states that this is “With offset 1: the maximum possible sum of numbers in an $N\times N$ standard Minesweeper grid”, which is precisely your problem. Unfortunately, no reference to a proof is given.
A: An elementary proof
Consider adding an extra row and column to an $(n-1)\times(n-1)$ board. The total count will be increased by an amount equal to the number of extra pairs of opposite coloured squares which have a vertex in common.
The bold edges shown on the image represent all these possible pairs in the case $n=4$. The edges have been grouped into arrowheads of four edges and one group of $6$ edges.
The possible extra pairs 
In general there will be $2n-4$ arrowheads. Three of the edges of each arrowhead form a triangle and therefore all three cannot link oppositely coloured squares. Therefore each arrowhead contributes at most $3$ to the extra count. Similarly the group of $6$ edges contributes at most $4$.
An upper bound on the additional score is therefore $$3(2n-4)+4=6n-8$$
For a $1\times 1$ board the score is  $0$ and so an upper bound for the $n\times n$ board is $$\sum_{i=2}^n (6i-8)=3n^2-5n+2.$$
This completes the proof since this score is attained by a striped board.
A: A general proof
Consider an inductive step of adding an extra row and column to an $(n-1)\times(n-1)$ board, for $n\ge 2$. 
The image shows the three types of vertices we need to deal with, shown in the case $n=4$.
The vertices
In general, there will be two vertices of type A, one of type B and $2(n-2)$ of type C.
We shall award points to these vertices by the following method which is designed so that the sum of these points will be precisely the extra score created by adding the row and column.
Type A  The score will be $0$ or $0.5$ depending upon whether the adjacent squares have the same colour or not. 
Type B and Type C  Award points to pairs of oppositely coloured squares as follows:
1 point if they are diagonally opposite;
1 point if they are both on an outside edge;
0.5 points if they share an edge and only one of the squares is on an outside edge.
Thus a maximum of $3.5$ points can be awarded to the type B vertex and a maximum of $3$ points to a type C vertex.
An upper bound on the additional score is therefore the integer part of $$2\times0.5+3.5+3\times2(n-2)=6n-7.5$$
i.e $6n-8$.
For a $1\times 1$ board the score is  $0$ and so an upper bound for the $n\times n$ board is $$\sum_{i=2}^n (6i-8)=3n^2-5n+2.$$
This completes the proof since this score is attained by a striped board.
N.B The scores awarded to  points differ from those used by Joriki because we are not counting points already awarded in the $(n-1)\times(n-1)$ board and, for type C, some adjacencies are not counted by any other vertex.
