AI { public Move think(int color, int level) { if (game.boards.get(color).pieces.isEmpty()) { Log.d(tag, "no more pieces for player : " + color); game.boards.get(color).over = true; return null; } Log.d(tag, "--------------------------------------------------------------------------------"); level = Math.min(level, adaptedLevel); if (level>1 && color!=1 ) level--; Log.d(tag, "thinking for player : " + color + ", upto # moves : " + maxMoves[level]); List<Move> moves = thinkUpToNMoves(color, level); Log.d(tag, "# moves : " + moves.size()); if (moves.size()==0) { game.boards.get(color).over = true; return null; } Collections.sort(moves); Collections.reverse(moves); Move move = moves.get( 0); Log.d(tag, "best move actually is : " + move); if (moves.size()>20) { for (int k=moves.size()-1; k>=2; k--) { if (moves.get(k).piece.count<=2) moves.remove(k); } if (moves.size()> 10) { move = moves.get( random.nextInt(3)); } else { Log.d(tag, "keeping best move!"); } } move.piece.reset(move.ghost); return move; } AI(Game game); boolean hasMove(int color); Move think(int color, int level); boolean overlaps( int color, Piece piece, int i, int j); static final String tag; public Game game; public int adaptedLevel; }
@Test public void testThinkEmptyBoard() { pieces.add( L4); assertNotNull( ai.think(0,0)); }