https://github.com/elmisback/mips-snakes
A MIPS implementation of the old arcade game.
https://github.com/elmisback/mips-snakes
Last synced: 8 months ago
JSON representation
A MIPS implementation of the old arcade game.
- Host: GitHub
- URL: https://github.com/elmisback/mips-snakes
- Owner: elmisback
- License: gpl-2.0
- Created: 2014-10-12T22:25:08.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2016-10-23T13:55:57.000Z (over 9 years ago)
- Last Synced: 2025-10-09T02:48:46.305Z (8 months ago)
- Language: Assembly
- Homepage:
- Size: 18.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
#mips-snakes
A MIPS implementation of Snakes! for Dr. Youtao Zhang's CS 447 at the
University of Pittsburgh.
## The Algorithm
I used a standard animation algorithm for moving the game's eponymous snake.
In pseudocode, it looks like this:
t = sys.time()
while True:
sleep(SMALL_INTERVAL)
if key_pressed(): # set new direction here;
# true if the direction has changed, else false
move_snake()
t = sys.time()
elif sys.time() - t > 200ms:
move_snake()
The move\_snake() function was also fairly simple. Before making a move, it
calls a validation function to check what's in the move destination. If the
destination is empty, the snake's tail segment is deleted and the destination
is added as the new head segment. If the destination is part of the snake, the
game is over. If the destination is a frog, the snake "consumes" the frog (the
tail is not deleted and the head advances). If the destination is a wall, the
validation function returns a value to indicate that the snake is tentatively
stuck. The move function responds to a stuck position by trying to turn left or
right (in a randomized order). If neither turn works, the snake is officially
stuck and the game ends.
As suggested in the assignment's writeup, I used a circular buffer to implement
a queue for tracking the snake's position. The snake's head corresponds to the
back of the queue, where elements are added; its tail corresponds to the front
of the queue, where elements are dequeued.
## Extra Credit
Note the splash screen's decadent grandeur.