11#include "../flipchess.h"
22#include <furi.h>
3- #include <furi_hal.h>
4- #include <furi_hal_random.h>
3+ // #include <furi_hal.h>
4+ // #include <furi_hal_random.h>
55#include <input/input.h>
66#include <gui/elements.h>
77//#include <dolphin/dolphin.h>
1616
1717#include "../chess/smallchesslib.h"
1818
19- #define MAX_TEXT_LEN 30 // 30 = max length of text
19+ #define ENABLE_960 0 // setting to 1 enables 960 chess
20+ #define MAX_TEXT_LEN 15 // 15 = max length of text
2021#define MAX_TEXT_BUF (MAX_TEXT_LEN + 1) // max length of text + null terminator
2122
2223struct FlipChessScene1 {
@@ -28,25 +29,22 @@ typedef struct {
2829 uint8_t paramPlayerW ;
2930 uint8_t paramPlayerB ;
3031
31- // uint8_t paramBoard = 1;
3232 uint8_t paramAnalyze ; // depth of analysis
3333 uint8_t paramMoves ;
34- //uint8_t paramXboard = 0;
3534 uint8_t paramInfo ;
36- //uint8_t paramDraw = 1;
3735 uint8_t paramFlipBoard ;
38- //uint8_t paramHelp = 0;
3936 uint8_t paramExit ;
4037 uint16_t paramStep ;
4138 char * paramFEN ;
4239 char * paramPGN ;
43- //uint16_t paramRandom = 0;
44- //uint8_t paramBlind = 0;
4540
4641 int clockSeconds ;
4742 SCL_Game game ;
4843 SCL_Board startState ;
44+
45+ #if ENABLE_960
4946 int16_t random960PosNumber ;
47+ #endif
5048
5149 //uint8_t picture[SCL_BOARD_PICTURE_WIDTH * SCL_BOARD_PICTURE_WIDTH];
5250 uint8_t squareSelected ;
@@ -55,9 +53,9 @@ typedef struct {
5553 char * msg ;
5654 char * msg2 ;
5755 char * msg3 ;
58- char moveString [16 ];
59- char moveString2 [16 ];
60- char moveString3 [16 ];
56+ char moveString [MAX_TEXT_BUF ];
57+ char moveString2 [MAX_TEXT_BUF ];
58+ char moveString3 [MAX_TEXT_BUF ];
6159
6260 SCL_SquareSet moveHighlight ;
6361 uint8_t squareFrom ;
@@ -66,7 +64,7 @@ typedef struct {
6664
6765} FlipChessScene1Model ;
6866
69- uint8_t picture [SCL_BOARD_PICTURE_WIDTH * SCL_BOARD_PICTURE_WIDTH ];
67+ static uint8_t picture [SCL_BOARD_PICTURE_WIDTH * SCL_BOARD_PICTURE_WIDTH ];
7068
7169void flipchess_putImagePixel (uint8_t pixel , uint16_t index ) {
7270 picture [index ] = pixel ;
@@ -145,8 +143,8 @@ void flipchess_shiftMessages(FlipChessScene1Model* model) {
145143 // shift messages
146144 model -> msg3 = model -> msg2 ;
147145 model -> msg2 = model -> msg ;
148- strncpy (model -> moveString3 , model -> moveString2 , 15 );
149- strncpy (model -> moveString2 , model -> moveString , 15 );
146+ strncpy (model -> moveString3 , model -> moveString2 , MAX_TEXT_LEN );
147+ strncpy (model -> moveString2 , model -> moveString , MAX_TEXT_LEN );
150148}
151149
152150void flipchess_drawBoard (FlipChessScene1Model * model ) {
@@ -319,9 +317,9 @@ uint8_t flipchess_turn(FlipChessScene1Model* model) {
319317 SCL_moveToString (model -> game .board , s0 , s1 , p , model -> moveString );
320318 }
321319 break ;
320+ model -> paramExit = moveType ;
322321 }
323322
324- model -> paramExit = moveType ;
325323 return model -> paramExit ;
326324}
327325
@@ -377,11 +375,14 @@ static int flipchess_scene_1_model_init(
377375 model -> paramStep = 0 ;
378376 model -> paramFEN = NULL ;
379377 model -> paramPGN = NULL ;
380-
381378 model -> clockSeconds = -1 ;
379+
382380 SCL_Board emptyStartState = SCL_BOARD_START_STATE ;
383381 memcpy (model -> startState , & emptyStartState , sizeof (SCL_Board ));
382+
383+ #if ENABLE_960
384384 model -> random960PosNumber = -1 ;
385+ #endif
385386
386387 model -> squareSelected = 255 ;
387388 model -> squareSelectedLast = 28 ; // start selector near middle
@@ -399,14 +400,14 @@ static int flipchess_scene_1_model_init(
399400 model -> squareTo = 255 ;
400401 model -> turnState = 0 ;
401402
402- furi_hal_random_init ();
403403 SCL_randomBetterSeed (furi_hal_random_get ());
404404
405+ #if ENABLE_960
405406#if SCL_960_CASTLING
406407 if (model -> random960PosNumber < 0 ) model -> random960PosNumber = SCL_randomBetter ();
407408#endif
408-
409409 if (model -> random960PosNumber >= 0 ) model -> random960PosNumber %= 960 ;
410+ #endif
410411
411412 if (model -> paramFEN != NULL )
412413 SCL_boardFromFEN (model -> startState , model -> paramFEN );
@@ -416,9 +417,12 @@ static int flipchess_scene_1_model_init(
416417 SCL_boardInit (model -> startState );
417418 SCL_recordApply (record , model -> startState , model -> paramStep );
418419 }
420+
421+ #if ENABLE_960
419422#if SCL_960_CASTLING
420423 else
421424 SCL_boardInit960 (model -> startState , model -> random960PosNumber );
425+ #endif
422426#endif
423427
424428 SCL_gameInit (& (model -> game ), model -> startState );
@@ -577,7 +581,7 @@ void flipchess_scene_1_exit(void* context) {
577581 FlipChessScene1 * instance = (FlipChessScene1 * )context ;
578582
579583 with_view_model (
580- instance -> view , FlipChessScene1Model * model , { model -> squareSelected = 255 ; }, true);
584+ instance -> view , FlipChessScene1Model * model , { model -> paramExit = 0 ; }, true);
581585}
582586
583587void flipchess_scene_1_enter (void * context ) {
0 commit comments