码迷,mamicode.com
首页 > 其他好文 > 详细

Lab8 Greedy Snake Battle

时间:2019-12-19 13:17:42      阅读:94      评论:0      收藏:0      [点我收藏+]

标签:nal   com   stl   speed   forward   hat   tick   some   rem   


Lab8 – Greedy Snake Battle
Greedy snake is a well-known computer game. In this lab, you’ll try to write an AI
program for a modified greedy-snake battle. Compete with each other and have fun!
Figure 1. Classic Greedy Snake Game
1. Basic rules
The modified greedy-snake game will let two snakes to fight against each other in a 50-
by-50 field. The goal of a player is to kill the other’s snake and keep his snake alive. At
each tick, the snake goes one step forward in the direction he assigned before. Once a
snake goes across border, or it crashes his or the opponents’ tail, he automatically loses
and the opponent wins. If the head of the snake lays on the food, the snake body will be
one pixel longer. If the battle didn’t end within 500 ticks, the snake with longer body wins.
To enable the battle of two AIs, we limit the operating speed of a play is one action per
tick, and limit the direction to be LEFT, RIGHT, UP or DOWN.
Figure 2. Greedy Snake Battle Field
The snakes
2. Interface and usage
The lab will support a basic interface, including the class you need to implement (game_t),
a bug-free 2D vector class (vector2D) and the file main.cpp containing all the I/O
specifications and gaming requirements. The implementation of game_t should be
written in a single file (lab8.cpp) and you should link the main.cpp and lab8.cpp to get
your final executable file (and it’s more recommended to write your own main.cpp to test
your implementations because your implementations should be valid with any valid
main.cpp).
The prototype of the game_t class is shown below:
/* The class that you need to implement for the game, the functions may
be useful to you
*/
class game_t {
private:
std::vector<vector2D> snakeSelf, snakeOpp;
vector2D food;
int round{};
bool first;
public:
/* EFFECTS: Initialize the game board
* MODIFIES: this
*/
game_t(vector2D birthSelf, vector2D birthOpp, vector2D food, bool
first);
/* EFFECTS: Set the position of food
* MODIFIES: this->food
*/
void setFood(vector2D food);
/* EFFECTS: Get the position of food
*/
vector2D getFood() const;
/* EFFECTS: Make a move with corresponding direction
* MODIFIES: this->snakeSelf, this->food, this->round
* RETURNS: 0 - Game continues
1 - You win
2 - Opponent win
*/
int selfMove(direction_t dir);
/* EFFECTS: Update the opponent‘s position
* MODIFIES: this->snakeOpp, this->food, this->round
* RETURNS: 0 - Game continues
1 - You win
2 - Opponent win
*/
int oppMove(direction_t dir);
/* EFFECTS: Tell if the move is invalid *Only to snakeSelf
*/
bool moveValid(direction_t dir);
/* EFFECTS: Tell if the move will cause boundary cross
*/
bool moveCross(direction_t dir);
/* EFFECTS: Determine the best direction to go at the current situation
*/
direction_t judge();
};
In the game_t class, the snakes are represented by two STL vectors of vector2D (snakeSelf
and snakeOpp). The class also contains private member variables food, round and first (if
you are the first to make action).
You should realize all the functions listed in the prototype of the game_t class and you
may use these functions in your judge function as well.
The related files could be downloaded in lab8-related-files.zip.
3. How to upload
To attend this lab and get some score, you need to submit the code at the OJ server
Snake Battle作业代做
http://202.182.106.242. You should login with your student ID and the password you
preferred to use to log in the OJ, then you could submit your code and compete with
other AIs in http://202.182.106.242/submission/submit. Note that when you upload the
codes, you only need to upload the contents in your lab8.cpp and we will automatically
link other supporting files.
Please test your codes before submitting. Any intentional or unintentional attack to the
server, including malicious modification to other files, allocating excessing memory are
strictly forbidden and will cause extremely heavy deduction.

因为专业,所以值得信赖。如有需要,请加QQ99515681  微信:codehelp

Lab8 Greedy Snake Battle

标签:nal   com   stl   speed   forward   hat   tick   some   rem   

原文地址:https://www.cnblogs.com/bizhunjava/p/12066071.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!