美文网首页
讲解:Snake Battle、c++、C/C++C/C++|D

讲解:Snake Battle、c++、C/C++C/C++|D

作者: haoyuanjun | 来源:发表于2019-12-29 10:18 被阅读0次

Lab8 – Greedy Snake Battle Greedy snake is a well-known computer game. In this lab, you’ll try to write an AIprogram for a modified greedy-snake battle. Compete with each other and have fun!Figure 1. Classic Greedy Snake Game1. Basic rulesThe 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. Ateach tick, the snake goes one step forward in the direction he assigned before. Once asnake goes across border, or it crashes his or the opponents’ tail, he automatically losesand the opponent wins. If the head of the snake lays on the food, the snake body will beone 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 pertick, and limit the direction to be LEFT, RIGHT, UP or DOWN.Figure 2. Greedy Snake Battle FieldThe snakes 2. Interface and usageThe 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/Ospecifications and gaming requirements. The implementation of game_t should bewritten in a single file (lab8.cpp) and you should link the main.cpp and lab8.cpp to getyour final executable file (and it’s more recommended to write your own main.cpp to testyour implementations because your implementations should be valid with any validmain.cpp).The prototype of the game_t class is shown below:/* The class that you need to implement for the game, the functions maybe useful to you */class game_t {private: std::vector snakeSelf, snakeOpp; vector2D food; int round{}; bool first;public: /* EFFECTS: Initialize the game board * MODIFIES: this */ game_t(vector2D birthSelf, vector2D birthOpp, vector2D food, boolfirst); /* EFFECTS: Set the position of food * MOSnake Battle作业代做、c++编程语言作业调试、代写C/C++实验作业 帮做C/C++编程|代做DatabasDIFIES: 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 opponents 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 (snakeSelfand snakeOpp). The class also contains private member variables food, round and first (ifyou are the first to make action).You should realize all the functions listed in the prototype of the game_t class and youmay use these functions in your judge function as well.The related files could be downloaded in lab8-related-files.zip.3. How to uploadTo attend this lab and get some score, you need to submit the code at the OJ serverhttp://202.182.106.242. You should login with your student ID and the password youpreferred to use to log in the OJ, then you could submit your code and compete withother AIs in http://202.182.106.242/submission/submit. Note that when you upload thecodes, you only need to upload the contents in your lab8.cpp and we will automaticallylink other supporting files.Please test your codes before submitting. Any intentional or unintentional attack to theserver, including malicious modification to other files, allocating excessing memory arestrictly forbidden and will cause extremely heavy deduction. 转自:http://www.daixie0.com/contents/13/4495.html

相关文章

网友评论

      本文标题:讲解:Snake Battle、c++、C/C++C/C++|D

      本文链接:https://www.haomeiwen.com/subject/lphyoctx.html