Selaa lähdekoodia

Merge chess from https://github.com/xtruan/flipper-chess

Willy-JL 1 vuosi sitten
vanhempi
commit
394964718c

+ 1 - 1
chess/.github/workflows/build.yml

@@ -7,7 +7,7 @@ on:
       - develop
 
 env:
-  firmware_version: '0.104.0'
+  firmware_version: '1.1.2'
 
 jobs:
   build:

+ 1 - 1
chess/.github/workflows/release.yml

@@ -6,7 +6,7 @@ on:
       - 'v[0-9]+.[0-9]+.[0-9]+'
 
 env:
-  firmware_version: '0.104.0'
+  firmware_version: '1.1.2'
 
 jobs:
   build:

+ 10 - 0
chess/.gitignore

@@ -50,3 +50,13 @@ modules.order
 Module.symvers
 Mkfile.old
 dkms.conf
+
+.DS_Store
+dist/*
+.vscode
+.nvim
+.clang-format
+.clangd
+.editorconfig
+.env
+.ufbt

+ 1 - 1
chess/README.md

@@ -7,7 +7,7 @@
 ![FLIPR](https://github.com/xtruan/flipper-chess/blob/main/icons/FLIPR_128x64.png)
 
 ## Chess game for Flipper Zero
-- Built against `0.104.0` Flipper Zero firmware release
+- Built against `1.1.2` Flipper Zero firmware release
 - Uses [smallchesslib](https://codeberg.org/drummyfish/smallchesslib)
 
 ### Installation

+ 1 - 1
chess/application.fam

@@ -14,6 +14,6 @@ App(
     fap_category="Games",
     fap_author="Struan Clark (xtruan)",
     fap_weburl="https://github.com/xtruan/flipper-chess",
-    fap_version=(1, 11),
+    fap_version=(1, 12),
     fap_description="Chess for Flipper",
 )

+ 2 - 2
chess/catalog/manifest.yml

@@ -2,9 +2,9 @@ sourcecode:
   type: git
   location:
     origin: https://github.com/xtruan/flipper-chess.git
-    commit_sha: e5ee4520dfc68080b1723b03f6d8e857ec10a6b0
+    commit_sha: f850ffbc6d8ca9c9e12c3a2bab16d5cbb009365e
 description: "How about a nice game of chess?"
-changelog: "v1.11 - Update to support new FW"
+changelog: "v1.12 - Update to fix illegal move bug"
 author: "@xtruan"
 screenshots:
   - "./catalog/startscreen.png"

+ 1 - 1
chess/flipchess.h

@@ -16,7 +16,7 @@
 #include "views/flipchess_startscreen.h"
 #include "views/flipchess_scene_1.h"
 
-#define FLIPCHESS_VERSION "v1.11"
+#define FLIPCHESS_VERSION "v1.12"
 
 #define TEXT_BUFFER_SIZE 96
 #define TEXT_SIZE        (TEXT_BUFFER_SIZE - 1)

+ 18 - 6
chess/views/flipchess_scene_1.c

@@ -228,13 +228,25 @@ uint8_t flipchess_turn(FlipChessScene1Model* model) {
             //     break;
 
             if(model->turnState == 0 && model->squareSelected != 255) {
-                model->squareFrom = model->squareSelected;
-                model->turnState = 1;
+                // Color check before allowing piece selection
+                char piece = model->game.board[model->squareSelected];
+                if(piece != '.' &&
+                   SCL_pieceIsWhite(piece) == SCL_boardWhitesTurn(model->game.board)) {
+                    model->squareFrom = model->squareSelected;
+                    model->turnState = 1;
+                }
             } else if(model->turnState == 1 && model->squareSelected != 255) {
-                model->squareTo = model->squareSelected;
-                model->turnState = 2;
-                model->squareSelectedLast = model->squareSelected;
-                //model->squareSelected = 255;
+                // Validate before executing
+                if(SCL_boardMoveIsLegal(
+                       model->game.board, model->squareFrom, model->squareSelected)) {
+                    model->squareTo = model->squareSelected;
+                    model->turnState = 2;
+                    model->squareSelectedLast = model->squareSelected;
+                } else {
+                    // Invalid move, reset state
+                    model->turnState = 0;
+                    SCL_squareSetClear(model->moveHighlight);
+                }
             }
 
             if(model->turnState == 1 && model->squareFrom != 255) {