📜 ⬆️ ⬇️

How to win at the computer in the Military Game

Military Game with hints There is one amusing game in the list of Java Web Start demos , called Military Game (you can start the game from the browser by clicking on Military Game ).

Rules of the game:

Black starts the game, the players go alternately. A red chip can go to any adjacent cell, black - only up or to the side.
')
Black wins by blocking a red chip so that it cannot make a move. Red win either by reaching the bottom cell or after 10 passive (not up) black moves in a row.

Winning a computer with black chips was not an easy task. I found several strategies, but any deviation from them led to defeat. And then I decided to write a program that would tell me what move I can do in order not to lose. It was also interesting to find out whether it is possible to block the red chip not in the upper cell, but in the side one.

The result was the Military Game (with hints) (click to launch).

How it works:

The program calculates whether the game situation (the situation is described by the location of chips on the field and the walking side) is advantageous using the following rules of game theory:

1) the situation is advantageous for player A, if at least one move leads to a losing situation for player B;
2) the situation is losing for player A, if all moves lead to winning situations for player B.

That is, if I make a winning situation for the opponent under my own power, then I lose, and vice versa. Assessing all the game situations, we can say how to walk to win: all moves that lead to losing (for the enemy) situations will be winning (for us).

In order to visually show the winning moves, I decompiled the Military Game with an excellent jad program, added my own class and drawing green arrows to the appropriate paintComponent method. Well that's all. Enjoy!

And I remembered the whole story thanks to habrochelovek fil u and his note about the sapper .

Source: https://habr.com/ru/post/16219/


All Articles