All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.fathzer.games.ai.time.BasicTimeManager Maven / Gradle / Ivy

The newest version!
package com.fathzer.games.ai.time;

import com.fathzer.games.clock.CountDownState;

/** A TimeManager that uses a {@link RemainingMoveCountPredictor} to estimate the number of moves to finish the game
 *  and distributes the available time equally between all future moves.
 * @param  The type of the data required by the predictor.
 */
public class BasicTimeManager implements TimeManager {
	private final RemainingMoveCountPredictor oracle;
	
	/** Constructor
	 * @param oracle The oracle to use to predict the number of moves to go
	 */
	public BasicTimeManager(RemainingMoveCountPredictor oracle) {
		this.oracle = oracle;
	}

	@Override
	public long getMaxTime(B data, CountDownState countDown) {
		int movesToGo = countDown.getMovesToGo();
		if (movesToGo==0) {
			// Evaluate number of remaining moves
			movesToGo = oracle.getRemainingHalfMoves(data);
			// Convert half moves count to moves count
			movesToGo = (movesToGo+1)/2;
		}
		long remainingMs = countDown.getRemainingMs() + countDown.getIncrementMs()*(movesToGo-1);
		return remainingMs/movesToGo;
	}

}