# HW 4: Snake ** Due Oct 25, 2018 ** Preliminary Design Report (one PDF) including * drawing of the top level (hand drawing is ok) * module descriptions including IO descriptions and outline of functional specifications * your outline should also include a test plan ** Due Oct 29, 2018 ** Final Project and Report You must include sufficient testbenches and the results of running them in your PDF report. Your report should explicitly discuss any changes from your Preliminary Design. You are going to create a snake game much like this one: https://www.coolmath-games.com/0-snake 1 ** Game description ** ![game diagram](./game_diagram.svg) The game should conform to the following specifications: * The game play area is set up as a 26-by-38 grid surrounded by an electric fence (blue). The game display should occupy the majority of the screen, don't make a game field that is 26-by-38 pixels on the monitor. Decide an appropriate size in pixels for each grid cell. * To start the game, press BTNC (reset). Upon release, a single grid point represents a snake (cyan) and a single grid point represents food (red). * The snake starts by moving to the right one grid point roughly every 1/8th of a second (125 ms update interval, need not be exact). * A player may change the direction of the movement by 90 degree clockwise or counterclockwise by using the East (BTNR) and West (BTNL) buttons respectively. Each button press should correspond to a 90 degree angle change. * If the snake goes onto the fence, the game should freeze. * If the snake goes onto the food, the length of the snake should increase by one grid segment on the next movement with a trailing body, per the behavior of the game shown in the provided link. The moving head should be cyan (green+blue), and the grown body segments should be green. * Each time the snake reaches the food, another food should be positioned in a manor seemly random to the user. * Each subsequent time the snake eats food, the segment length should grow by one, up to a length of 32 (including the head). * If the head of the snake overlaps a body segment then the game should freeze. * If the length of the snake reaches 32, the game should instead increase in speed by reducing the update interval by roughly 10 ms.. * Display details: If the food (red) overlaps any snake segment (green/cyan), the food should be shown. If the snake head overlaps the fence, the snake head should be shown. 2 ** Design Approach ** The design approach and structure is up to you. Here is one modular approach that breaks up the design into many small pieces. I don't represent that this is the best or easiest. It just seemed like the easiest one to describe. More complex behavioral units would allow for different segmenting of the design. * Graphics modules: * Use the module from HW1 to drive the VGA monitor. Remember that it directly drives the "sync" signals to the VGA monitor, but sends the present draw coordinates to your module so that the appropriate color is output to the monitor at a given point in time. However, this game is represented on a 26-by-38 grid, so you need to change the request ... * Create a module to convert the color request from "Present Color for pixel X,Y" to "Present Color for Gird U,V". U,V can now be passed to another module that outputs color for the present Grid. * You might create a "display" module that would accept the food position and all snake and body segment positions and any other necessary data in order to represent them on the grid. When presented with U,V it outputs the appropriate color data. Pay attention to the "display details" in the specifications * Food module: this module would internally choose a pseudo-random position and provide it as an output. It would also accept the snake head position as an input and output a signal if an overlap occurs. Upon overlap, a new position should be chosen. * Snake module: this should track and update the head position and the body segments. It should accept an input that indicates to grow and four inputs to signal a move (up, down, left, right). It should output all head and body segment positions. * End game collision: this should accept all snake and body segment positions and detect a game-stopping collision of the head with a fence or the body. * "Pacemaker": periodically sends a one-clock-cycle "update" signal to other modules. (All modules should be driven by one system clock). The update interval should be stored internally and reduced on-demand based on control signals from other modules. * other pieces as need... 3 ** What to be sure to turn in ** * Your initial report should be sumitted in the report directory in the git repo * Submit your source files with a working TCL file to compile your project. One is provided in the repo once you clone it. (CODE COMMENTING IS GRADED) * Create and include multiple Verilog testbench modules that test your design, more points are given for thoroughness of testing of individual modules and the game as a whole. Testbench modules may be placed in the src folder. * Create a report that briefly explains your design and your testing. Again, you must have one testbench for each module. * Include the output of your Verilog testbench(s) in your report in a professional presentation (THIS IS EXPLICITLY GRADED) with additional explanation about each testbench as needed to convince someone that each part of your design works and your simulation-based testing of each module is sufficient. 4 ** Bonus ** For bonus points, implement the following features. Do not do these independently of each other; you may only turn in one implementation of the game. You MUST document that you have implemented these so that the grader will know to check for them. Full credit is based on graders' judgments of your design an implementation. * up to +5 points: implement the apple update such that it does not appear at an active body segment location when spawned. * up to +5 points: implement a portal pairs along the fence: holes in the fence that transport the snake such that it emerges from another portal location along the fence. Late Policy: One or Two day late: 20/100 points off Provided Files * https://eclipse.umbc.edu/robucci/cmpe415/attachments/pulser.v , * https://eclipse.umbc.edu/robucci/cmpe415/attachments/random2.v