Question
I need help modifing the snake pygame to make a function that satisfies the following artificial intelligence. please help if you can. % -----------------------------------ASSIGNMENT ----------------------------------%
I need help modifing the snake pygame to make a function that satisfies the following artificial intelligence. please help if you can.
% -----------------------------------ASSIGNMENT ----------------------------------% Download the python file "MiniSnake" in a file called "MiniSnake.py" It can be found at the link below. I would like the thank the author Daniel Westbrook (http://projects.pixelatedawesome.com/minisnake/ ). You will be extending that code as follows: Write an AI for snake. Main part (80% of code portions points): walls, but no obstacles (no blocks). Please follow a zig-zagging pattern (not a requirement), as most other algorithms will be challenging to implement correctly. Medium difficulty (10% of code portions points): Account for a single block, still using the zig-zagging algorithm. You're programming style will be graded as well. This regards naming conventions, comments, style, (10% of code portions points). Place all your code in a separate file called "ai_snake.py" in a function the meets the requirements discussed below. The instructor will handle the calling of your function during the grading of your project. The instructor will do so by replacing in MiniSnake.py the part of the original code that handles accepting keyboard input and changing the snake's direction variable with a call to your function (and importing your snake_ai.py module). Figure 1 Zig-zagging pattern for snake movement % ----------------------------- Code MANAGEMENT ----------------------- % We will be using Gitlabs through VT. You may log in at git.ece.vt.edu with you PID if you click the standard login option. Gitlabs, is basically a host for git repositories that function using git commands. I have been told that people have used git for other classes, but here is a link to some consise, easy to understand basics: http://rogerdudler.github.io/git-guide/
% ---------------------------- TEAMWORK ---------------------------- % You will work in teams of two. Tell me who you're partnered with before the end of March, or the instructor will match you. Please email the instructor if you anticipate or experience any issues regarding teamwork. You will write the following function: # Returns: a single movement direction: # either up, down, left or right (not a direction in which to turn) # Inputs: # snake_head: the Sprite at the beginning of the snake # snake_body_group: a Group of Sprites the represent the body # current_snake_direction: either 'up', 'down', 'left', or 'right' # SCREEN_SIZE: list of 2 values. The final x and y values of the screen # (i.e. the width and length, all > 0, note: the screen starts at [0, 0] # TILE_SIZE: the size of a single snake body part. # block_group: a Group of Sprites representing the obstacles auto_decide_snake_direction(snake_head, snake_body_group, current_snake_direction, SCREEN_SIZE, TILE_SIZE, block_group) The instructor will call you code just like that within the MiniSnake.py example. This means you technically dont need to know anything about how MiniSnake.py is written, but you will likely enjoy looking at the code for examples. % ------------------------ HOW YOUR CODE WILL BE TESTED ------------------------- % No blocks or food will share a border with the boundary of the screen. That is, the snake will always be able to move around the blocks to either side. During testing, neither the start position nor the size of the screen will be fixed. The most basic testing will be with short snakes. A snake with a length of two tiles is actually less work to code than a snake of length 1. Thus, the tests will be performed with a minimum snake length of two tiles. The instructor/TA will automatically run your code on a series of hand-picked cases (i.e. most* of which will have no randomness in block, food placement) for grading fairness reasons. Test difficulty will range from easy to hard in and points assigned in accordance with the rubric. Points will automatically be assigned for this portion of the grade. *One test will run your game for a long time and use randomness. Most likely, the average of the score over many attempts will be used as a metric to assign a grade. % ----------------------------------- REFERENCES ------------------------------------- % Checking for collisions with blocks and snake body - The bouncing ball homework. Storing information outside the function local scope (can be used in later calls to your function) - http://stackoverflow.com/questions/18034587/how-can-i-use-external-variables-in-python-like-extern-int-x-in-c
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started