Пример #1
0
 def test_get_filled_with(self):
     tkinter = Tk()
     canvas = Canvas(tkinter, width=500, height=500)
     cell0 = Cell(canvas, 200, 300, 50, "grey")
     self.assertEqual(None, cell0.get_filled_with())
     piece0 = Piece(cell0, "white")
     self.assertEqual(piece0, cell0.get_filled_with())
Пример #2
0
 def __init__(self, canvas):
     # canvas this board is placed on
     self.__canvas = canvas
     # othello is played on an 8 x 8 board
     self.__size = 8
     # internal representation of this board
     self.__board = []
     for x in range(self.__size):
         vertical_strip = []
         for y in range(self.__size):
             if (x + y) % 2 == 0:
                 vertical_strip.append(Cell(canvas, x * 50 + 50, y * 50 + 50, 50, "grey"))
             else:
                 vertical_strip.append(Cell(canvas, x * 50 + 50, y * 50 + 50, 50, "white"))
         self.__board.append(vertical_strip)
     # othello board starts with four pieces in the middle
     Piece(self.__board[int(self.__size / 2)][int(self.__size / 2 - 1)], "black")
     Piece(self.__board[int(self.__size / 2 - 1)][int(self.__size / 2 - 1)], "white")
     Piece(self.__board[int(self.__size / 2 - 1)][int(self.__size / 2)], "black")
     Piece(self.__board[int(self.__size / 2)][int(self.__size / 2)], "white")
     # the first cell to be selected is at coordinates (0, 0)
     self.__cell_selected_coordinates = (0, 0)
     self.__board[self.__cell_selected_coordinates[0]][self.__cell_selected_coordinates[1]].set_is_selected(True)
     # number of turns played so far in game
     self.__turns_played = 0
 def test_cell_state_filled_unfilled(self):
     cell = Cell()
     cell.state = True
     self.assertTrue(cell)
     self.assertEquals(str(cell), 'x')
     cell.state = False
     self.assertFalse(cell.state)
     self.assertEquals(str(cell), ' ')
Пример #4
0
 def test_equals(self):
     tkinter = Tk()
     canvas0 = Canvas(tkinter, width=500, height=500)
     canvas1 = Canvas(tkinter, width=500, height=500)
     cell0 = Cell(canvas0, 250, 250, 50, "grey")
     cell1 = Cell(canvas1, 250, 250, 50, "grey")
     cell2 = Cell(canvas0, 250, 250, 50, "grey")
     # difference between == and __eq__(self, other)
     self.assertNotEqual(cell0, cell1)
     self.assertEqual(cell0, cell2)
 def test_condition_one(self):
     test_grid = Grid(size=4)
     game = GameOfLife(grid=test_grid)
     for x in range(0, 4):
         [
             test_grid.set_cell(
                 Cell(live=Life(status=True),
                      position_x=Position(x),
                      position_y=Position(y))) for y in range(0, 4)
         ]
     self.assertEqual(
         False,
         game.apply_rule_one(
             Cell(live=Life(status=True),
                  position_x=Position(2),
                  position_y=Position(2))))
Пример #6
0
 def test_set_is_selected(self):
     tkinter = Tk()
     canvas = Canvas(tkinter, width=500, height=500)
     cell0 = Cell(canvas, 200, 300, 50, "grey")
     try:
         cell0.set_is_selected("Hello")
     except ValueError:
         self.assertEqual(cell0.get_is_selected(), False)
     cell0.set_is_selected(True)
     self.assertEqual(cell0.get_is_selected(), True)
    def __init__(self):

        self.size = (settings.COLNO, settings.ROWNO)
        self.cells = [[Cell(Position(y, x)) for x in range(self.size[1])] \
                      for y in range(self.size[0])]

        self.next_state = [[0 for x in range(self.size[1])] \
                      for y in range(self.size[0])]

        for i in range(self.size[0]):
            for j in range(self.size[1]):
                self.cells[i][j] == Cell(Position(i, j))

        self.rule_dict = RuleInitialiser("rules.txt").generate_dict()

        self.__init__loop()

        self.changed_cells = []
Пример #8
0
    def apply_rule_one(self, cell: Cell) -> bool:
        surrounded_alive_cells = []
        cell_positions = cell.return_position()
        x = cell_positions[0]
        y = cell_positions[1]
        allowed_positions = [[x - 1, y], [x + 1, y], [x, y - 1], [x, y + 1],
                             [x + 1, y + 1], [x - 1, y - 1], [x - 1, y + 1],
                             [x + 1, y - 1]]
        for row in range(0, self.grid.size):
            [
                surrounded_alive_cells.append(cell)
                for cell in self.grid.grid[row]
                if cell.live and cell.position in allowed_positions
            ]

        if len(surrounded_alive_cells) > 3:
            cell.live = False
            return False

        return True
Пример #9
0
 def test_get_is_selected(self):
     tkinter = Tk()
     canvas = Canvas(tkinter, width=500, height=500)
     cell0 = Cell(canvas, 200, 300, 50, "grey")
     self.assertEqual(cell0.get_is_selected(), False)
     cell0.set_is_selected(True)
     self.assertEqual(cell0.get_is_selected(), True)
Пример #10
0
    def test_initialize_grid_correct(self):
        N = 3
        list_grid = ['--m', '-x-', '-p-']

        grid_ = [[
            Cell(cell_type=CellType.free),
            Cell(cell_type=CellType.free),
            Cell(cell_type=CellType.mario)
        ],
                 [
                     Cell(cell_type=CellType.free),
                     Cell(cell_type=CellType.obstacle),
                     Cell(cell_type=CellType.free)
                 ],
                 [
                     Cell(cell_type=CellType.free),
                     Cell(cell_type=CellType.princess),
                     Cell(cell_type=CellType.free)
                 ]]

        gr = GridHandler()
        grid = gr.initialize_grid(N, list_grid)

        self.assertEqual(grid.board[0][0].type == grid_[0][0].type, True)
        self.assertEqual(grid.board[0][1].type == grid_[0][1].type, True)
        self.assertEqual(grid.board[0][2].type == grid_[0][2].type, True)
        self.assertEqual(grid.board[1][0].type == grid_[1][0].type, True)
        self.assertEqual(grid.board[1][1].type == grid_[1][1].type, True)
        self.assertEqual(grid.board[1][2].type == grid_[1][2].type, True)
        self.assertEqual(grid.board[2][0].type == grid_[2][0].type, True)
        self.assertEqual(grid.board[2][1].type == grid_[2][1].type, True)
        self.assertEqual(grid.board[2][2].type == grid_[2][2].type, True)
        self.assertEqual(grid.board[0][0].pos == [0, 0], True)
        self.assertEqual(grid.board[0][1].pos == [0, 1], True)
        self.assertEqual(grid.board[0][2].pos == [0, 2], True)
        self.assertEqual(grid.board[1][0].pos == [1, 0], True)
        self.assertEqual(grid.board[1][1].pos == [1, 1], True)
        self.assertEqual(grid.board[1][2].pos == [1, 2], True)
        self.assertEqual(grid.board[2][0].pos == [2, 0], True)
        self.assertEqual(grid.board[2][1].pos == [2, 1], True)
        self.assertEqual(grid.board[2][2].pos == [2, 2], True)
        self.assertEqual(gr.error_flag, False)
Пример #11
0
 def test_fill(self):
     tkinter = Tk()
     canvas = Canvas(tkinter, width=500, height=500)
     cell0 = Cell(canvas, 200, 300, 50, "grey")
     cell1 = Cell(canvas, 200, 300, 50, "white")
     piece0 = Piece(cell0, "white")
     piece1 = Piece(cell1, "black")
     try:
         piece1 = Piece(cell0, "black")
         print(str(piece1) + " did not throw an exception!")
         self.assertNotEqual(piece1, cell0.get_filled_with())
     except ValueError:
         self.assertEqual(piece0, cell0.get_filled_with())
         self.assertEqual(cell1, piece1.get_cell())
     self.assertEqual(cell0, cell0.get_filled_with().get_cell())
Пример #12
0
 def test_assign_wrong_coordinates(self):
     state = Life(False)
     posX = Position(-12)
     posY = Position(2)
     cell = Cell(live=state,position_x= posX, position_y = posY)
     self.assertEqual(False, cell.return_position())
Пример #13
0
 def test_generate_live_cell(self):
     state = Life(True)
     posX = Position(0)
     posY = Position(0)
     cell = Cell(live=state,position_x= posX, position_y = posY)
     self.assertEqual(True, cell.live)
Пример #14
0
def test_Cell_make_yellow():
    cell = Cell.Cell()
    cell.make_yellow()
    assert not (cell.is_empty())
    assert not (cell.is_red())
    assert (cell.is_yellow())
Пример #15
0
def test_Cell_construction():
    cell = Cell.Cell()
    assert (cell.current_state == const.CellState.EMPTY)
    assert (cell.is_empty())
    assert not (cell.is_red())
    assert not (cell.is_yellow())
Пример #16
0
 def test_get_color(self):
     tkinter = Tk()
     canvas = Canvas(tkinter, width=500, height=500)
     cell0 = Cell(canvas, 200, 300, 50, "grey")
     self.assertEqual(cell0.get_color(), "grey")
pygame.display.init()
screen = pygame.display.set_mode((settings.SCREENWIDTH, settings.SCREENHEIGHT))
fps_clock = pygame.time.Clock()

grid = Grid()

#for i in range(Settings.COLLNO):
 #   for j in range(Settings.ROWNO):
  ##      grid.cells[i][j] = Cell(Position(i, j))

WHITE = (255, 255, 255)

is_paused = True
FPS = settings.FPS

cell = Cell(Position(3, 3))
fpscount = 0

take_screenshot = False


while True:
    mousePressed = False
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
        elif event.type == pygame.KEYDOWN:
            if event.key == pygame.K_ESCAPE:
                pygame.quit()
            elif event.key == pygame.K_p:
                is_paused = not is_paused
Пример #18
0
 def test_assign_correct_coordinates(self):
     state = Life(False)
     posX = Position(12)
     posY = Position(2)
     cell = Cell(live=state,position_x= posX, position_y = posY)
     self.assertEqual([12,2], cell.return_position())
 def test_set_cell_colour(self):
     cell = Cell()
     cell.colour = 'o'
     self.assertEquals(cell.colour, 'o')
 def test_set_cell_state_filled(self):
     cell = Cell()
     cell.state = True
     self.assertTrue(cell.state)
     self.assertEquals(str(cell), 'x')