<commit_before>/**
 * 
 */

package theviolator;

import connect4.MiniMaxConnect4Player;
import breakthrough.*;
import game.*;

public class TheViolatorMiniMaxPlayer extends game.GamePlayer {
	protected final int MAX_DEPTH = 50;
	protected final int MAX_SCORE = 12 * BreakthroughState.N
			* BreakthroughState.N + 1;
	protected int depthLimit;
	protected ScoredBreakthroughMove[] stack;

	public TheViolatorMiniMaxPlayer(String nickname, int depthLimit) {
		super(nickname, new BreakthroughState(), false);
		this.depthLimit = depthLimit;
		// TODO Auto-generated constructor stub
	}

	/**
	 * 
	 * @author <NAME>, <NAME>, <NAME>
	 * 
	 */
	protected class ScoredBreakthroughMove extends
			breakthrough.BreakthroughMove {
		protected double score;

		protected ScoredBreakthroughMove(int r1, int c1, int r2,
				int c2, double s) {
			super(r1, c1, r2, c2);
			score = s;
		}

		protected void setScore(int r1, int c1, int r2, int c2,
				double s) {
			startRow = r1;
			startCol = c1;
			endingRow = r2;
			endingCol = c2;
			score = s;
		}
	}

	protected static void shuffle(int[] cols) {
		for (int i = 0; i < cols.length; i++) {
			int val1 = Util.randInt(0, cols.length);
			int swap = cols[i];
			cols[i] = cols[val1];
			cols[val1] = swap;
		}
	}

	public void init() {
		stack = new ScoredBreakthroughMove[MAX_DEPTH];
		for (ScoredBreakthroughMove m : stack)
			m = new ScoredBreakthroughMove(0, 0, 0, 0, 0);
	}

	protected boolean terminalValue(GameState state,
			ScoredBreakthroughMove mv) {
		GameState.Status status = state.getStatus();
		boolean isTerminal = true;

		if (status == GameState.Status.HOME_WIN) {
			mv.setScore(0, 0, 0, 0, MAX_SCORE);
		} else if (status == GameState.Status.AWAY_WIN) {
			mv.setScore(0, 0, 0, 0, -MAX_SCORE);
		} else if (status == GameState.Status.DRAW) {
			mv.setScore(0, 0, 0, 0, 0);
		} else {
			isTerminal = false;
		}
		return isTerminal;
	}

	protected static int evalBoard(BreakthroughState state) {
		return 0;
	}

	private void minimax(BreakthroughState brd, int currDepth) {
		boolean toMaximize = (brd.getWho() == GameState.Who.HOME);
		boolean isTerminal = terminalValue(brd, stack[currDepth]);
		
		if (isTerminal) {
			;
		} else if (currDepth == depthLimit) {
			stack[currDepth].setScore(0, 0, 0, 0, evalBoard(brd));
		} else {
			ScoredBreakthroughMove curr = new ScoredBreakthroughMove(
					0, 0, 0, 0, 0);
			double bestScore = (toMaximize ? Double.NEGATIVE_INFINITY
					: Double.POSITIVE_INFINITY);
			ScoredBreakthroughMove bestMove = stack[currDepth];
			ScoredBreakthroughMove nextMove = stack[currDepth + 1];
			bestMove.setScore(0, 0, 0, 0, bestScore);
			GameState.Who currTurn = brd.getWho();
			
			int[] cols = new int[BreakthroughState.N];
			int[] rows = new int[BreakthroughState.N];<commit_msg>implement evalBoard method in TheViolatorMiniMaxPlayer.java<commit_after>/**
 * 
 */

package theviolator;

import breakthrough.*;
import game.*;

public class TheViolatorMiniMaxPlayer extends GamePlayer {
	protected final int MAX_DEPTH = 50;
	protected final static int MAX_SCORE = 12 * BreakthroughState.N
			* BreakthroughState.N + 1;
	protected int depthLimit;
	protected ScoredBreakthroughMove[] stack;

	public TheViolatorMiniMaxPlayer(String nickname, int depthLimit) {
		super(nickname, new BreakthroughState(), false);
		this.depthLimit = depthLimit;
		// TODO Auto-generated constructor stub
	}

	/**
	 * 
	 * @author <NAME>, <NAME>, <NAME>
	 * 
	 */
	protected class ScoredBreakthroughMove extends
			breakthrough.BreakthroughMove {
		protected double score;

		protected ScoredBreakthroughMove(int r1, int c1, int r2,
				int c2, double s) {
			super(r1, c1, r2, c2);
			score = s;
		}

		protected void setScore(int r1, int c1, int r2, int c2,
				double s) {
			startRow = r1;
			startCol = c1;
			endingRow = r2;
			endingCol = c2;
			score = s;
		}
	}

	protected static void shuffle(int[] cols) {
		for (int i = 0; i < cols.length; i++) {
			int val1 = Util.randInt(0, cols.length);
			int swap = cols[i];
			cols[i] = cols[val1];
			cols[val1] = swap;
		}
	}

	public void init() {
		stack = new ScoredBreakthroughMove[MAX_DEPTH];
		for (ScoredBreakthroughMove m : stack)
			m = new ScoredBreakthroughMove(0, 0, 0, 0, 0);
	}

	protected boolean terminalValue(GameState state,
			ScoredBreakthroughMove mv) {
		GameState.Status status = state.getStatus();
		boolean isTerminal = true;

		if (status == GameState.Status.HOME_WIN) {
			mv.setScore(0, 0, 0, 0, MAX_SCORE);
		} else if (status == GameState.Status.AWAY_WIN) {
			mv.setScore(0, 0, 0, 0, -MAX_SCORE);
		} else if (status == GameState.Status.DRAW) {
			mv.setScore(0, 0, 0, 0, 0);
		} else {
			isTerminal = false;
		}
		return isTerminal;
	}

	protected static int evalBoard(BreakthroughState state) {
		int score = 0;
		for (int r = 0; r < BreakthroughState.N; r++) {
			for (int c = 0; c < BreakthroughState.N; c++) {
				if (state.board[r][c] == BreakthroughState.homeSym) {
					score += (r+1);
				} else if (state.board[r][c] == BreakthroughState.awaySym) {
					score -= (BreakthroughState.N-r);
				}
			}
		}
		
		if (Math.abs(score) > MAX_SCORE) {
			System.err.println("Problem with eval");
			System.exit(0);
		}
		return score;
	}

	private void minimax(BreakthroughState brd, int currDepth) {
		boolean toMaximize = (brd.getWho() == GameState.Who.HOME);
		boolean isTerminal = terminalValue(brd, stack[currDepth]);
		
		if (isTerminal) {
			;
		} else if (currDepth == depthLimit) {
			stack[currDepth].setScore(0, 0, 0, 0, evalBoard(brd));
		} else {
			ScoredBreakthroughMove curr = new ScoredBreakthroughMove(
					0, 0, 0, 0, 0);
			double bestScore = (toMaximize ? Double.NEGATIVE_INFINITY
					: Double.POSITIVE_INFINITY);
			ScoredBreakthroughMove bestMove = stack[currDepth];
			ScoredBreakthroughMove nextMove = stack[currDepth + 1];
			bestMove.setScore(0, 0, 0, 0, bestScore);
			GameState.Who currTurn = brd.getWho();
			
			int[] cols = new int[BreakthroughState.N];
			int[] rows = new int[BreakthroughState.N];
{'fraction_non_alphanumeric': 0.12437479159719907, 'fraction_numerical': 0.020673557852617538, 'mean_word_length': 3.6721183800623054, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 10, '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': '943353', 'n_tokens_mistral': 2466, 'n_tokens_neox': 2112, 'n_words': 541}