<commit_before>package edu.gmu.cs.multiagent.matrix;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import com.google.gson.stream.*;

/**
 * 
 * @author <NAME>
 * 
 */

public class Game {

	public int numActions;
	public int numStates;
	public int currentState;
	private int startState;
	private boolean gameEnded;
	private String gameName;
	private int agentOneActionNum;
	private int agentTwoActionNum;
	private ArrayList<State> stateList;
	private double[] rewards;

	public Game(String gameFile) {
		stateList = new ArrayList<State>();
		startState = 0; // default start state
		parseGame(gameFile);
		gameEnded = false;
	}

	private void parseGame(String gameFile) {
		try {
			JsonReader jsonReader = new JsonReader(new FileReader(gameFile));
			// start to read objects
			jsonReader.beginObject();
			while (jsonReader.hasNext()) {
				String name = jsonReader.nextName();
				if (name.equals("Name")) {
					gameName = jsonReader.nextString();
					System.out.println(gameName);
				}
				else if (name.equals("AgentOneAction")) {
					agentOneActionNum = jsonReader.nextInt();
				}
				else if (name.equals("AgentTwoAction")) {
					agentTwoActionNum = jsonReader.nextInt();
				}
				else if (name.equals("StartState")) {
					startState = jsonReader.nextInt();
				}
				else if (name.equals("Matrices")) {
					jsonReader.beginArray();

					// read the data of each state
					while (jsonReader.hasNext()) {
						State state = new State(jsonReader, agentOneActionNum, agentTwoActionNum);
						stateList.add(state);
					}
					jsonReader.endArray();
				}

			}

			jsonReader.endObject();
			jsonReader.close();

		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

	}


	public void play(int agentOneAction, int agentTwoAction) {
		State state = getCurrentState();
		state.play(agentOneAction, agentTwoAction);
		rewards = state.getReward();
		currentState = state.getNextState();

		if (getCurrentState().isTerminalState())
			gameEnded = true;
	}
	
	public void resetGame() {
		currentState = startState;
	}

	private State getCurrentState() {
		return stateList.get(currentState);
	}

	public double getReward(boolean firstAgent) {
		if (firstAgent)
			return rewards[0];
		else
			return rewards[1];
	}

	public boolean isGameEnd() {
		return gameEnded;
	}
}<commit_msg>minor fix<commit_after>package edu.gmu.cs.multiagent.matrix;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import com.google.gson.stream.*;

/**
 * 
 * @author <NAME>
 * 
 */

public class Game {
	public String gameName;
	public int[] numActions;
	public int numStates;
	public int currentState;
	private int startState;
	private boolean gameEnded;
	private ArrayList<State> stateList;
	private double[] rewards;
	private int agentOneLastAction;
	private int agentTwoLastAction;

	public Game(String gameFile) {
		stateList = new ArrayList<State>();
		startState = 0; // default start state
		parseGame(gameFile);
		gameEnded = false;
		numActions = new int[2];
	}

	private void parseGame(String gameFile) {
		try {
			JsonReader jsonReader = new JsonReader(new FileReader(gameFile));
			// start to read objects
			jsonReader.beginObject();
			while (jsonReader.hasNext()) {
				String name = jsonReader.nextName();
				if (name.equals("Name")) {
					gameName = jsonReader.nextString();
					System.out.println(gameName);
				}
				else if (name.equals("AgentOneAction")) {
					numActions[0] = jsonReader.nextInt();
				}
				else if (name.equals("AgentTwoAction")) {
					numActions[1] = jsonReader.nextInt();
				}
				else if (name.equals("StartState")) {
					startState = jsonReader.nextInt();
				}
				else if (name.equals("Matrices")) {
					jsonReader.beginArray();

					// read the data of each state
					while (jsonReader.hasNext()) {
						State state = new State(jsonReader, numActions[0], numActions[1]);
						stateList.add(state);
					}
					jsonReader.endArray();
				}

			}

			jsonReader.endObject();
			jsonReader.close();

		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

	}


	public void play(int agentOneAction, int agentTwoAction) {
		
		State state = getCurrentState();
		state.play(agentOneAction, agentTwoAction);
		rewards = state.getReward();
		currentState = state.getNextState();

		if (getCurrentState().isTerminalState())
			gameEnded = true;
		
		agentOneLastAction = agentOneAction;
		agentTwoLastAction = agentTwoAction;
	}
	
	public void resetGame() {
		currentState = startState;
	}

	private State getCurrentState() {
		return stateList.get(currentState);
	}

	public double getReward(boolean firstAgent) {
		if (firstAgent)
			return rewards[0];
		else
			return rewards[1];
	}

	public boolean isGameEnd() {
		return gameEnded;
	}
	
	public int getAgentOneLastAction() {
		return agentOneLastAction;
	}

	public int getAgentTwoLastAction() {
		return agentTwoLastAction;
	}
}
{'fraction_non_alphanumeric': 0.11790050920485703, 'fraction_numerical': 0.002154328241284763, 'mean_word_length': 3.763992537313433, 'pattern_counts': {'":': 0, '<': 9, '<?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': '1448310', 'n_tokens_mistral': 1867, 'n_tokens_neox': 1565, 'n_words': 370}