<commit_before>package utils;

import gui.BattlefieldMap;
import gui.Field;
import java.awt.Color;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.List;
import model.Ship;

public class MapSaverAndLoader {

    private BattlefieldMap map;

    public MapSaverAndLoader(BattlefieldMap map) {
        this.map = map;
    }

    public void saveMap(ObjectOutputStream os) throws IOException {
        os.writeObject(map.getSavedStateOfMap());
        os.writeObject(map.getListOfShips());

        for (Field[] gridField : map.getGridFields()) { // TODO: try whole array(make serial. first)
            for (Field field : gridField) {
                os.writeObject(field.isWithShip());
                os.writeObject(field.isHit());
            }
        }
    }

    public void loadMap(ObjectInputStream ois) throws IOException {
        try {
            map.setSavedStateOfMap((boolean[][]) ois.readObject());
            @SuppressWarnings("unchecked")
            List<Ship> list = (List<Ship>) ois.readObject();
            map.setListOfShips(list);

            repaintMap();

            for (Field[] gridField : map.getGridFields()) {
                for (Field field : gridField) {
                    field.setContainsShip((Boolean) ois.readObject());
                    field.setIsHit((Boolean) ois.readObject());
                    if (field.isHit() && !field.isWithShip()) {
                        field.setBackground(Color.GRAY);
                    } else if (field.isHit() && field.isWithShip()) {
                        field.setBackground(Color.RED);
                    }
                }
            }
        } catch (ClassNotFoundException ex) {
            ex.printStackTrace();
        }
    }

    public void repaintMap() {
        for (int row = 0; row < 10; row++) {
            for (int column = 0; column < 10; column++) {
                if (!map.getSavedStateOfMap()[row][column]) {
                    map.getGridFields()[row][column].setBackground(Color.BLUE);
                } else {
                    map.getGridFields()[row][column].setBackground(Color.CYAN);
                }
            }
        }
        map.setPotencialStateOfMap(map.getSavedStateOfMap());
    }

}<commit_msg>Prevent loading game from revealing enemy ships<commit_after>package utils;

import gui.BattlefieldMap;
import gui.Field;
import java.awt.Color;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.List;
import model.Ship;

public class MapSaverAndLoader {

    private BattlefieldMap map;

    public MapSaverAndLoader(BattlefieldMap map) {
        this.map = map;
    }

    public void saveMap(ObjectOutputStream os) throws IOException {
        os.writeObject(map.getSavedStateOfMap());
        os.writeObject(map.getListOfShips());

        for (Field[] gridField : map.getGridFields()) { // TODO: try whole array(make serial. first)
            for (Field field : gridField) {
                os.writeObject(field.isWithShip());
                os.writeObject(field.isHit());
            }
        }
    }

    public void loadMap(ObjectInputStream ois) throws IOException {
        try {
            map.setSavedStateOfMap((boolean[][]) ois.readObject());
            @SuppressWarnings("unchecked")
            List<Ship> list = (List<Ship>) ois.readObject();
            map.setListOfShips(list);

            repaintMap();

            for (Field[] gridField : map.getGridFields()) {
                for (Field field : gridField) {
                    field.setContainsShip((Boolean) ois.readObject());
                    field.setIsHit((Boolean) ois.readObject());
                    if (field.isHit() && !field.isWithShip()) {
                        field.setBackground(Color.GRAY);
                    } else if (field.isHit() && field.isWithShip()) {
                        field.setBackground(Color.RED);
                    }
                }
            }
        } catch (ClassNotFoundException ex) {
            ex.printStackTrace();
        }
    }

    public void repaintMap() {
        for (int row = 0; row < 10; row++) {
            for (int column = 0; column < 10; column++) {
                if (map.getSavedStateOfMap()[row][column] && map.getNameOfMap().equals("user")) {
                    map.getGridFields()[row][column].setBackground(Color.CYAN);
                } else {
                    map.getGridFields()[row][column].setBackground(Color.BLUE);
                }
            }
        }
        map.setPotencialStateOfMap(map.getSavedStateOfMap());
    }

}
{'fraction_non_alphanumeric': 0.12000858737655647, 'fraction_numerical': 0.0025762129669386004, 'mean_word_length': 1.910056214865709, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, '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': '950836', 'n_tokens_mistral': 1307, 'n_tokens_neox': 1267, 'n_words': 241}