add random field generation

This commit is contained in:
matixezor 2021-03-14 19:32:24 +01:00
parent 9feb4048c6
commit 9ea066a79e
2 changed files with 8 additions and 6 deletions

View File

@ -1,10 +1,11 @@
from typing import List
from random import choices
from const import DEFAULT_FIELD
def generate_field() -> List[List[int]]:
return [choices(range(6), weights=[8, 8, 4, 4, 4, 4], k=10) for y in range(10)]
class Environment:
def __init__(self, field: List[List[int]] = DEFAULT_FIELD):
self.field = field
self.rows = len(field)
self.cols = len(field[0])
def __init__(self, field: List[List[int]] = None):
self.field = field if field else generate_field()

View File

@ -3,6 +3,7 @@ import pygame
from const import ICON
from agent import Agent
from game_ui import GameUi
from const import DEFAULT_FIELD
from environment import Environment
@ -11,7 +12,7 @@ def main():
pygame.display.set_caption('Super Saper')
pygame.display.set_icon(pygame.image.load(ICON))
env = Environment()
env = Environment(DEFAULT_FIELD)
agent = Agent()
game_ui = GameUi(agent, env)
game_ui.update()