public PacmanSimulator(PacmanState pacmanState, Pacman pacman, int refreshPeriod) {
    state = pacmanState;
    // Changement ici
    this.pv = new PacmanVisualizerWithGhosts(state.getHeight(), state.getWidth());
    this.refreshPeriod = refreshPeriod;
    this.pacman = pacman;
}

public void gameLoop(){
    while(true){
        long startTime = System.currentTimeMillis();
        Position nextPos = pacman.chooseAction(state);
        state = state.move(nextPos);
        for (Position position: state.findGhosts()){
            Position ghostMove = this.ghost.chooseAction(state, position);
            state = state.moveGhost(position, ghostMove);
        }
        this.pv.update(state);
        if (state.isFinalState()) break;
        while (this.refreshPeriod - (System.currentTimeMillis() - startTime) > 0);
    }
    if (state.isWon()) {
        System.out.println("Victory !");
        System.out.println("Score: " + state.getScore());
    } else {
        System.out.println("You lost !");
        System.out.println("Remaining food: " + state.findFoods().size());
    }
}