[HDLbits] Conway‘s game of life
@HDLbits
Conway’s game of life
Question:
The “game” is played on a two-dimensional grid of cells, where each cell is either 1 (alive) or 0 (dead). At each time step, each cell changes state depending on how many neighbours it has:
0-1 neighbour: Cell becomes 0.
2 neighbours: Cell state does not change.
3 neighbours: Cell becomes 1.
4+ neighbours: Cell becomes 0.
The game is formulated for an infinite grid. In this circuit, we will use a 16x16 grid. To make things more interesting, we will use a 16x16 toroid, where the sides wrap around to the other side of the grid. For example, the corner cell (0,0) has 8 neighbours: (15,1), (15,0), (15,15), (0,1), (0,15), (1,1), (1,0), and (1,15). The 16x16 grid is represented by a length 256 vector, where each row of 16 cells is represented by a sub-vector: q[15:0] is row 0, q[31:16] is row 1, etc. (This tool accepts SystemVerilog, so you may use 2D vectors if you wish.)
load: Loads data into q at the next clock edge, for loading initial state.
q: The 16x16 current state of the game, updated every clock cycle.
The game state should advance by one timestep every clock cycle.
分析:该题主要是需要考虑边缘情况,看到有很多博主是将边缘情况全都表示出来,这样也不妨是一种做法。这里比较推荐在周围加一圈padding,将1616的网格扩充为1818的网格,扩充的内容即为边缘的neighbours,扩充完后便可直接用counter对neighbour进行计数,从而求解。
module top_module(input clk,input load,input [255:0] data,output [255:0] q ); reg [3:0] counter;reg [323:0] data_padding;reg [255:0] q_next;//change statealways @(posedge clk) beginif(load)q <= data;else q <= q_next;end//calculate q_nextalways @(*) begindata_padding[17:0] = {q[240],q[255:240],q[255]};data_padding[323:306] = {q[0],q[15:0],q[15]};for(int i=1;i<17;i++) begindata_padding[i*18 +:18] = {q[(i-1)*16],q[(i-1)*16 +: 16],q[i*16-1]};endfor(int i=1;i<17;i++) beginfor(int j=1;j<17;j++) begincounter = data_padding[18*i+j-1]+data_padding[18*i+j+1]+data_padding[18*(i-1)+j-1]+data_padding[18*(i-1)+j]+data_padding[18*(i-1)+j+1]+data_padding[18*(i+1)+j-1]+data_padding[18*(i+1)+j]+data_padding[18*(i+1)+j+1];case(counter)2: q_next[16*(i-1)+j-1] <= q[16*(i-1)+j-1];3: q_next[16*(i-1)+j-1] <= 1;default: q_next[16*(i-1)+j-1] <= 0;endcaseendendend
endmodule
[HDLbits] Conway‘s game of life相关推荐
- 用Verilog实现Conway‘s Game of Life 16x16(HDLbits的Conwaylife题)
Title:Conwaylife Conway's Game of Life is a two-dimensional cellular automaton. The "game" ...
- HDLBITS笔记30:rule 90、rule 100以及Conway‘s game of life 16*16
目录 ## 题目1:rule 90规则90是具有有趣属性的一维元胞自动机. 题目2:rule 100 题目3:Conwaylife ## 题目1:rule 90 规则90是具有有趣属性的一维元胞自动机 ...
- verilog练习:hdlbits网站上的做题笔记(5)
前言 之前的文章<如何学习verilog,如何快速入门?>中提到了verilog学习,推荐了一个可以练习的网站:hdlbits网站,那自己也玩玩这个网站. 这篇文章,是接着<veri ...
- 一代数学大家--John Conway逝世,丘成桐、陶哲轩纷纷发文缅怀!
关注上方"深度学习技术前沿",选择"星标公众号", 资源干货,第一时间送达! 天才之间,总是惺惺相惜.当代最有趣的数学家 John Horton Conway, ...
- HDLBits 系列(0)专题目录
本篇博文是近来总结HDLBits系列的目录,点击蓝色字体即可进入查看具体内容. HDLBits 系列(1)从HDLBits中获取灵感,整顿自己,稳步前行 HDLBits 系列(2)如何避免生成锁存器? ...
- HDLBits 系列(40)如何写 TestBench 文件?
目录 序言 变量定义 时钟设计 设计输入 模块例化 实战演练 序言 由于入门的测试文件很简单,所以一直以来也都是直接给出测试文件,直到今天才想着去总结一个测试文件的写法.这篇博客将根据HDLBits的 ...
- HDLBits 系列(31)Serial Receiver and Datapath
目录 序言 原题复现 我的设计 序言 上篇博文: HDLBits 系列(30)Serial Receiver 写了串行接收器如何接收8位串行数据,正确接收8位串行数据后给一个接收完毕标志信号,这篇博文 ...
- HDLBits 系列(29)PS/2 mouse protocol(PS/2 packet parser and datapath)
目录 序言 原题传送 题目解释 我的设计 序言 上篇博客: HDLBits 系列(28)PS/2 mouse protocol(PS/2 packet parser) 只对PS/2 mouse pro ...
- HDLBits 系列(17) 计数器的级联实现1000分频的分频器
目录 原题复现 审题 我的设计 原题复现 原题 From a 1000 Hz clock, derive a 1 Hz signal, called OneHertz, that could be u ...
最新文章
- tensorflow教程 开始——Premade Estimators(预制评估器)
- 删除rabbitmq的队列和队列中的数据
- android 4.2 noclassdeffounderror,NoClassDefFoundError:android.support.v7.internal
- java 虚拟打印机_打印作业提交给打印机,使用虚拟打印机但不是真正的打印机 . Java的...
- sql数据库的链接方式
- 圈圈教你玩usb第一版件软件使用说明
- 三层交换机LACP协议对 L2/L3端口,报文处理实验
- java 上传图片 并压缩图片大小
- 计算机图形学原理与实践 答案,知到高级计算机图形学原理与实践单元测试答案...
- 阿尔伯塔大学计算机科学的申请条件,阿尔伯塔大学计算机科学硕士专业
- java导出excel表格设置行高_EasyExcel之不使用对象灵活生成Excel,并且调整行高、自动列宽与自由合并...
- E1: 在idea中执行flink程序时报错 No ExecutorFactory found to execute the application.
- 如何利用工具低成本构建华为云灾备方案?
- IO密集型和CPU密集型
- 卷妹带你学数据库---5天冲刺Day5
- NOIP2022游记
- 第十五章 软件工程新技术
- web漏洞扫描器原理_漏洞扫描技巧篇 「Web 漏洞扫描器」
- 配置eyeOS系统--1--虚拟机下安装CentOS6系统
- 易语言大漠插件模块制作后台找字FindStrFast
热门文章
- 深度linux live,LinuxDeepin/用LinuxLive USB Creator安装LinuxDeepin
- 利用streamline函数绘制电力线
- IOS 判断设备屏幕尺寸、分辨率 根据屏幕尺寸和分辨率
- n维单位正交向量和他的转秩α*α^T性质
- 单容水箱液位pid控制实验报告_单容水箱液位过程控制实验报告
- 如今的微信时代,这份微信公众号代运营方案值得你去看一下
- 安装HeidiSQL
- 目前市场上主流PDM软件是什么?
- 计算机CCT考试模拟操作题,基础计算机cct考试模拟题
- 计算机硬件及组成原理中文版,计算机硬件及组成原理.docx