@@ -24,6 +24,8 @@ public class Computer {
2424 private Set <Coordinates > possibleMoves = new HashSet <>();
2525 private Set <Coordinates > possibleKickAndNotIsEnemyKickMe = new HashSet <>();
2626
27+ private BoardPoint boardPoint = new BoardPoint ();
28+
2729 public Computer () {
2830 if (isExists ()) {
2931 load ();
@@ -99,6 +101,7 @@ public void getGameData() {
99101 public Coordinates choosePawn () {
100102 switch (skill ) {
101103 case 1 : return choosePawnEasy ();
104+ case 2 : return choosePawnHard ();
102105 default : return choosePawnNormal ();
103106 }
104107 }
@@ -128,6 +131,59 @@ private Coordinates choosePawnNormal() {
128131 return (Coordinates ) object [random .nextInt (object .length )];
129132 }
130133
134+ private Coordinates choosePawnHard () {
135+ int minNumber = -1000 ;
136+
137+ Set <Coordinates > cachePawn = new HashSet <>();
138+ cachePawn .addAll (possibleKick );
139+ cachePawn .addAll (possibleMoves );
140+
141+ Set <Coordinates > cachePossiblePawn = new HashSet <>();
142+
143+ for (Coordinates coordinates : cachePawn ) {
144+
145+ PawnMoves moves = new PawnMoves (Board .getPawn (coordinates ), coordinates );
146+
147+ Set <Coordinates > cacheMoves = new HashSet <>();
148+ cacheMoves .addAll (moves .getPossibleKick ());
149+ cacheMoves .addAll (moves .getPossibleMoves ());
150+
151+ for (Coordinates moveCoordinates : cacheMoves ) {
152+ PawnClass oldPawn = Board .addPawnWithoutDesign (moveCoordinates , Board .getPawn (coordinates ));
153+
154+ int point = boardPoint .calculateBoard ();
155+
156+ if (point > minNumber ) {
157+ minNumber = point ;
158+ }
159+
160+ Board .removePawnWithoutDesign (moveCoordinates );
161+
162+ if (oldPawn != null ) {
163+ Board .addPawnWithoutDesign (moveCoordinates , oldPawn );
164+ }
165+ }
166+
167+ for (Coordinates moveCoordinates : cacheMoves ) {
168+ PawnClass oldPawn = Board .addPawnWithoutDesign (moveCoordinates , Board .getPawn (coordinates ));
169+
170+ int point = boardPoint .calculateBoard ();
171+
172+ if (point == minNumber ) {
173+ cachePossiblePawn .add (coordinates );
174+ }
175+
176+ Board .removePawnWithoutDesign (moveCoordinates );
177+
178+ if (oldPawn != null ) {
179+ Board .addPawnWithoutDesign (moveCoordinates , oldPawn );
180+ }
181+ }
182+ }
183+
184+ return (Coordinates ) cachePossiblePawn .toArray ()[random .nextInt (cachePossiblePawn .size ())];
185+ }
186+
131187 public Coordinates chooseMove (Coordinates coordinates ) {
132188 switch (skill ) {
133189 case 1 : return chooseMoveEasy (coordinates );
0 commit comments