diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2024-05-10 09:10:12 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2024-05-10 09:10:12 +0200 |
| commit | a660922d738b78b11fc78207daabea031058f710 (patch) | |
| tree | db46bd95bffeb330cea6066c77f2709f96c033aa /src/moves.h | |
| parent | 75966319fd5891c2c1bd35b1f7c93eab172fd28e (diff) | |
| download | nissy-core-a660922d738b78b11fc78207daabea031058f710.tar.gz nissy-core-a660922d738b78b11fc78207daabea031058f710.zip | |
Split into .h files
Diffstat (limited to '')
| -rw-r--r-- | src/moves.h | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/moves.h b/src/moves.h new file mode 100644 index 0000000..7da6405 --- /dev/null +++ b/src/moves.h | |||
| @@ -0,0 +1,47 @@ | |||
| 1 | _static_inline bool allowednextmove(uint8_t *, uint8_t); | ||
| 2 | _static_inline uint8_t inverse_trans(uint8_t); | ||
| 3 | _static_inline uint8_t movebase(uint8_t); | ||
| 4 | _static_inline uint8_t moveaxis(uint8_t); | ||
| 5 | |||
| 6 | _static bool | ||
| 7 | allowednextmove(uint8_t *moves, uint8_t n) | ||
| 8 | { | ||
| 9 | uint8_t base[3], axis[3]; | ||
| 10 | |||
| 11 | if (n < 2) | ||
| 12 | return true; | ||
| 13 | |||
| 14 | base[0] = movebase(moves[n-1]); | ||
| 15 | axis[0] = moveaxis(moves[n-1]); | ||
| 16 | base[1] = movebase(moves[n-2]); | ||
| 17 | axis[1] = moveaxis(moves[n-2]); | ||
| 18 | |||
| 19 | if (base[0] == base[1] || (axis[0] == axis[1] && base[0] < base[1])) | ||
| 20 | return false; | ||
| 21 | |||
| 22 | if (n == 2) | ||
| 23 | return true; | ||
| 24 | |||
| 25 | base[2] = movebase(moves[n-3]); | ||
| 26 | axis[2] = moveaxis(moves[n-3]); | ||
| 27 | |||
| 28 | return axis[1] != axis[2] || base[0] != base[2]; | ||
| 29 | } | ||
| 30 | |||
| 31 | _static_inline uint8_t | ||
| 32 | inverse_trans(uint8_t t) | ||
| 33 | { | ||
| 34 | return inverse_trans_table[t]; | ||
| 35 | } | ||
| 36 | |||
| 37 | _static_inline uint8_t | ||
| 38 | movebase(uint8_t move) | ||
| 39 | { | ||
| 40 | return move / 3; | ||
| 41 | } | ||
| 42 | |||
| 43 | _static_inline uint8_t | ||
| 44 | moveaxis(uint8_t move) | ||
| 45 | { | ||
| 46 | return move / 6; | ||
| 47 | } | ||
