<commit_before>#!/usr/bin/env python
#-*- coding: utf8 -*-

import ai
import random
from stuff_on_map import *

MAP_X = 640
MAP_Y = 480
SQUARE_SIZE = 32


class MapSizeException(Exception):
    pass


class MapLogicException(Exception):
    pass


class Map (object):

    def __init__(self):
        self.unpassable = []
        self.objects = []
        self.box_size = SQUARE_SIZE
        if MAP_X % SQUARE_SIZE or MAP_Y % SQUARE_SIZE:
            raise MapSizeException("Map sizes cannot be divided by box size")
        self.x_boxes = MAP_X / SQUARE_SIZE
        self.y_boxes = MAP_Y / SQUARE_SIZE
        self.player_starts = []
        self.enemy_starts = []

    def real_coords(self, x, y):
        return (
                    x * self.box_size - self.box_size / 2,
                    y * self.box_size - self.box_size / 2
                )

    def load(self, map_file):
        #!TODO: add try+catch, stat of map file for 0 bytes, too large
        mapf = open(map_file, 'r')
        map_str = mapf.read()
        mapf.close()

        y = 1
        for row in map_str.splitlines():
            if y > self.y_boxes or len(row) > self.x_boxes:
                raise MapSizeException("Map size in file corrupted")
            x = 1
            for square in row:
                if square == 'w':
                    self.objects.append(Wall(self.real_coords(x, y)))
                if square == 'p':
                    self.player_starts.append(self.real_coords(x, y))
                if square == 'e':
                    self.enemy_starts.append(self.real_coords(x, y))
                if square == '~':
                    self.unpassable.append(Water(self.real_coords(x, y)))<commit_msg>Format code in world.py<commit_after>#!/usr/bin/env python
#-*- coding: utf8 -*-

import ai
import random
from stuff_on_map import *

MAP_X = 640
MAP_Y = 480
SQUARE_SIZE = 32


class MapSizeException(Exception):
    pass


class MapLogicException(Exception):
    pass


class Map (object):

    def __init__(self):
        self.unpassable = []
        self.objects = []
        self.box_size = SQUARE_SIZE
        if MAP_X % SQUARE_SIZE or MAP_Y % SQUARE_SIZE:
            raise MapSizeException("Map sizes cannot be divided by box size")
        self.x_boxes = MAP_X / SQUARE_SIZE
        self.y_boxes = MAP_Y / SQUARE_SIZE
        self.player_starts = []
        self.enemy_starts = []

    def real_coords(self, x, y):
        return (x * self.box_size - self.box_size / 2,
                y * self.box_size - self.box_size / 2)

    def load(self, map_file):
        #!TODO: add try+catch, stat of map file for 0 bytes, too large
        mapf = open(map_file, 'r')
        map_str = mapf.read()
        mapf.close()

        y = 1
        for row in map_str.splitlines():
            if y > self.y_boxes or len(row) > self.x_boxes:
                raise MapSizeException("Map size in file corrupted")
            x = 1
            for square in row:
                if square == 'w':
                    self.objects.append(Wall(self.real_coords(x, y)))
                if square == 'p':
                    self.player_starts.append(self.real_coords(x, y))
                if square == 'e':
                    self.enemy_starts.append(self.real_coords(x, y))
                if square == '~':
                    self.unpassable.append(Water(self.real_coords(x, y)))
{'fraction_non_alphanumeric': 0.1063388625592417, 'fraction_numerical': 0.008293838862559242, 'mean_word_length': 1.7703035274815422, 'pattern_counts': {'":': 0, '<': 3, '<?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': '29794', 'n_tokens_mistral': 1136, 'n_tokens_neox': 1063, 'n_words': 268}