46 lines
1.8 KiB
C++
46 lines
1.8 KiB
C++
#pragma once
|
|
|
|
#include "Effect.h"
|
|
#include "prototypes.h"
|
|
|
|
#define SNAKE_DIR_NORTH 0
|
|
#define SNAKE_DIR_EAST 1
|
|
#define SNAKE_DIR_SOUTH 2
|
|
#define SNAKE_DIR_WEST 3
|
|
|
|
class SnakeEffect : public Effect {
|
|
private:
|
|
Coords _pos;
|
|
Coords _apple;
|
|
int8_t _dir = SNAKE_DIR_NORTH;
|
|
uint8_t* _map;
|
|
uint16_t _pixels;
|
|
uint8_t _length;
|
|
unsigned long _last_apple_at;
|
|
unsigned long _last_move_at;
|
|
// 204.6 points, length 35, 58% stopped, 42% dead
|
|
// float _weights[18] = {0.8613356309729567, 0.1010670216231977, -0.03801953620401166, 0.7556556498067926, -0.9925124063206012, 0.6375227768823608, 0.7216340201735381, 0.5557451907997892, 0.03496949604344035, 0.7238725631217913, 0.9070987343528141, 0.6518810721526125, -0.17322587217593544, -0.7726195238221361, 0.8044226332955624, 0.8434782354002677, 0.8508760698750302, 0.47735675603010397};
|
|
// Round 2077: 208.6 points, length 36, 50% stopped, 50% dead
|
|
float _weights[18] = {-0.1648448727142625, -0.7505284618312464, 0.0037384390323656203, -0.6678743938665241, 0.917231716139375, 0.05960885292612439, -0.7585782758281971, 0.8275111343144115, 0.7821852602229209, 0.29970244548911523, 0.9737979047604144, -0.2384723067003974, -0.7854491847031548, 0.44652781127984964, 0.9127919336231882, 0.3309096816699824, -0.9071832356948208, -0.23802066581485848};
|
|
uint16_t _xy2i(uint8_t x, uint8_t y);
|
|
uint16_t _xy2i(Coords c);
|
|
Coords _i2xy(uint16_t i);
|
|
Coords _new_pos(uint8_t dir);
|
|
uint8_t _dying = 0;
|
|
bool _is_free(uint8_t dir);
|
|
uint8_t _free_spaces(uint8_t dir);
|
|
uint8_t _to_apple(uint8_t dir);
|
|
void _place_apple();
|
|
void _init();
|
|
void _decide();
|
|
int8_t _manual_decision();
|
|
void _move();
|
|
void _draw();
|
|
public:
|
|
SnakeEffect();
|
|
~SnakeEffect();
|
|
void loop(uint16_t ms);
|
|
boolean can_be_shown_with_clock();
|
|
String get_name() override { return "snake"; }
|
|
};
|