Download as pdf or txt
Download as pdf or txt
You are on page 1of 13

SNAKE GAME M Rajashekar Reddy 09007044 K Vineel Pratap 09007045 T Chakradhar 09007046

INTRODUCTION Snake game originated around 1970s and has become a classic game in almost all mobile phones. The player controls a long, thin creature, resembling a snake, which roams around on a bordered plane, picking up food (or some other item), trying to avoid hitting its own tail or the "walls" that surround the playing area. Each time the snake eats a piece of food, its tail grows longer, making the game increasingly difficult. The user controls the direction of the snake's head (up, down, left, or right), and the snake's body follows. The player cannot stop the snake from moving while the game is in progress, and cannot make the snake go in reverse. However, Snake has had many variations since its release, depending on the game's platform. These variations involve the modification of certain rules e.g. the lethality of contact with walls. PROJECT In our project the output display of the game is an array of LEDs (mostly 8x8), the input consists of 4 switches, and the processing consists of logic gates, multiplexers, 8bit adders, 8bit registers, and a static ram (8 bit). The main components of the system are as follows

THE INTERNAL PROCESS

HEAD REGISTER

The contents of each register are as follows

TAIL REGISTER DIRECTION BITS(2) X CO-ORDINATE(3 bits) Y CO-ORDINATE(3 bits)

CORNER REGISTER

ADDRESS REGISTER

The address register stores the address of the last but one corner

MEMORY
STATIC RAM 8 bit input/output THE COMPONENTS OF THE DISPLAY PROCESSES

SNAKE GAME M Rajashekar Reddy 09007044 K Vineel Pratap 09007045 T Chakradhar 09007046 We need 64 LEDs 8x8bit register for the main display; ROW 7

ROW 6

ROW 5

ROW 4 8x8 led display ROW 3

ROW 2

ROW 1

ROW 0

SNAKE GAME M Rajashekar Reddy 09007044 K Vineel Pratap 09007045 T Chakradhar 09007046

The display as we have seen above consists of eight register which are updated once every speed cycle which is the speed at which the display is flashed. The out most important display process is the updating of head and tail from the contents of head and tail register. This is the display process 1.

DISPLAY PROCESS 1
Is the led already glowing? YES NO flag is already set
ADD the decoded value to the appropriate display register

NO GAME OVER

Decode the Head register for manipulation

Is itNO equal to food?

if yes the food

Above process is the main display process the decoding block decodes the y co-ordinate and a multiplexer selects the row corresponding to the y co-ordinate. And the 3 bit x co-ordinate is decoded to 8 bit with only one bit active and it is checked if it is already glowing, if not then it is added to the contents of the register already existing hence incrementing the head if it doesnt hit any of its body part. Decode the tail register for manipulation ADD the decoded value to appropriate display register

Similarly we see that the above tail manipulation is similar but without any if conditions the main hardware for the both manipulations is same hence we could do serial processing for both of them if we have the global clock cycle speed high enough.

SNAKE GAME M Rajashekar Reddy 09007044 K Vineel Pratap 09007045 T Chakradhar 09007046

X co-ordinate

Y co-ordinate

3->8 binary to decimal decoder

C O N T R O L

D A T A B U S

3->8 binary to decimal decoder

B U S

Display registers

8 bit adder

SNAKE GAME M Rajashekar Reddy 09007044 K Vineel Pratap 09007045 T Chakradhar 09007046

THE MAIN EGG PROCESS; There is a register that is set for flags; if the bit corresponding to egg is 1, it means that the egg has been consumed in the process and new one must be generated.

If egg flag is set

Generate a random 6 bit number

Is that coordinate already set?

Decode the random number and add it to display To generate the random number we use a random noise generator coupled with Schmidt trigger, or we have thought of using a pseudo random generator using the number of times snake has turned during the last struggle for egg, either way the flow chart of the generation process is above Egg flag enable DECODER c

EGG shift REGISTER

Random 8 bit generator

DISPLAY REGISTERS

SNAKE GAME M Rajashekar Reddy 09007044 K Vineel Pratap 09007045 T Chakradhar 09007046

The hardware of the random number generator is as follows The PN junction of Q1 is reverse biased to produce avalanche noise. The resultant signal is amplified for the purpose of driving a TTL-level Schmitt trigger to produce a square wave; a series of rising and falling edges with unpredictable time intervals between edges.

COUTESY of random generator: Aaron louge (cryogineous.com). The output random signal is sampled every once in the clock cycle hence it takes about 8 clock cycles to reload the egg register. We check from the display registers if the egg co-ordinate generated is already occupied by the body of the snake. If not we have completed the process of egg generation, else we again repeat the process. Again for the checking in the display we need the decoding part we had above and check it by using a xnor bit wise if the answer if no , again generate the random number and again continue the process. If the egg co-ordinate is correct

ADDITIONAL CORNER PROCESS NEW corner load the head register into memory from address from register

Is the direction from the input different from that of previous head?

SNAKE GAME M Rajashekar Reddy 09007044 K Vineel Pratap 09007045 T Chakradhar 09007046 INTERNAL PROCESSES Gameover process1 ONE of the important processes in game is striking an egg or striking an edge one of which only happens at a time the flow diagram for the process is show below. Since the updating of display takes place after all the internal processes are over, the game over flag should be set immediately after the head size exceeds. Now if the head coordinates equal that of the egg the snake is elongated backwards i.e., we would see that the egg and head have merged and the tail hasnt moved.so only the head process should happen and the tail process doesnt. This process must run always after the head register is updated from the input. And only after this should the tail process be done

he tail processes

NO Does any one of the HEAD co-ordinate exceed the array size? i.e., is the carry flag set?

GAME OVER
yes i.e. set the game over flag

does the HEAD coordinates match with that of egg

NO

YES

ONT do tail process nd raise the egg flag

We have to check if the co-ordinates of the head after increment match with that of the egg, if that happens we do not need to perform the tail process as the body of the snake grows by 1.

SNAKE GAME M Rajashekar Reddy 09007044 K Vineel Pratap 09007045 T Chakradhar 09007046

The main head process

INPUT: From four switches the input is taken at the time of starting of the global time cycle

Is the direction from the input equal to reverse of the previous

YES

Make no change in the direction of the head register change to the

NO

HEAD PROCESS

The change the direction of the head register

INCREMENT: Change the head register according to the direction of the head

First the input is taken from the four push buttons. This is the beginning of the entire internal processes. The input from four switches is encoded into two bits and are checked and updated according to the initial direction of the movement of head. The construction of push buttons, encoders are as follows B0=A1+A4; A1 A4 A2 4bits: A 1-4 B1=A1+A2; This encoder encodes 1000-11(up) 0100-01(right) A3 0010-00(down) 0001-10(left) 2 bits B0, B1

After the input is decoded it is checked to see if it is valid .i.e., the direction of head must not be opposite to that of present one. The directions are encoded in such a way that the dot product of the exactly opposite directions I zero so if we check that first two bits and the bits B0, B1 are dot producted zero retain the original else increment in the

SNAKE GAME M Rajashekar Reddy 09007044 K Vineel Pratap 09007045 T Chakradhar 09007046 direction of the input direction. The process for this is given above in the data flow diagram. The hardware is as follows

D1 ADD/SUB H7, H6 Multiplexer 2x2 bit Selects a pair of bits B0, B1 6b001000 Multiplexer 6x6

INPUT1

D0, D1 Valid direction 6b000001

INPUT2 OUTPUT 2 bit D0,D1 H7-H6 H5-H0 (6 bit) 6 bit D0 CARRY

HEAD REGISTER 8 BIT


8 bit updated Head co-ordinate

CARRY FLAG IS SET ONLY IF ADDITION OVER FLOWS OR H7 B0 H6 B1 SUBSTRACTION UNDERFLOWS

The process first part selects the correct direction bit depending upon the previous direction of head and the resulting direction is used to update the register. The directions are coded such that if the last bit is one, we should

SNAKE GAME M Rajashekar Reddy 09007044 K Vineel Pratap 09007045 T Chakradhar 09007046 add to the co-ordinate else subtract from the co-ordinate. And if the first bit is 0 we should select the x-coordinate else its counterpart. THE WORKING OF ADD/SUB; We need a 6 bit adder for the working of the above unit. First if the input at ADD/SUB is one we should add it directly else take its twos complement and add if the carry is set to one then we should give the output carry ADD/SUB will be

2s complement

6 bit adder

6x6 multiplexer

We can also do this directly by using a 4 select multiplexer in the main stage using the 2s complements directly in addition using the twos complements of 6b001000 and 6b000001 i.e.,6b111000 and 6b111111. i.e., we do it directly by the following blocks

6b111111 6b111000 6b001000 6b000001

00 10 01 11 ADDER

Carry output OUTPUT

SNAKE GAME M Rajashekar Reddy 09007044 K Vineel Pratap 09007045 T Chakradhar 09007046

The main tail process

xor

ate the TAIL register with the tents of previous corner and d the previous corner from mory with address in a register

YES

Check if the tail reached the previous corner

N O

TAIL PROCESS
Decrement the TAIL register according to the directions from its top 2 bits The tail processes is very much similar to that of the head processes but very much less complicated the main block diagram is as above. Since we have both the tail and its immediate next corner in available registers the isnt much complexity in this process all we have to do is compare the both registers bit by bit for exact match in the least 6 bits. If there is an exact match it means that the tail reached its corner hence we shift the contents of corner register to tail and load the corner register with the address from the address register into the corner register which has the co-ordinates of the next corner to the previous one. The following is the hardware implementation of the above logic

TAIL REGISTER

BIT WISE XNOR

AND OF ALL 8 bits

CORNER REGISTER

SNAKE GAME M Rajashekar Reddy 09007044 K Vineel Pratap 09007045 T Chakradhar 09007046 Output1

ADDRESS REGISTER

Read 2 MEMORY STATIC RAM 8 bit input/output data

Read 1

write 2

CORNER REGISTER

Write 1

TAIL REGISTER

ALL the above happens only if the output one is equal to 1; Hence we have to manage the control bus which accesses all the above such that all the above happen according to same sequence and timing there must be at least 2 or 3 clk cycles to manage this transition. If there are 5 bits to control this unit above one bit corresponding to write of each register and one is corresponding to read/write and chip enable of static ram. They must change in a specific sequence when the output1 goes high. This sequence can be stored in memory also, or they can be synthesized using logic. Such as a fsm which rotates few finite states when first triggered. We will discuss this in control unit. One part of the tail process is over the next part is the increment and decrement process that happened in the main head process. So we need not consider the whole process here only block diagram is being considered. Due to inherent problem with the tail manipulation in display the tail register always is one step behind the actual tail hence when we update the tail register according to the direction of the tail we have the co-ordinate of the tail where it was before hence when we subtract it from the row we have the actual snake on the display. Hence the difference b/w registers is always one greater than the length of the snake. Initially the control is in read mode to facilitate the manipulation of data. And after the manipulations the ctrl goes to write mode to save the updated data.

SNAKE GAME M Rajashekar Reddy 09007044 K Vineel Pratap 09007045 T Chakradhar 09007046

6b111111 6b111000 6b001000 6b000001 ctrl

00 10 01 11 ADDER

Direction bits TAIL REGISTER OUTPUT Co-ordinate bits(6)

You might also like