Snake effect now uses a neural net with a hidden layer; a bug in _is_free() that lead to lots of snakes committing suicide was fixed; neural net weights are now given as binary representation of a float to prevent rounding errors.
This commit is contained in:
@ -8,6 +8,8 @@
|
||||
#define SNAKE_DIR_SOUTH 2
|
||||
#define SNAKE_DIR_WEST 3
|
||||
|
||||
#define SNAKE_DEBUG false
|
||||
|
||||
class SnakeEffect : public Effect {
|
||||
private:
|
||||
Coords _pos;
|
||||
@ -18,10 +20,22 @@ private:
|
||||
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 _round;
|
||||
|
||||
// Neural net config
|
||||
// These are actually float values. But in order to prevent rounding errors and stuff, they are provided
|
||||
// in form of the raw binary data of the IEE754 floating point numbers.
|
||||
// In _decide() there's code to memcpy()-convert them to a float.
|
||||
// Round 340, 223.4 points, length 39, 36% stopped, 64% died
|
||||
// const uint32_t _weights[36] = {0xbd8e626e, 0xbee2cd2c, 0x3e4d5cab, 0x3eceb8c3, 0xbed0a514, 0x3ec62438, 0x3e947ed4, 0xbe4b8bf2, 0xbf301113, 0xbf3f0a75, 0x3f1868f7, 0xbf0253ca, 0xbedca2f2, 0xbd547c6d, 0x3edd6a8a, 0xbd4b97b6, 0x3f64ec26, 0xbe5323c1, 0x3eccf87d, 0xbf2d4796, 0xbf62b6e8, 0xbf71daf6, 0xbf03f08e, 0xbf222609, 0x3e26c03c, 0xbf497837, 0xbee4d175, 0x3ec601de, 0x3e4e0695, 0x3eef2619, 0xbe849370, 0xbf18fb2b, 0x3f25bbd1, 0xbf3dcd78, 0x3f37a58d, 0x3ef4a25b};
|
||||
// Round 630, 221.0 points, length 38, 36% stopped, 64% died
|
||||
const uint32_t _weights[36] = {0xbd25943f, 0xbf279d81, 0x3e25d128, 0x3ec62438, 0x3f0e719c, 0x3eefbea9, 0x3e947ed4, 0xbe5323c1, 0xbf2d4796, 0xbf3f0a75, 0x3f0e45d9, 0xbf0253ca, 0xbedca2f2, 0xbd79073c, 0x3ede80ec, 0xbd4b97b6, 0x3f69a6be, 0xbe4b8bf2, 0x3eccf87d, 0xbf301113, 0xbf62b6e8, 0xbf71daf6, 0xbf204130, 0xbf222609, 0x3e26c03c, 0xbf497837, 0xbee4d175, 0x3ec601de, 0x3e4954eb, 0x3eef2619, 0xbe849370, 0xbf18fb2b, 0x3f25bbd1, 0xbf3b4e44, 0x3f484d59, 0x3edd6a8a};
|
||||
|
||||
const uint8_t _net_layout[3] = {6, 4, 3};
|
||||
const uint8_t _net_layers = 3;
|
||||
const uint8_t _net_total_size = 36;
|
||||
|
||||
|
||||
uint16_t _xy2i(uint8_t x, uint8_t y);
|
||||
uint16_t _xy2i(Coords c);
|
||||
Coords _i2xy(uint16_t i);
|
||||
|
Reference in New Issue
Block a user