I am trying to find out if there are any 'optimal' moves in the game, so as to trap my enemy to put his pawns in the place where I need them
Puzzling Stack Exchange is a question and answer site for those who create, solve, and study puzzles. It only takes a minute to sign up.Sign up to join this community
forcing only happens when you can either make a 4 in a row next turn (forcing him to put his piece there to remain in the game) or
a 2 in a row with 2 spots one way and 1 spot the other:
2 1 B B 2
you could place a piece in
1 while the
2s are free then you have a guaranteed win, he needs to place in any of the free spots to be able to block you
In addition to @ratchetfreak's answer, it is possible to indirectly force a move in another way: when you can place a piece on your next turn such that there are multiple slots on which you can win (branching). This is a generalization of the "two free slots" case presented in his answer.
x oxx oxox
If x moves on row 2 (counting from the left), he is guaranteed a win on the subsequent turn; therefore, o must place a piece to block this branching first.
A more complex example of this could be multi-stage branching, which could look something like this:
o is forced to move in one of rows 1-5 in order to avoid losing; try playing it out to see why. (Needless to say, this would be very rare in a real game, but it's theoretically possible.)
In addition to the answers above, another key concept for Connect-4 is the notion of Zugzwang: having to make a move that one doesn't want to. Often parity is a way to force this; eventually a player is forced to play in a column that they don't want to. A very simple example of this concept is the following structure:
x xo oo __xx
Suppose it's X's turn to move here (the underscores represent an empty column). Then X can force a win by playing on the left hand side:
x xo oo x_xx
Now, o has to move into the second column to block the four-across - but doing so lets x win on the diagonal instead, by playing above o's piece. This particular configuration is obviously highly contrived - but 'locking' columns so that it's suicidal for one player to play there is often easier than it might seen; once that's done, it becomes a question of leaving that player with no other good moves.