Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
12 views9 pages

(Group 8) Group Work Week 9 Report

Report work
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views9 pages

(Group 8) Group Work Week 9 Report

Report work
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

VIETNAM JAPAN UNIVERSITY - VNU

MAJOR COURSE
COMPUTER SCIENCE AND ENGINEERING
------------------------

SUBJECT REPORT
TOPIC: Modelling Group Work
Group Name: InNova
Group members: Trần Thành Đạt​
​ ​ ​ ​ ​ ​ Đặng Thanh Phong​
​ ​ ​ ​ ​ ​ Phạm Việt Hưng​
​ ​ ​ ​ ​ ​ Dương Văn Quang​
​ ​ ​ ​ ​ ​ Phạm Hồng Kiên
Lecturer: Prof. Tetsuo Tamai​
​ ​ ​ Subject: Software Engineering​
​ ​ ​ Year: 2024 - 2025

Ha Noi, 2025
Group work - Week 9 Report

I.​ Our team members

Ordinal Name Student ID Role


1 Đặng Thanh 23110329 Leader, main
Phong coder.
2 Trần Thành Đạt 23110303 Secondary coder
3 Dương Văn 23110328 Checking,
Quang debugger.
4 Phạm Hồng Kiên Tester, report
analyst
5 Phạm Việt Hưng 23110173 Tester, Report
analyst

II. Main Group Work


1. Exercise Objective
-​ Develop a program named "Game of Life", which simulates the
evolution of cells on a two-dimensional grid. Each cell can exist in
one of two states: alive (1) or dead (0). The future state of each
cell is calculated based on the count of its surrounding live
neighbors.
-​ The ita library is utilized to display the changes across generations
through visual animations.
-​ Language: Python
2. Source Code
import ita
import random

def count_neighbor(data, i, j):


rows, cols = len(data), len(data[0])
count = 0
for di in [-1, 0, 1]:
for dj in [-1, 0, 1]:
if di == 0 and dj == 0:
continue
ni, nj = i + di, j + dj
if 0 <= ni < rows and 0 <= nj < cols and data[ni][nj] == 1:
count += 1
return count

def lifegame_rule(cur, neighbor):


if cur == 1:
if neighbor < 2:
return 0
elif neighbor in [2, 3]:
return 1
else:
return 0
else:
if neighbor == 3:
return 1
return 0

def lifegame_step(data):
rows, cols = len(data), len(data[0])
new_data = ita.array.make2d(rows, cols)
for i in range(rows):
for j in range(cols):
neighbors = count_neighbor(data, i, j)
new_data[i][j] = lifegame_rule(data[i][j], neighbors)
return new_data

def lifegame(data, steps):


results = ita.array.make1d(steps + 1)
results[0] = data
current = data
for step in range(1, steps + 1):
current = lifegame_step(current)
results[step] = current
return results

def distance(x1, y1, x2, y2):


return ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5

def draw_circle(r, center_y, center_x, color, image):


for i in range(len(image)):
for j in range(len(image[0])):
if distance(i, j, center_y, center_x) < r:
image[i][j] = color

def random_lifegame_pattern(rows, cols):


return [[random.choice([0, 1]) for _ in range(cols)] for _ in
range(rows)]

if __name__ == "__main__":
data = random_lifegame_pattern(50, 50)
ani = lifegame(data, 30)
ita.plot.animation_show(ani)

3. Code Explanation

The provided code implements Conway's Game of Life, a cellular


automaton simulation. Here's an explanation of each part of the code:

i. Function “count_neighbor(data, i, j)”

This function counts the number of live neighbors (cells with value 1)
around a specific cell (i, j) in the 2D grid data.

Logic:
It iterates over the 8 possible neighbors using offsets di and dj in
the range [-1, 0, 1].

Skips the current cell (i, j) itself using if di == 0 and dj == 0:


continue.

Checks if the neighbor (ni, nj) is within bounds and counts it if it is


alive (data[ni][nj] == 1).

ii. Function “lifegame_rule(cur, neighbor)”

This function determines the next state of a cell based on its current state
(cur) and the number of live neighbors (neighbor).

Rules:

If the cell is alive (cur == 1):

It dies if it has fewer than 2 neighbors (underpopulation) or more


than 3 neighbors (overpopulation).

It survives if it has 2 or 3 neighbors.

If the cell is dead (cur == 0):

It becomes alive if it has exactly 3 neighbors (reproduction).

iii. Function “lifegame_step(data)”

This function computes the next generation of the grid data by applying
the rules to each cell.

Logic:
Creates a new grid “new_data” of the same size as data.

Iterates over each cell (i, j) in the grid.

Counts the number of neighbors using “count_neighbor”.

Determines the next state of the cell using “lifegame_rule”.

Updates the new grid with the computed state.

iv. Function “lifegame(data, steps)”

This function simulates the Game of Life for a given number of steps.

Logic:

Creates a 1D array results to store the grid states for each step.

Initializes the first state with the input grid data.

Iteratively computes the next state using “lifegame_step” and


stores it in results.

Returns the array of all grid states.

v. Function “distance(x1, y1, x2, y2)”

This helper function calculates the Euclidean distance between two


points (x1, y1) and (x2, y2).

vi. Function “draw_circle(r, center_y, center_x, color, image)”


This function draws a circle on a 2D grid image with a given radius r,
center (center_y, center_x), and color.

Logic:

Iterates over all cells in the grid.

Checks if the cell lies within the circle using the distance function.

Colors the cell if it is within the circle.

vii. Function “random_lifegame_pattern(rows, cols)”

This function generates a random initial grid of size rows x cols for the
Game of Life.

Logic:

Creates a 2D list where each cell is randomly assigned a value of 0


(dead) or 1 (alive).

viii. Main Execution

The if __name__ == "__main__": block runs the simulation and


visualizes it.

Steps:

Generates a random initial grid of size 50 x 50.

Simulates the Game of Life for 30 steps using lifegame.

Visualizes the simulation using ita.plot.animation_show.


Visualization

The ita library is used for visualization:

ita.array.make2d and ita.array.make1d are used to create 2D and 1D


arrays, respectively.

ita.plot.animation_show displays the animation of the Game of Life.

This code provides a complete implementation of the Game of Life,


including random initialization, simulation, and visualization.

4. Result

Clip: Group8.HW9.mp4

III. Overview Explanation


This report introduces a Python-based simulation of Conway's Game of Life,
where each cell on a 2D grid evolves based on its neighbors. The program
visualizes the simulation using the ita library and helps learners practice working
with 2D arrays, loops, functions, and basic simulation concepts. Key features
include random pattern generation, rule-based state updates, and animated
visualization across generations.

IV. Conclusion
Exercises designed to help learners gain a better understanding of the patterns and
rules of the Game of Life. These exercises also reinforce knowledge about
two-dimensional arrays, loops, and functions in Python. Additionally, they aid in
familiarizing users with the ita library for visualizing data through images and
animations. Additional development directions:

-​ Integrate the ability to automatically expand the grid size to accommodate


infinite simulations.
-​ Provide a user interface that allows users to interactively input initial
configurations using the mouse.
-​ Add the feature to save and load simulation states, enabling users to resume
from previously halted points.
-​ Develop options to adjust the simulation speed, allowing users to easily
follow the progression of different states.

V. Member Assessment

Name Student ID Progression Note


Đặng Thanh 23110329 Completed
Phong
Trần Thành Đạt 23110303 Completed
Dương Văn 23110328 Completed
Quang
Phạm Việt Hưng 23110173 Completed
Phạm Hồng Kiên 23110311 Completed

You might also like