Download code/validation/C++/0030591_Snake.cpp from Variable-role/sajaniemi_variable_dataset_large: direct link, hf CLI and curl.
- Browser
- Download file 1.43 kB
-
https://huggingface.co/datasets/Variable-role/sajaniemi_variable_dataset_large/resolve/main/code/validation/C%2B%2B/0030591_Snake.cpp
- Command line
-
hf download hf://datasets/Variable-role/sajaniemi_variable_dataset_large/code/validation/C++/0030591_Snake.cpp
-
curl -L -o 0030591_Snake.cpp https://huggingface.co/datasets/Variable-role/sajaniemi_variable_dataset_large/resolve/main/code/validation/C%2B%2B/0030591_Snake.cpp
1.43 kB
| /* | |
| Created for Milestone 2 | |
| Group 12 | |
| Jonathan Mayer 66268081 | |
| Brian Lam 62101239 | |
| Yu Koizumi 000975171 | |
| Tommy Wong 71659011 | |
| */ | |
| Snake::Snake(Coord starting_pos, Board* board) | |
| { | |
| Node* n = new Node{nullptr, starting_pos}; | |
| head = n; | |
| tail = n; | |
| length = 1; | |
| direction = RIGHT; | |
| this->board = board; | |
| } | |
| Snake::~Snake() | |
| { | |
| Node* current = tail; | |
| Node* del = current; | |
| while(current != nullptr) | |
| { | |
| del = current; | |
| current = current->next; | |
| delete del; | |
| } | |
| } | |
| void Snake::update() | |
| { | |
| head->next = new Node{nullptr, head->value + direction}; | |
| head = head->next; | |
| int x = head->value.x; | |
| int y = head->value.y; | |
| if(x >= 0 &&y >= 0 && x < board->getLength() && y < board->getWidth()) | |
| { | |
| if(board->getItem(x, y) == food) // Check for food | |
| { | |
| length++; | |
| board->setItem(x, y, empty); | |
| board->addItem(food); | |
| return; | |
| } | |
| } | |
| Node* temp = tail; | |
| tail = tail->next; | |
| oldTail = temp->value; | |
| delete temp; | |
| } | |
| void Snake::changeDirection(Coord direction) | |
| { | |
| if(direction != -this->direction || length == 1) | |
| this->direction = direction; | |
| } | |
| Coord Snake::getHead() | |
| { | |
| return head->value; | |
| } | |
| Coord Snake::getOldTail() | |
| { | |
| return oldTail; | |
| } | |
| int Snake::getLength() | |
| { | |
| return length; | |
| } | |
| std::vector<Coord> Snake::getSnakePosition() | |
| { | |
| std::vector<Coord> snakeCoords{}; | |
| Node* current = tail; | |
| while(current != nullptr) | |
| { | |
| snakeCoords.push_back(current->value); | |
| current = current->next; | |
| } | |
| return snakeCoords; | |
| } |