<commit_before>package fr.utbm.vi51.model;

import java.util.ArrayList;
import java.util.List;

import fr.utbm.vi51.parser.JSONReadAndConvertingFromFile;

public class EnvironmentModel {

	private List<List<Cell>> grid;
	private int numberOfBody;
	private Cell entry;
	private Cell exit;
	private List<LemmingBody> listOfBody;
	private int deads = 0;
	private int out = 0;

	public EnvironmentModel(String level, int numberOfBody) {

		this.setGrid(level, numberOfBody);

	}
	
	public void addDead(){
		this.deads ++;
	}
	
	
	public void addOut(){
		this.out ++;
	}
	
	public int getDead(){
		return this.deads;
	}
	
	public int getOut(){
		return this.out;
	}
	

	public int getNumberOfBody() {
		return numberOfBody;
	}



	public List<List<Cell>> getGrid() {
		return grid;
	}

	public void setGrid(String level, int numberOfBody) {
		this.listOfBody = new ArrayList<LemmingBody>();
		this.numberOfBody = numberOfBody;
		JSONReadAndConvertingFromFile js = new JSONReadAndConvertingFromFile(level);
		this.grid = js.convertingContentForGame();
		if (js.getEntryPosition() != null)
			this.entry = this.grid.get((int) js.getEntryPosition().getX()).get((int) js.getEntryPosition().getY());
		if (js.getExitPosition() != null)
			this.exit = this.grid.get((int) js.getExitPosition().getX()).get((int) js.getExitPosition().getY());

		for (int i = 0; i < this.numberOfBody; i++) {
			this.listOfBody.add(new LemmingBody(i, this.entry.getX(), this.entry.getY()));
			this.entry.getListOfBodyInCell().add(listOfBody.get(i));
		}
	}

	public Cell getEntry() {
		return entry;
	}

	public Cell getExit() {
		return exit;
	}

	// SearchedBody return the position of the body in the list of a Cell
	public SearchedBody searchBody(int id) {
		int p = 0;
		int k = 0;
		while (listOfBody.get(p).getId() != id) {
			p++;
		}
		k = searchBodyInCell(listOfBody.get(p));
		return new SearchedBody(listOfBody.get(p), k);

	}
	
	public int searchBodyInCell (LemmingBody body){
		int k = 0;
		while (grid.get(body.getX()).get(body.getY()).getListOfBodyInCell().get(k).getId() != body.getId()) {
			k++;
		}
		return k;
	}
	
	public List<Percept> getPerception(int id) {
		/*
		 * Disposition of the perception --> 00 00 00 | 00 XY 00 v 00 00 00 00
		 * 00 00 00 00 00 00
		 * 
		 */
		List<Percept> allPerception = null;
		LemmingBody body = searchBody(id).getBody();
		int x = body.getX();
		int y = body.getY();

		for (int i = 0; i == body.getFovLeft(); i++) {
			for (int j = 0; j == body.getFovUp(); j++) {
				if (x - i >= 0 && y - i >= 0) {
					allPerception.add(new Percept(grid.get(x - i).get(y - j)));
				}
			}
		}
		for (int i = 0; i == body.getFovRight(); i++) {
			for (int j = 0; j == body.getFovUp(); j++) {
				if (i + j != 0 && x + i < grid.size() && y - i >= 0) {
					allPerception.add(new Percept(grid.get(x + i).get(y - j)));
				}
			}
		}

		for (int i = 0; i == body.getFovLeft(); i++) {
			for (int j = 0; j == body.getFovUnder(); j++) {
				if (i + j != 0 && i + j <= body.getFovUnder() && x - i >= 0 && y - i < grid.get(x).size()) {
					allPerception.add(new Percept(grid.get(x - i).get(x + j)));
				}
			}
		}

		for (int i = 0; i == body.getFovRight(); i++) {
			for (int j = 0; j == body.getFovUnder(); j++) {
				if (i + j != 0 && i + j <= body.getFovUnder() && x + i > grid.size() && y - i < grid.get(x).size()) {
					allPerception.add(new Percept(grid.get(x + i).get(x + j)));
				}
			}
		}
		return allPerception;
	}
<commit_msg>Change Perception<commit_after>package fr.utbm.vi51.model;

import java.util.ArrayList;
import java.util.List;

import fr.utbm.vi51.parser.JSONReadAndConvertingFromFile;

public class EnvironmentModel {

	private List<List<Cell>> grid;
	private int numberOfBody;
	private Cell entry;
	private Cell exit;
	private List<LemmingBody> listOfBody;
	private int deads = 0;
	private int out = 0;

	public EnvironmentModel(String level, int numberOfBody) {

		this.setGrid(level, numberOfBody);

	}
	
	public void addDead(){
		this.deads ++;
	}
	
	
	public void addOut(){
		this.out ++;
	}
	
	public int getDead(){
		return this.deads;
	}
	
	public int getOut(){
		return this.out;
	}
	

	public int getNumberOfBody() {
		return numberOfBody;
	}



	public List<List<Cell>> getGrid() {
		return grid;
	}

	public void setGrid(String level, int numberOfBody) {
		this.listOfBody = new ArrayList<LemmingBody>();
		this.numberOfBody = numberOfBody;
		JSONReadAndConvertingFromFile js = new JSONReadAndConvertingFromFile(level);
		this.grid = js.convertingContentForGame();
		if (js.getEntryPosition() != null)
			this.entry = this.grid.get((int) js.getEntryPosition().getX()).get((int) js.getEntryPosition().getY());
		if (js.getExitPosition() != null)
			this.exit = this.grid.get((int) js.getExitPosition().getX()).get((int) js.getExitPosition().getY());

		for (int i = 0; i < this.numberOfBody; i++) {
			this.listOfBody.add(new LemmingBody(i, this.entry.getX(), this.entry.getY()));
			this.entry.getListOfBodyInCell().add(listOfBody.get(i));
		}
	}

	public Cell getEntry() {
		return entry;
	}

	public Cell getExit() {
		return exit;
	}

	// SearchedBody return the position of the body in the list of a Cell
	public SearchedBody searchBody(int id) {
		int p = 0;
		int k = 0;
		while (listOfBody.get(p).getId() != id) {
			p++;
		}
		k = searchBodyInCell(listOfBody.get(p));
		return new SearchedBody(listOfBody.get(p), k);

	}
	
	public int searchBodyInCell (LemmingBody body){
		int k = 0;
		while (grid.get(body.getX()).get(body.getY()).getListOfBodyInCell().get(k).getId() != body.getId()) {
			k++;
		}
		return k;
	}
	
	public List<Percept> getPerception(int id) {
		/*
		 * Disposition of the perception --> 
		 * 08 02 09
		 * 01 00 03
		 * 13 04 10
		 * 14 05 12
		 * 15 06 12
		 *    07
		 */
		List<Percept> allPerception = null;
		
		LemmingBody body = searchBody(id).getBody();
		int x = body.getX();
		int y = body.getY();
		
		allPerception.add(new Percept(grid.get(x).get(y)));
		
		//left
		for (int i = 1; i == body.getFovLeft(); i++){
			if(x - i >= 0) {
				allPerception.add(new Percept(grid.get(x - i).get(y)));
			}
		}
		
		//up
		for (int j = 1; j == body.getFovUp(); j++) {
				if (y - j >= 0) {
					allPerception.add(new Percept(grid.get(x).get(y - j)));
				}
		}
		
		//right
		for (int i = 1; i == body.getFovRight(); i++){
			if(x - i <= grid.size()) {
				allPerception.add(new Percept(grid.get(x + i).get(y)));
			}
		}
		
		//down
		for (int j = 1; j == body.getFovUnder(); j++) {
			if (y + j <= grid.get(x).size()) {
				allPerception.add(new Percept(grid.get(x).get(y + j)));
			}
		}			
				
				
				
		//left up
		for (int i = 1; i == body.getFovLeft(); i++) {
			for (int j = 1; j == body.getFovUp(); j++) {
				if (x - i >= 0 && y - i >= 0) {
					allPerception.add(new Percept(grid.get(x - i).get(y - j)));
				}
			}
		}
		
		//right up
		for (int i = 1; i == body.getFovRight(); i++) {
			for (int j = 1; j == body.getFovUp(); j++) {
				if (x + i < grid.size() && y - i >= 0) {
					allPerception.add(new Percept(grid.get(x + i).get(y - j)));
				}
			}
		}

		//right down
		for (int i = 1; i == body.getFovRight(); i++) {
			for (int j = 0; j == body.getFovUnder(); j++) {
				if (i + j <= body.getFovUnder() && x + i > grid.size() && y - i < grid.get(x).size()) {
					allPerception.add(new Percept(grid.get(x + i).get(x + j)));
				}
			}
		}
		
		//left down
		for (int i = 1; i == body.getFovLeft(); i++) {
			for (int j = 1; j == body.getFovUnder(); j++) {
				if (i + j <= body.getFovUnder() && x - i >= 0 && y - i < grid.get(x).size()) {
					allPerception.add(new Percept(grid.get(x - i).get(x + j)));
				}
			}
		}

		return allPerception;
	}

{'fraction_non_alphanumeric': 0.17914543316346532, 'fraction_numerical': 0.015026786880961714, 'mean_word_length': 2.96580310880829, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, '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': '6985114', 'n_tokens_mistral': 3406, 'n_tokens_neox': 2889, 'n_words': 705}