Example #1
0
    def test_when_checking_for_mines_on_top_then_detects_right_number(self):
        string = "x3y2***..."
        grid = Grid(string)
        mined_string = grid.get_mines_surronding_squares()
        mined_string = mined_string.replace('\n', '')

        self.assertEqual(int(mined_string[4]), self.MAX_NUMBER_MINES_CENTER_FOR_ROW)
        self.assertEqual(int(mined_string[3]), self.MAX_NUMBER_MINES_CORNER_FOR_ROW)
Example #2
0
    def test_when_checking_for_mines_then_detects_right_number(self):
        string = "x3y3****.****"
        middle = 4
        grid = Grid(string)
        mined_string = grid.get_mines_surronding_squares()
        mined_string = mined_string.replace('\n', '')

        self.assertEqual(self.MAX_NUMBER_MINES_AROUND_SQUARE, int(mined_string[middle]))
Example #3
0
    def test_when_checking_for_mines_on_sides_then_detects_right_number(self):
        string = "x1y3.*."
        grid = Grid(string)
        mined_string = grid.get_mines_surronding_squares()
        mined_string = mined_string.replace('\n', '')

        self.assertEqual(int(mined_string[0]), 1)
        self.assertEqual(int(mined_string[2]), 1)
Example #4
0
    def __init__(self, params: EnvironmentParams):
        self.display = DHDisplay()
        super().__init__(params, self.display)

        self.grid = Grid(params.grid_params, stats=self.stats)
        self.rewards = Rewards(params.reward_params, stats=self.stats)
        self.physics = Physics(params=params.physics_params, stats=self.stats)
        self.agent = DDQNAgent(params.agent_params,
                               self.grid.get_example_state(),
                               self.physics.get_example_action(),
                               stats=self.stats)
        self.trainer = DDQNTrainer(params.trainer_params, agent=self.agent)

        self.display.set_channel(self.physics.channel)

        self.first_action = True
        self.last_actions = []
        self.last_rewards = []
        self.last_states = []
Example #5
0
from src.Grid import Grid

try:
    lines = [line.rstrip('\n') for line in open('minesweeper.txt')]
except FileNotFoundError:
    raise IOError("File 'minesweeper.txt' needs to exist !")

for line in lines:
    grid = Grid(line)
    print(grid)
 def __init__(self, xml_file, xml_recipe):
     self.grid = Grid(xml_recipe, xml_file)
     self.grid.initializeGrid()
     self.gridBasicMeasures = ['residence_time', 'concentrations']
     self.beachCondition = getBeachFromRecipe(xml_recipe)
Example #7
0
    def test_when_adding_padding_then_it_is_correctly_set(self):
        string = "x2y3.*.*.*"
        grid = Grid(string)
        padded = grid.pad_grid(grid.data)

        self.assertEqual((3 + 2) * (2 + 2), sum(len(x) for x in padded))
Example #8
0
    def test_when_parsing_grid_then_row_number_matches_input(self):
        grid_data = "...***"
        string = "x3y2" + grid_data
        grid = Grid(string)

        self.assertEqual(2, len(grid.data))
Example #9
0
    def test_when_parsing_grid_then_correct_data_is_set(self):
        grid_data = "*..*"
        string = "x2y2" + grid_data
        grid = Grid(string)

        self.assertEqual(len(grid_data), sum(len(x) for x in grid.data))
Example #10
0
 def test_given_invalid_grid_data_when_parsing_then_raises(self):
     string = "x1y1.."
     with self.assertRaises(SyntaxError):
         grid = Grid(string)
Example #11
0
    def test_when_parsing_grid_then_correct_dimensions_are_set(self):
        string = "x1y1*"
        grid = Grid(string)

        self.assertEqual((grid.x, grid.y), (1, 1))