Skip to content

Latest commit

 

History

History
87 lines (72 loc) · 3.04 KB

README.md

File metadata and controls

87 lines (72 loc) · 3.04 KB

The-Hungry-Snake 🐍

Control your snake and avoid collusion!

  • 🌴 This is the final project of Data Structure instructed by Prof. Ken-Yi Lee at National Taiwan University
  • 🥇 Our algorithm is rated 1st/41 teams
  • 🎥 Watch our final project demo competition here

Usage

  • Set up the environment for using SFML on your IDE
  • Add all the source files to your IDE (I use Xcode for building the project)
  • Define your controller in CustomController.h, and build the project

How to play

  • There are 3 challenges and 3 modes to choose from:
    • 3 challenges
      • Type A: No other snakes
      • Type B: Several other snakes, and they won't avoid collusion with you
      • Type C: Several other snakes, and they will avoid collusion with you
    • 3 modes
      • Mode 0: Use your keyboard up down left right to control your snake
      • Mode 1: Use the controller defined in CustomController.h and run the game with GUI
      • Mode 2: Run till the end without GUI and show the score

Rules

  • The game will end in a period by default
  • Every snake is allowed to collide with itself
  • Gameover if collide with walls or other snakes
  • Eat more dots to get scores

Folder structure

.
├── CMakeLists.txt
├── DSAP-Final
│   ├── DSAP-Final-Info.plist
│   └── Resources
│       └── arial.ttf
├── README.md
├── img
│   ├── TypeA.png
│   ├── TypeB.png
│   └── TypeC.png
└── src
    ├── Config.h
    ├── ConstantDirectionController.h
    ├── ConstantDirectionControllerA.h
    ├── ConstantDirectionControllerB.h
    ├── CustomController.h
    ├── DirectionType.h
    ├── GUI.cpp
    ├── GUI.h
    ├── Game.cpp
    ├── Game.h
    ├── ISnakeController.h
    ├── PlayerController.h
    ├── Position.cpp
    ├── Position.h
    ├── Snake.cpp
    ├── Snake.h
    ├── StraightForwardController.cpp
    ├── StraightForwardController.h
    └── main.cpp

4 directories, 26 files

Default algorithm introduction

  • We use the function getCollisionDistance() to determine whether we will collide soon(i.e. in danger)
  • If we are in danger, we use DesideTurnDirection() to decide whether we should turn left or right
  • We always turn to the direction that is farest from the obstacle in front of us
  • If we start to loop, decrease the turing radius of the snake

A little preview of the game

TypeA TypeB TypeB