<commit_before>package main.java.player;

import java.rmi.RemoteException;

import main.java.automaton.Dumbest;
import main.java.automaton.PlayerAutomaton;
import main.java.automaton.Traveler;
import main.java.data.Action;
import main.java.data.Data;
import main.java.game.ExceptionFullParty;
import main.java.game.ExceptionGameHasAlreadyStarted;
import main.java.game.ExceptionUsedPlayerColor;
import main.java.game.ExceptionUsedPlayerName;
import main.java.game.GameInterface;
import main.java.rubbish.InterfaceIHM;








@SuppressWarnings("serial")
public class PlayerAI extends PlayerAbstract implements Runnable
{
// --------------------------------------------
// Attributes:
// --------------------------------------------
	private PlayerAutomaton	automaton;

// --------------------------------------------
// Builder:
// --------------------------------------------
	/**=====================================================================
	 * @return Creates a local player that can be called as a local object
	 * @throws RemoteException 			: The web host is offline	(caught by IHM)
	 * @throws ExceptionFullParty									(caught by IHM)
	 * @throws ExceptionUsedPlayerColor 							(caught by IHM)
	 * @throws ExceptionUsedPlayerName 								(caught by IHM)
	 * @throws ExceptionGameHasAlreadyStarted						(caught by IHM)
	 =======================================================================*/
	public PlayerAI(String playerName, boolean isHost, GameInterface app, int iaLevel, InterfaceIHM ihm) throws RemoteException, ExceptionFullParty, ExceptionUsedPlayerName, ExceptionUsedPlayerColor, ExceptionGameHasAlreadyStarted
	{
		super(playerName, app, ihm);
		switch (iaLevel)
		{
			case 1	:this.automaton	= new Dumbest(playerName);	break;
			case 2	:this.automaton = new Traveler(playerName);	break;
//			case 3	:this.automaton = new 3eme_niveau_de_difficulte(playerName);	break;
			default	:throw new RuntimeException("Undefined AI difficulty : " + iaLevel);
		}
		super.game.onJoinGame(this, false, isHost, iaLevel);						// Log the player to the application
	}

// --------------------------------------------
// Public methods: may be called by the remote object
// Must implement "throws RemoteException"
// --------------------------------------------
	public boolean isHumanPlayer()
	{
		return false;
	}
	public synchronized void gameHasChanged(Data data) throws RemoteException
	{
		super.gameHasChanged(data);
		if (!data.isGameStarted())			return;
		if (!data.isPlayerTurn(playerName)) return;
		if (data.getWinner() != null)		return;
		if (data.isGameBlocked())			return;

		if (data.hasRemainingAction(playerName))					// choix d'action
		{
			if(data.getHandSize(playerName)>0 || data.hasStartedMaidenTravel(playerName))
			{
				Action a = this.automaton.makeChoice(data.getClone(playerName));
	
// TODO: check action type, do others action types !!
				try
				{
					if		(a.isSimpleConstructing())		super.placeTile(a.tile1, a.positionTile1);
					else if (a.isTwoSimpleConstructing())	{super.placeTile(a.tile1, a.positionTile1); super.placeTile(a.tile2, a.positionTile2);}
else throw new RuntimeException("Not implemented yet");
					
				}
				catch (Exception e) {e.printStackTrace(); return;}
			}
			else System.out.println(playerName + " BLOCKED");
			return;
		}

		int nbrCards = data.getPlayerRemainingTilesToDraw(playerName);
		if (nbrCards > 0 && data.getNbrRemainingDeckTile() > 0)		// pioche
		{
			try
			{
				if (!data.isEnougthTileInDeck(nbrCards))
				{
					nbrCards = data.getNbrRemainingDeckTile();
				}
				super.drawTile(nbrCards);
			}
			catch (Exception e) {e.printStackTrace(); return;}
			return;
		}
		else														// fin de tour
		{
			try					{super.validate();}
			catch (Exception e) {e.printStackTrace(); return;}
		}
	}
	public synchronized void excludePlayer() throws RemoteException
	{
		if (super.ihm != null)	super.ihm.excludePlayer();
	}

// --------------------------------------------
// Local methods
// --------------------------------------------
	public void run()
	{
		
	}
}<commit_msg>pour julie<commit_after>package main.java.player;

import java.rmi.RemoteException;

import main.java.automaton.Dumbest;
import main.java.automaton.PlayerAutomaton;
import main.java.automaton.Traveler;
import main.java.data.Action;
import main.java.data.Data;
import main.java.game.ExceptionFullParty;
import main.java.game.ExceptionGameHasAlreadyStarted;
import main.java.game.ExceptionUsedPlayerColor;
import main.java.game.ExceptionUsedPlayerName;
import main.java.game.GameInterface;
import main.java.rubbish.InterfaceIHM;








@SuppressWarnings("serial")
public class PlayerAI extends PlayerAbstract implements Runnable
{
// --------------------------------------------
// Attributes:
// --------------------------------------------
	private PlayerAutomaton	automaton;

// --------------------------------------------
// Builder:
// --------------------------------------------
	/**=====================================================================
	 * @return Creates a local player that can be called as a local object
	 * @throws RemoteException 			: The web host is offline	(caught by IHM)
	 * @throws ExceptionFullParty									(caught by IHM)
	 * @throws ExceptionUsedPlayerColor 							(caught by IHM)
	 * @throws ExceptionUsedPlayerName 								(caught by IHM)
	 * @throws ExceptionGameHasAlreadyStarted						(caught by IHM)
	 =======================================================================*/
	public PlayerAI(String playerName, boolean isHost, GameInterface app, int iaLevel, InterfaceIHM ihm) throws RemoteException, ExceptionFullParty, ExceptionUsedPlayerName, ExceptionUsedPlayerColor, ExceptionGameHasAlreadyStarted
	{
		super(playerName, app, ihm);
		switch (iaLevel)
		{
			case 1	:this.automaton	= new Dumbest(playerName);	break;
			case 2	:this.automaton = new Traveler(playerName);	break;
//			case 3	:this.automaton = new 3eme_niveau_de_difficulte(playerName);	break;
			default	:throw new RuntimeException("Undefined AI difficulty : " + iaLevel);
		}
		super.game.onJoinGame(this, false, isHost, iaLevel);						// Log the player to the application
	}

// --------------------------------------------
// Public methods: may be called by the remote object
// Must implement "throws RemoteException"
// --------------------------------------------
	public boolean isHumanPlayer()
	{
		return false;
	}
	public synchronized void gameHasChanged(Data data) throws RemoteException
	{
		super.gameHasChanged(data);
		if (!data.isGameStarted())			return;
		if (!data.isPlayerTurn(playerName)) return;
		if (data.getWinner() != null)		{System.out.println("The winner is: " + data.getWinner());return;}
		if (data.isGameBlocked())			{System.out.println("The game is blocked"); return;}

		if (data.hasRemainingAction(playerName))					// choix d'action
		{
			if(data.getHandSize(playerName)>0 || data.hasStartedMaidenTravel(playerName))
			{
				Action a = this.automaton.makeChoice(data.getClone(playerName));
	
// TODO: check action type, do others action types !!
				try
				{
					if		(a.isSimpleConstructing())		super.placeTile(a.tile1, a.positionTile1);
					else if (a.isTwoSimpleConstructing())	{super.placeTile(a.tile1, a.positionTile1); super.placeTile(a.tile2, a.positionTile2);}
else throw new RuntimeException("Not implemented yet");
					
				}
				catch (Exception e) {e.printStackTrace(); return;}
			}
			else System.out.println(playerName + " BLOCKED");
			return;
		}

		int nbrCards = data.getPlayerRemainingTilesToDraw(playerName);
		if (nbrCards > 0 && data.getNbrRemainingDeckTile() > 0)		// pioche
		{
			try
			{
				if (!data.isEnougthTileInDeck(nbrCards))
				{
					nbrCards = data.getNbrRemainingDeckTile();
				}
				super.drawTile(nbrCards);
			}
			catch (Exception e) {e.printStackTrace(); return;}
			return;
		}
		else														// fin de tour
		{
			try					{super.validate();}
			catch (Exception e) {e.printStackTrace(); return;}
		}
	}
	public synchronized void excludePlayer() throws RemoteException
	{
		if (super.ihm != null)	super.ihm.excludePlayer();
	}

// --------------------------------------------
// Local methods
// --------------------------------------------
	public void run()
	{
		
	}
}
{'fraction_non_alphanumeric': 0.21989084293511219, 'fraction_numerical': 0.003153426318981201, 'mean_word_length': 2.7756410256410255, 'pattern_counts': {'":': 0, '<': 3, '<?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': '7538573', 'n_tokens_mistral': 2755, 'n_tokens_neox': 2357, 'n_words': 546}