<commit_before>package edu.fmi.ai.reversi;

import java.util.Collection;

import edu.fmi.ai.reversi.model.Board;
import edu.fmi.ai.reversi.model.Player;

public class GameSolver {

	/**
	 * {@value}
	 */
	private static final int MAX_LEVEL_SEARCH_DEPTH = 3;

	public GameMoveHelper getOptimalMove(final Board state) {
		final GameMoveHelper result = getOptimalMinMove(new GameSolverParameter(state,
				Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY, 0));
		result.move = result.diff(state);
		return result;
	}

	public GameMoveHelper getOptimalMinMove(final GameSolverParameter parameter) {
		if (parameter.level == MAX_LEVEL_SEARCH_DEPTH) {
			return new GameMoveHelper(parameter, Player.WHITE);
		}

		final Collection<Board> gameStates = parameter.getNextBoards(Player.WHITE);
		GameMoveHelper result = new GameMoveHelper(Float.POSITIVE_INFINITY, parameter.board);

		for (final Board nextState : gameStates) {
			final GameSolverParameter nextParameter = GameSolverParameter.increasedLevel(nextState,
					parameter);
			final GameMoveHelper optimalMove = getOptimalMaxMove(nextParameter);
			tryUpdateMinResult(parameter, result, nextState, optimalMove);

			if (parameter.beta <= parameter.alpha) {
				return result;
			}
		}

		return result;
	}

	public GameMoveHelper getOptimalMaxMove(final GameSolverParameter parameter) {
		if (parameter.level == MAX_LEVEL_SEARCH_DEPTH) {
			return new GameMoveHelper(parameter, Player.BLACK);
		}

		final Collection<Board> gameStates = parameter.getNextBoards(Player.BLACK);
		GameMoveHelper result = new GameMoveHelper(Float.NEGATIVE_INFINITY, parameter.board);

		for (final Board nextState : gameStates) {
			final GameSolverParameter nextParameter = GameSolverParameter.increasedLevel(nextState,
					parameter);

			final GameMoveHelper optimalMove = getOptimalMinMove(nextParameter);

			tryUpdateMaxResult(parameter, result, nextState, optimalMove);
			if (parameter.beta <= parameter.alpha) {
				return result;
			}
		}
		return result;
	}

	private void tryUpdateMaxResult(final GameSolverParameter parameter, GameMoveHelper result,
			final Board nextState, final GameMoveHelper next) {
		if (result.value < next.value) {
			result.value = next.value;
			result.state = nextState;
			parameter.alpha = next.value;
		}
	}

	private void tryUpdateMinResult(final GameSolverParameter parameter, GameMoveHelper result,
			final Board nextState, final GameMoveHelper next) {
		if (result.value > next.value) {
			result.value = next.value;
			result.state = nextState;
			parameter.beta = next.value;
		}
	}

}
<commit_msg>fixed an issue in the game solver<commit_after>package edu.fmi.ai.reversi;

import java.util.Collection;

import edu.fmi.ai.reversi.model.Board;
import edu.fmi.ai.reversi.model.Player;

public class GameSolver {

	/**
	 * {@value}
	 */
	private static final int MAX_LEVEL_SEARCH_DEPTH = 3;

	public GameMoveHelper getOptimalMove(final Board state) {
		final GameMoveHelper result = getOptimalMinMove(new GameSolverParameter(state,
				Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY, 0));
		result.move = result.diff(state);
		return result;
	}

	public GameMoveHelper getOptimalMinMove(final GameSolverParameter parameter) {
		if (parameter.level == MAX_LEVEL_SEARCH_DEPTH) {
			return new GameMoveHelper(parameter, Player.WHITE);
		}

		final Collection<Board> gameStates = parameter.getNextBoards(Player.WHITE);
		GameMoveHelper result = new GameMoveHelper(Float.POSITIVE_INFINITY, parameter.board);

		for (final Board nextState : gameStates) {
			final GameSolverParameter nextParameter = GameSolverParameter.increasedLevel(nextState,
					parameter);
			final GameMoveHelper optimalMove = getOptimalMaxMove(nextParameter);
			tryUpdateMinResult(parameter, result, nextState, optimalMove);

			if (parameter.beta <= parameter.alpha) {
				return result;
			}
		}

		return result;
	}

	public GameMoveHelper getOptimalMaxMove(final GameSolverParameter parameter) {
		if (parameter.level == MAX_LEVEL_SEARCH_DEPTH) {
			return new GameMoveHelper(parameter, Player.BLACK);
		}

		final Collection<Board> gameStates = parameter.getNextBoards(Player.BLACK);
		GameMoveHelper result = new GameMoveHelper(Float.NEGATIVE_INFINITY, parameter.board);

		for (final Board nextState : gameStates) {
			final GameSolverParameter nextParameter = GameSolverParameter.increasedLevel(nextState,
					parameter);

			final GameMoveHelper optimalMove = getOptimalMinMove(nextParameter);

			tryUpdateMaxResult(parameter, result, nextState, optimalMove);
			if (parameter.beta <= parameter.alpha) {
				return result;
			}
		}
		return result;
	}

	private void tryUpdateMaxResult(final GameSolverParameter parameter, GameMoveHelper result,
			final Board nextState, final GameMoveHelper next) {
		if (result.value <= next.value) {
			result.value = next.value;
			result.state = nextState;
			parameter.alpha = next.value;
		}
	}

	private void tryUpdateMinResult(final GameSolverParameter parameter, GameMoveHelper result,
			final Board nextState, final GameMoveHelper next) {
		if (result.value >= next.value) {
			result.value = next.value;
			result.state = nextState;
			parameter.beta = next.value;
		}
	}

}

{'fraction_non_alphanumeric': 0.0866641763167725, 'fraction_numerical': 0.0007471049682480389, 'mean_word_length': 4.095147478591818, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4109627', 'n_tokens_mistral': 1804, 'n_tokens_neox': 1569, 'n_words': 348}