coordinated project modules; fully implemented blitting using display_assets.py; updated maps; fixed some bugs

This commit is contained in:
JakubR 2021-05-07 22:26:58 +02:00
parent e7270b8c3a
commit 8ffdacd603
9 changed files with 188 additions and 200 deletions

View File

@ -1,21 +1,19 @@
import pygame
import project_constants as const
import json_generator as js
import json
# Class of our agent, initialization of it
# movement functions (those defiend by the 'go_' prefix are not meant to actually move our agent, they just return some values
# that are later used by another function called 'is_valid_move' (which is defined in Minefield));
# movement functions (those defined by the 'go_' prefix are not meant to actually move our agent, they just return some
# values that are later used by another function called 'is_valid_move' (which is defined in Minefield));
class Agent:
def __init__(self, json_path):
with open(json_path) as json_data:
data = json.load(json_data)
self.row, self.column = data['agent_starting_position'].split(",")
self.row, self.column = data["agents_initial_state"]["position"].split(",")
self.position = [int(self.row), int(self.column)]
# self.direction = const.Direction()
self.direction = const.Direction.UP
self.direction = const.Direction(data["agents_initial_state"]["direction"])
def rotate_left(self):
self.direction = self.direction.previous()

View File

@ -2,6 +2,10 @@ import pygame
import project_constants as const
from mine_models.standard_mine import StandardMine
from mine_models.chained_mine import ChainedMine
from mine_models.time_mine import TimeMine
# ================================= #
# === SO THE OLD BLITTING WORKS === #
@ -14,7 +18,9 @@ tile_asset_options = {
}
mine_asset_options = {
"MINE": CONST.ASSET_MINE
"MINE": const.ASSET_MINE,
"CHAINS": const.ASSET_CHAINS,
"TIME_MINE": const.ASSET_TIME_MINE,
}
@ -52,10 +58,16 @@ def blit_graphics(minefield):
# draw a mine on top if there is one
if tile.mine is not None:
# current icons don't represent actual types, thus every mine has the same icon (temporary solution)
const.SCREEN.blit(mine_asset_options["MINE"], tile_screen_coords)
if isinstance(tile.mine, StandardMine):
const.SCREEN.blit(mine_asset_options["MINE"], tile_screen_coords)
if isinstance(tile.mine, ChainedMine):
predecessor = tile.mine.predecessor
predecessor_position = predecessor.position if predecessor is not None else None
display_chained_mine(tile.position, predecessor_position)
elif isinstance(tile.mine, TimeMine):
display_time_mine(tile.position, "0" + str(tile.mine.timer))
# sapper
display_sapper(
@ -241,9 +253,9 @@ def display_time_mine(coords, time):
mine_coords = calculate_screen_position(coords)
number_coords = mine_coords
if which_digit == const.Digit.ONES:
number_coords = (mine_coords[0] + 36, mine_coords[1] + 22)
elif which_digit == const.Digit.TENS:
number_coords = (mine_coords[0] + 44, mine_coords[1] + 22)
elif which_digit == const.Digit.TENS:
number_coords = (mine_coords[0] + 36, mine_coords[1] + 22)
const.SCREEN.blit(
number_asset,

View File

@ -4,12 +4,12 @@ import random
import project_constants as const
# import tile class
import tile as tl
from tile import Tile
# import mine models
import mine_models.standard_mine as sm
import mine_models.time_mine as tm
import mine_models.chained_mine as cm
from mine_models.standard_mine import StandardMine
from mine_models.time_mine import TimeMine
from mine_models.chained_mine import ChainedMine
class JsonGenerator:
@ -18,7 +18,7 @@ class JsonGenerator:
# constructor that can be used to set agent's initial state
def __init__(self, agents_initial_position=(0, 0), agents_initial_direction=const.Direction.UP.value):
# saving agent's initial state (position & direction)
self.agents_initial_position = agents_initial_position
self.agents_initial_position = format_position_to_tuple(agents_initial_position)
self.agents_initial_direction = agents_initial_direction
# saving data to the grid dictionary
@ -30,7 +30,7 @@ class JsonGenerator:
# sets agent's initial state
def set_agents_initial_state(self, position=(0, 0), direction=const.Direction.UP.value):
# setting fields in the instance
self.agents_initial_position = position
self.agents_initial_position = format_position_to_tuple(position)
self.agents_initial_direction = direction
# setting new agent's initial state
@ -39,11 +39,14 @@ class JsonGenerator:
"direction": direction
}
# overwrites grid field with a new grid with randomized terrains and mines
# overwrites grid field with a new grid with randomized colors and mines
def generate_randomized_grid(self, dimensions, mine_appearance_chance=0.15, predecessor_chance_decrease=0.25):
# clearing grid field
self.clear_grid()
# formatting dimensions to tuple
dimensions = format_position_to_tuple(dimensions)
# getting grid dimensions
num_of_rows, num_of_columns = dimensions
@ -53,13 +56,13 @@ class JsonGenerator:
for j in range(num_of_columns):
# picking random values for tiles
random_tile_terrain = random.choice(const.STRUCT_TILE_TERRAINS)
random_tile_color = random.choice(const.STRUCT_TILE_TERRAINS)
# adding added tile's indexes to a pool
tile_pool.append((i, j))
# creating random tile
self.add_tile((i, j), random_tile_terrain)
self.add_tile((i, j), random_tile_color)
# deleting agent's starting tile from the pool
deleted_row, deleted_column = self.agents_initial_position
@ -104,15 +107,15 @@ class JsonGenerator:
current_tile = predecessor
# adds a new tile or edits an existing one in the grid field
def add_tile(self, position, terrain):
def add_tile(self, position, color):
# creating new tile without a mine
self.grid[format_position_to_str(position)] = {
"terrain": terrain,
"color": color,
"mine": None
}
# adds a new tile with a mine or edits an existing one in the grid field
def add_tile_with_a_mine(self, position, terrain, mine_type, attribute_values):
def add_tile_with_a_mine(self, position, color, mine_type, attribute_values):
# setting mine data using attribute_values
mine_values = const.STRUCT_MINE_ATTRIBUTES[mine_type]
@ -122,14 +125,14 @@ class JsonGenerator:
# creating a new tile
self.grid[format_position_to_str(position)] = {
"terrain": terrain
"color": color
}
# updating the tile with a mine field
self.grid[format_position_to_str(position)]["mine"] = {}
for key in mine_values.keys():
self.grid[format_position_to_str()]["mine"][key] = mine_values[key]
self.grid[format_position_to_str(position)]["mine"][key] = mine_values[key]
# deletes a mine with a given position from the grid field
def delete_a_tile(self, position):
@ -227,16 +230,16 @@ def create_a_mine(mine_dict, position):
# if mine's type is "standard" - creating standard mine
if mine_dict["mine_type"] == "standard":
mine = sm.StandardMine(position)
mine = StandardMine(position)
# if mine's type is "time" - creating time mine
elif mine_dict["mine_type"] == "time":
timer_value = mine_dict["timer"]
mine = tm.TimeMine(position, timer_value)
mine = TimeMine(position, timer_value)
# if mine's type is "chained" - creating chained mine (no successors assigned yet)
elif mine_dict["mine_type"] == "chained":
mine = cm.ChainedMine(position)
mine = ChainedMine(position)
return mine
@ -247,11 +250,11 @@ def create_a_tile(tile_dict, position):
position = format_position_to_tuple(position)
# getting tile's parameters
terrain = tile_dict["terrain"]
mine = create_a_mine(position, tile_dict["mine"])
color = tile_dict["color"]
mine = create_a_mine(tile_dict["mine"], position)
# creating and returning a tile with the parameters set above
return tl.Tile(position, terrain, mine)
return Tile(position, color, mine)
# returns a list of tuples containing chained mine's position and it's predecessors position
@ -268,7 +271,8 @@ def get_chained_mine_and_its_predecessor_pairs(minefield_dictionary):
# getting the chained mines and it's predecessors positions
this_mines_position = tuple(int(i) for i in key.split(','))
its_predecessors_position = tuple(int(i) for i in minefield_dictionary[key]["mine"]["predecessor"].split(','))
its_predecessors_position = \
tuple(int(i) for i in minefield_dictionary[key]["mine"]["predecessor"].split(','))
# adding the positions to the list as a tuple
predecessors.append((this_mines_position, its_predecessors_position))

View File

@ -10,11 +10,14 @@ from display_assets import blit_graphics
from ui.input_box import *
from ui.button import *
from ui.text_box import *
import json_generator as jg
def main():
pygame.init()
pygame.display.set_caption(const.V_NAME_OF_WINDOW)
jes = jg.JsonGenerator()
print(jes.get_grid())
# for blocky textures
glEnable(GL_TEXTURE_2D)

View File

@ -1,10 +1,10 @@
import json
import agent as ag
import project_constants as const
import tile as tl
from mine_models import standard_mine as sm
from mine_models import time_mine as tm
from mine_models import chained_mine as cm
import json_generator as jg
class Minefield:
@ -14,29 +14,28 @@ class Minefield:
self.agent = ag.Agent(const.MAP_RANDOM_10x10)
# open JSON with minefield info
with open(json_path) as json_data:
data = json.load(json_data)
json_gen = jg.JsonGenerator()
json_gen.load_from_a_file(json_path)
# create matrix of a desired size, fill it with default tile objects
self.matrix = [
[
tl.Tile((row, column)) for column in range(const.V_GRID_HOR_TILES)
tl.Tile(
(row, column),
terrain_type=json_gen.get_tile((row, column))["terrain"],
mine=jg.create_a_mine(json_gen.get_mine((row, column)), (row, column))
) for column in range(const.V_GRID_HOR_TILES)
] for row in range(const.V_GRID_VER_TILES)
]
# iterate through tiles, set their terrains and add mines
for row in range(const.V_GRID_VER_TILES):
for column in range(const.V_GRID_HOR_TILES):
# iterate through chained mines, set mine predecessors
for pair in jg.get_chained_mine_and_its_predecessor_pairs(json_gen.get_grid()):
successor_position, predecessor_position = pair
successor_row, successor_column = successor_position
predecessor_row, predecessor_column = predecessor_position
# load tile's data from json
tile_data = data[f"{row},{column}"]
# if there is a mine, create & assign new Mine object (type recognition included)
if tile_data["mine"] is not None:
mine = self._create_mine(tile_data["mine"], row, column)
self.matrix[row][column].mine = mine
self.matrix[row][column].terrain_type = tile_data["terrain"].upper()
predecessor = self.matrix[predecessor_row][predecessor_column]
self.matrix[successor_row][successor_column].mine.predecessor = predecessor
# ================ #
# === MOVEMENT === #

View File

@ -17,11 +17,11 @@ V_NAME_OF_WINDOW = "MineFusion TM"
DIR_ASSETS = os.path.join("resources", "assets")
V_FPS = 60
ACTION_INTERVAL = 1 # interval between two actions in seconds
ACTION_INTERVAL = 1 # interval between two actions in seconds
V_TILE_SIZE = 60
V_GRID_VER_TILES = 10 # vertical (number of rows)
V_GRID_HOR_TILES = 10 # horizontal (number of columns)
V_GRID_VER_TILES = 10 # vertical (number of rows)
V_GRID_HOR_TILES = 10 # horizontal (number of columns)
V_SCREEN_PADDING = 10
V_NUMBER_PADDING = 50
V_TILE_AREA_HEIGHT = V_TILE_SIZE * V_GRID_VER_TILES
@ -30,7 +30,7 @@ V_TILE_AREA_WIDTH = V_TILE_SIZE * V_GRID_HOR_TILES
SCREEN = pygame.display.set_mode(
(
V_TILE_AREA_WIDTH + 2 * V_SCREEN_PADDING + V_NUMBER_PADDING, # screen width
V_TILE_AREA_HEIGHT + 2 * V_SCREEN_PADDING + V_NUMBER_PADDING # screen height
V_TILE_AREA_HEIGHT + 2 * V_SCREEN_PADDING + V_NUMBER_PADDING # screen height
)
)
@ -85,8 +85,8 @@ class Terrain(Enum):
# # USED BY JSON GENERATOR
# used to generate random tile colors
#####################STRUCT_TILE_COLORS = ["BLUE", "GREEN", "ORANGE", "PURPLE", "RED", "WHITE", "YELLOW"]
STRUCT_TILE_TERRAINS = ["CONCRETE","GRASS","MUD"]
STRUCT_TILE_TERRAINS = ["CONCRETE", "GRASS", "MUD"]
# used to generate random mines and create not random mines
STRUCT_MINE_TYPES = ["standard", "chained", "time"]
@ -119,14 +119,12 @@ STRUCT_MINE_ATTRIBUTE_TYPES = {
"time": [int]
}
# ============== #
# ==== MAPS ==== #
# ============== #
MAP_RANDOM_10x10 = os.path.join("resources", "minefields", "fourthmap.json")
# ============== #
# === ASSETS === #
# ============== #
@ -176,7 +174,6 @@ ASSET_TIME_MINE = pygame.transform.scale(
(V_TILE_SIZE, V_TILE_SIZE)
)
# ==================== #
# === TIME NUMBERS === #
# ==================== #
@ -231,7 +228,6 @@ ASSET_NUMBER_TIME_9 = pygame.transform.scale(
(6, 16)
)
# ====================== #
# === CHAINS NUMBERS === #
# ====================== #
@ -316,7 +312,6 @@ ASSET_NUMBER_CHAINS_15 = pygame.transform.scale(
(6, 12)
)
# ================== #
# === OLD ASSETS === #
# ================== #

View File

@ -14,7 +14,6 @@
"0,3": {
"terrain": "CONCRETE",
"mine": {
"asset": "B",
"mine_type": "chained",
"predecessor": null
}
@ -22,7 +21,6 @@
"0,4": {
"terrain": "CONCRETE",
"mine": {
"asset": "B",
"mine_type": "chained",
"predecessor": null
}
@ -42,7 +40,6 @@
"0,8": {
"terrain": "CONCRETE",
"mine": {
"asset": "B",
"mine_type": "chained",
"predecessor": "0,3"
}
@ -50,7 +47,6 @@
"0,9": {
"terrain": "GRASS",
"mine": {
"asset": "F",
"mine_type": "time",
"timer": 20
}
@ -62,7 +58,6 @@
"1,1": {
"terrain": "GRASS",
"mine": {
"asset": "A",
"mine_type": "standard"
}
},
@ -73,7 +68,6 @@
"1,3": {
"terrain": "CONCRETE",
"mine": {
"asset": "B",
"mine_type": "chained",
"predecessor": null
}
@ -109,7 +103,6 @@
"2,1": {
"terrain": "CONCRETE",
"mine": {
"asset": "A",
"mine_type": "standard"
}
},
@ -120,7 +113,6 @@
"2,3": {
"terrain": "MUD",
"mine": {
"asset": "B",
"mine_type": "chained",
"predecessor": null
}
@ -132,7 +124,6 @@
"2,5": {
"terrain": "MUD",
"mine": {
"asset": "A",
"mine_type": "standard"
}
},
@ -147,7 +138,6 @@
"2,8": {
"terrain": "MUD",
"mine": {
"asset": "B",
"mine_type": "chained",
"predecessor": null
}
@ -163,7 +153,6 @@
"3,1": {
"terrain": "MUD",
"mine": {
"asset": "F",
"mine_type": "time",
"timer": 19
}
@ -175,7 +164,6 @@
"3,3": {
"terrain": "MUD",
"mine": {
"asset": "B",
"mine_type": "chained",
"predecessor": "1,3"
}
@ -191,7 +179,6 @@
"3,6": {
"terrain": "MUD",
"mine": {
"asset": "B",
"mine_type": "chained",
"predecessor": null
}
@ -219,7 +206,6 @@
"4,2": {
"terrain": "CONCRETE",
"mine": {
"asset": "A",
"mine_type": "standard"
}
},
@ -242,7 +228,6 @@
"4,7": {
"terrain": "CONCRETE",
"mine": {
"asset": "B",
"mine_type": "chained",
"predecessor": null
}
@ -262,7 +247,6 @@
"5,1": {
"terrain": "MUD",
"mine": {
"asset": "B",
"mine_type": "chained",
"predecessor": "2,3"
}
@ -278,7 +262,6 @@
"5,4": {
"terrain": "CONCRETE",
"mine": {
"asset": "B",
"mine_type": "chained",
"predecessor": "2,8"
}
@ -326,7 +309,6 @@
"6,5": {
"terrain": "GRASS",
"mine": {
"asset": "A",
"mine_type": "standard"
}
},
@ -345,14 +327,12 @@
"6,9": {
"terrain": "CONCRETE",
"mine": {
"asset": "A",
"mine_type": "standard"
}
},
"7,0": {
"terrain": "CONCRETE",
"mine": {
"asset": "B",
"mine_type": "chained",
"predecessor": "4,7"
}
@ -376,14 +356,12 @@
"7,5": {
"terrain": "GRASS",
"mine": {
"asset": "A",
"mine_type": "standard"
}
},
"7,6": {
"terrain": "CONCRETE",
"mine": {
"asset": "F",
"mine_type": "time",
"timer": 39
}
@ -407,7 +385,6 @@
"8,1": {
"terrain": "GRASS",
"mine": {
"asset": "F",
"mine_type": "time",
"timer": 24
}
@ -419,7 +396,6 @@
"8,3": {
"terrain": "CONCRETE",
"mine": {
"asset": "A",
"mine_type": "standard"
}
},
@ -442,7 +418,6 @@
"8,8": {
"terrain": "GRASS",
"mine": {
"asset": "B",
"mine_type": "chained",
"predecessor": "3,6"
}
@ -474,7 +449,6 @@
"9,5": {
"terrain": "GRASS",
"mine": {
"asset": "B",
"mine_type": "chained",
"predecessor": "0,4"
}
@ -495,6 +469,8 @@
"terrain": "MUD",
"mine": null
},
"agent_starting_position": "0,0"
"agents_initial_state": {
"direction": 1,
"position": "0,0"
}
}

View File

@ -1,456 +1,456 @@
{
"0,0": {
"color": "BLUE",
"terrain": "GRASS",
"mine": null
},
"0,1": {
"color": "WHITE",
"terrain": "GRASS",
"mine": null
},
"0,2": {
"color": "GREEN",
"terrain": "MUD",
"mine": null
},
"0,3": {
"color": "PURPLE",
"terrain": "CONCRETE",
"mine": null
},
"0,4": {
"color": "WHITE",
"terrain": "GRASS",
"mine": null
},
"0,5": {
"color": "GREEN",
"terrain": "MUD",
"mine": null
},
"0,6": {
"color": "RED",
"terrain": "MUD",
"mine": null
},
"0,7": {
"color": "ORANGE",
"terrain": "CONCRETE",
"mine": null
},
"0,8": {
"color": "ORANGE",
"terrain": "CONCRETE",
"mine": null
},
"0,9": {
"color": "ORANGE",
"terrain": "CONCRETE",
"mine": {
"mine_type": "time",
"timer": 28
}
},
"1,0": {
"color": "ORANGE",
"terrain": "CONCRETE",
"mine": null
},
"1,1": {
"color": "PURPLE",
"terrain": "CONCRETE",
"mine": null
},
"1,2": {
"color": "GREEN",
"terrain": "MUD",
"mine": null
},
"1,3": {
"color": "WHITE",
"terrain": "GRASS",
"mine": {
"mine_type": "chained",
"predecessor": "8,9"
}
},
"1,4": {
"color": "PURPLE",
"terrain": "CONCRETE",
"mine": null
},
"1,5": {
"color": "RED",
"terrain": "MUD",
"mine": null
},
"1,6": {
"color": "BLUE",
"terrain": "GRASS",
"mine": null
},
"1,7": {
"color": "YELLOW",
"terrain": "GRASS",
"mine": null
},
"1,8": {
"color": "BLUE",
"terrain": "GRASS",
"mine": null
},
"1,9": {
"color": "YELLOW",
"terrain": "GRASS",
"mine": null
},
"2,0": {
"color": "ORANGE",
"terrain": "CONCRETE",
"mine": null
},
"2,1": {
"color": "ORANGE",
"terrain": "CONCRETE",
"mine": {
"mine_type": "time",
"timer": 27
}
},
"2,2": {
"color": "YELLOW",
"terrain": "GRASS",
"mine": null
},
"2,3": {
"color": "RED",
"terrain": "MUD",
"mine": null
},
"2,4": {
"color": "PURPLE",
"terrain": "CONCRETE",
"mine": null
},
"2,5": {
"color": "ORANGE",
"terrain": "CONCRETE",
"mine": null
},
"2,6": {
"color": "BLUE",
"terrain": "GRASS",
"mine": {
"mine_type": "chained",
"predecessor": "7,2"
}
},
"2,7": {
"color": "BLUE",
"terrain": "GRASS",
"mine": null
},
"2,8": {
"color": "BLUE",
"terrain": "GRASS",
"mine": null
},
"2,9": {
"color": "BLUE",
"terrain": "GRASS",
"mine": null
},
"3,0": {
"color": "WHITE",
"terrain": "GRASS",
"mine": {
"mine_type": "time",
"timer": 27
}
},
"3,1": {
"color": "ORANGE",
"terrain": "CONCRETE",
"mine": null
},
"3,2": {
"color": "GREEN",
"terrain": "MUD",
"mine": null
},
"3,3": {
"color": "BLUE",
"terrain": "GRASS",
"mine": null
},
"3,4": {
"color": "PURPLE",
"terrain": "CONCRETE",
"mine": {
"mine_type": "chained",
"predecessor": "8,8"
}
},
"3,5": {
"color": "YELLOW",
"terrain": "GRASS",
"mine": null
},
"3,6": {
"color": "RED",
"terrain": "MUD",
"mine": null
},
"3,7": {
"color": "GREEN",
"terrain": "MUD",
"mine": null
},
"3,8": {
"color": "WHITE",
"terrain": "GRASS",
"mine": null
},
"3,9": {
"color": "YELLOW",
"terrain": "GRASS",
"mine": null
},
"4,0": {
"color": "GREEN",
"terrain": "MUD",
"mine": {
"mine_type": "chained",
"predecessor": null
}
},
"4,1": {
"color": "PURPLE",
"terrain": "CONCRETE",
"mine": {
"mine_type": "standard"
}
},
"4,2": {
"color": "YELLOW",
"terrain": "GRASS",
"mine": null
},
"4,3": {
"color": "RED",
"terrain": "MUD",
"mine": null
},
"4,4": {
"color": "BLUE",
"terrain": "GRASS",
"mine": null
},
"4,5": {
"color": "BLUE",
"terrain": "GRASS",
"mine": null
},
"4,6": {
"color": "ORANGE",
"terrain": "CONCRETE",
"mine": null
},
"4,7": {
"color": "GREEN",
"terrain": "MUD",
"mine": null
},
"4,8": {
"color": "ORANGE",
"terrain": "CONCRETE",
"mine": null
},
"4,9": {
"color": "PURPLE",
"terrain": "CONCRETE",
"mine": null
},
"5,0": {
"color": "BLUE",
"terrain": "GRASS",
"mine": null
},
"5,1": {
"color": "GREEN",
"terrain": "MUD",
"mine": null
},
"5,2": {
"color": "GREEN",
"terrain": "MUD",
"mine": null
},
"5,3": {
"color": "YELLOW",
"terrain": "GRASS",
"mine": {
"mine_type": "time",
"timer": 25
}
},
"5,4": {
"color": "YELLOW",
"terrain": "GRASS",
"mine": null
},
"5,5": {
"color": "RED",
"terrain": "MUD",
"mine": null
},
"5,6": {
"color": "YELLOW",
"terrain": "GRASS",
"mine": null
},
"5,7": {
"color": "PURPLE",
"terrain": "CONCRETE",
"mine": null
},
"5,8": {
"color": "BLUE",
"terrain": "GRASS",
"mine": null
},
"5,9": {
"color": "BLUE",
"terrain": "GRASS",
"mine": null
},
"6,0": {
"color": "ORANGE",
"terrain": "CONCRETE",
"mine": {
"mine_type": "chained",
"predecessor": "6,1"
}
},
"6,1": {
"color": "BLUE",
"terrain": "GRASS",
"mine": {
"mine_type": "chained",
"predecessor": "3,4"
}
},
"6,2": {
"color": "ORANGE",
"terrain": "CONCRETE",
"mine": null
},
"6,3": {
"color": "YELLOW",
"terrain": "GRASS",
"mine": null
},
"6,4": {
"color": "PURPLE",
"terrain": "CONCRETE",
"mine": null
},
"6,5": {
"color": "GREEN",
"terrain": "MUD",
"mine": null
},
"6,6": {
"color": "PURPLE",
"terrain": "CONCRETE",
"mine": null
},
"6,7": {
"color": "YELLOW",
"terrain": "GRASS",
"mine": null
},
"6,8": {
"color": "WHITE",
"terrain": "GRASS",
"mine": null
},
"6,9": {
"color": "GREEN",
"terrain": "MUD",
"mine": null
},
"7,0": {
"color": "YELLOW",
"terrain": "GRASS",
"mine": {
"mine_type": "time",
"timer": 30
}
},
"7,1": {
"color": "WHITE",
"terrain": "GRASS",
"mine": null
},
"7,2": {
"color": "WHITE",
"terrain": "GRASS",
"mine": {
"mine_type": "chained",
"predecessor": "7,3"
}
},
"7,3": {
"color": "GREEN",
"terrain": "MUD",
"mine": {
"mine_type": "chained",
"predecessor": null
}
},
"7,4": {
"color": "ORANGE",
"terrain": "CONCRETE",
"mine": null
},
"7,5": {
"color": "PURPLE",
"terrain": "CONCRETE",
"mine": {
"mine_type": "standard"
}
},
"7,6": {
"color": "PURPLE",
"terrain": "CONCRETE",
"mine": null
},
"7,7": {
"color": "BLUE",
"terrain": "GRASS",
"mine": null
},
"7,8": {
"color": "WHITE",
"terrain": "GRASS",
"mine": null
},
"7,9": {
"color": "PURPLE",
"terrain": "CONCRETE",
"mine": null
},
"8,0": {
"color": "GREEN",
"terrain": "MUD",
"mine": null
},
"8,1": {
"color": "PURPLE",
"terrain": "CONCRETE",
"mine": null
},
"8,2": {
"color": "WHITE",
"terrain": "GRASS",
"mine": null
},
"8,3": {
"color": "PURPLE",
"terrain": "CONCRETE",
"mine": null
},
"8,4": {
"color": "PURPLE",
"terrain": "CONCRETE",
"mine": null
},
"8,5": {
"color": "YELLOW",
"terrain": "GRASS",
"mine": null
},
"8,6": {
"color": "WHITE",
"terrain": "GRASS",
"mine": {
"mine_type": "standard"
}
},
"8,7": {
"color": "GREEN",
"terrain": "MUD",
"mine": null
},
"8,8": {
"color": "PURPLE",
"terrain": "CONCRETE",
"mine": {
"mine_type": "chained",
"predecessor": null
}
},
"8,9": {
"color": "PURPLE",
"terrain": "CONCRETE",
"mine": {
"mine_type": "chained",
"predecessor": null
}
},
"9,0": {
"color": "ORANGE",
"terrain": "CONCRETE",
"mine": null
},
"9,1": {
"color": "BLUE",
"terrain": "GRASS",
"mine": {
"mine_type": "chained",
"predecessor": "4,0"
}
},
"9,2": {
"color": "PURPLE",
"terrain": "CONCRETE",
"mine": null
},
"9,3": {
"color": "PURPLE",
"terrain": "CONCRETE",
"mine": null
},
"9,4": {
"color": "WHITE",
"terrain": "GRASS",
"mine": null
},
"9,5": {
"color": "PURPLE",
"terrain": "CONCRETE",
"mine": null
},
"9,6": {
"color": "WHITE",
"terrain": "GRASS",
"mine": null
},
"9,7": {
"color": "RED",
"terrain": "MUD",
"mine": null
},
"9,8": {
"color": "ORANGE",
"terrain": "CONCRETE",
"mine": null
},
"9,9": {
"color": "RED",
"terrain": "MUD",
"mine": null
},
"agents_initial_state": {

21
tile.py
View File

@ -1,17 +1,18 @@
from project_constants import Terrain as t
from project_constants import Terrain
#Assume_cost function assumes colour as an argument (colour that is already given to a tile) and depending
#on what it is returns value of Terrein Enum
#It is used in Tile.cost (giving the value to the tile)
# Assume_cost function assumes colour as an argument (colour that is already given to a tile) and depending
# on what it is returns value of Terrein Enum
# It is used in Tile.cost (giving the value to the tile)
def assume_cost(terrain_type):
if (terrain_type == "CONCRETE"):
return t.CONCRETE
elif (terrain_type == "GRASS"):
return t.GRASS
elif (terrain_type == "MUD"):
return t.MUD
if terrain_type == "CONCRETE":
return Terrain.CONCRETE
elif terrain_type == "GRASS":
return Terrain.GRASS
elif terrain_type == "MUD":
return Terrain.MUD
class Tile: