diff --git a/.gitignore b/.gitignore index 67b862b..b19ecf3 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,4 @@ Cargo.lock .idea/ dist/ +sol_chess.tar.gz diff --git a/build-gh.sh b/build-gh.sh deleted file mode 100755 index 8106f20..0000000 --- a/build-gh.sh +++ /dev/null @@ -1,6 +0,0 @@ -cargo build --target wasm32-unknown-unknown --release -mkdir -p ./dist -rm ./web/sol_chess.wasm -mv ./target/wasm32-unknown-unknown/release/sol_chess.wasm ./dist/sol_chess.wasm - -basic-http-server ./dist diff --git a/build-web.sh b/build-web.sh index 8106f20..f3a90de 100755 --- a/build-web.sh +++ b/build-web.sh @@ -1,6 +1,15 @@ cargo build --target wasm32-unknown-unknown --release -mkdir -p ./dist -rm ./web/sol_chess.wasm -mv ./target/wasm32-unknown-unknown/release/sol_chess.wasm ./dist/sol_chess.wasm -basic-http-server ./dist +if [ $? -ne 0 ]; then + echo "Wasm build failed" + exit 1 +fi + +rm -rf ./dist && mkdir -p ./dist && mv ./target/wasm32-unknown-unknown/release/sol_chess.wasm ./dist/sol_chess.wasm && cp ./web/index.html ./dist/index.html + +if [ $? -ne 0 ]; then + echo "Failed to create create dist directory" + exit 1 +fi + +tar -czvf ./sol_chess.tar.gz -C ./dist . && rm -rf ./dist && echo "Web build complete" diff --git a/src/main.rs b/src/main.rs index 1daffcc..173a0a6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -299,15 +299,22 @@ impl Game { std::process::exit(0); } - if is_mouse_button_pressed(MouseButton::Right) { + if is_mouse_button_released(MouseButton::Left) { let current_state = self.state.clone(); let new_state = match current_state { - GameState::SelectSource(_) => GameState::SelectSource(None), - GameState::SelectTarget((_, _)) => { - self.reset_squares(); - GameState::SelectSource(None) + GameState::SelectSource(previous_target) => { + self.handle_select_source(mouse_position(), previous_target) } - GameState::GameOver((i, j)) => GameState::SelectSource(Some((i, j))), + GameState::SelectTarget(source) => { + let next = self.handle_select_target(mouse_position(), source); + if let GameState::SelectTarget(_) = next { + self.reset_squares(); + GameState::SelectSource(None) + } else { + next + } + } + GameState::GameOver(previous_target) => GameState::GameOver(previous_target), }; self.state = new_state; return; @@ -325,21 +332,6 @@ impl Game { self.state = new_state; } - - if is_mouse_button_released(MouseButton::Left) { - let current_state = self.state.clone(); - let new_state = match current_state { - GameState::SelectSource(previous_target) => { - GameState::SelectSource(previous_target) - } - GameState::SelectTarget(source) => { - self.handle_select_target(mouse_position(), source) - } - GameState::GameOver(previous_target) => GameState::GameOver(previous_target), - }; - - self.state = new_state; - } } fn handle_select_source( diff --git a/tools/puzzle_checker/games/1.txt b/tools/puzzle_checker/games/1.txt deleted file mode 100644 index 785dad5..0000000 --- a/tools/puzzle_checker/games/1.txt +++ /dev/null @@ -1,26 +0,0 @@ -*********** Game 1 ************ - -Generating a puzzle with 7 pieces with a maximum of 5 solutions - Total attempts: 328 - Total pieces placed: 3363 - Success pieces placed: 2296 - Total time (ms): 1840 - - ♗ ♗ ♙ ♘ - - . . . ♖ - - . . ♙ . - - . . . ♙ - - - id: 140771860875974 - -Found 1 solutions -1. BxPc2 -2. BxPd1 -3. RxBd1 -4. RxNd4 -5. RxPc4 -6. RxBb4 diff --git a/tools/puzzle_checker/games/10.txt b/tools/puzzle_checker/games/10.txt deleted file mode 100644 index 997d2a3..0000000 --- a/tools/puzzle_checker/games/10.txt +++ /dev/null @@ -1,26 +0,0 @@ -*********** Game 10 ************ - -Generating a puzzle with 7 pieces with a maximum of 5 solutions - Total attempts: 43 - Total pieces placed: 407 - Success pieces placed: 301 - Total time (ms): 238 - - ♙ . ♖ . - - . . ♘ ♙ - - . ♙ ♘ . - - ♗ . . . - - - id: 211381923512704 - -Found 4 solutions -1. BxPb2 -2. NxPa4 -3. RxNc2 -4. RxBb2 -5. NxRb2 -6. NxPd3 diff --git a/tools/puzzle_checker/games/2.txt b/tools/puzzle_checker/games/2.txt deleted file mode 100644 index 2da1541..0000000 --- a/tools/puzzle_checker/games/2.txt +++ /dev/null @@ -1,26 +0,0 @@ -*********** Game 2 ************ - -Generating a puzzle with 7 pieces with a maximum of 5 solutions - Total attempts: 47 - Total pieces placed: 473 - Success pieces placed: 329 - Total time (ms): 279 - - . . . ♗ - - ♘ . ♗ . - - ♙ . . . - - . ♘ ♖ ♗ - - - id: 25288852387844 - -Found 4 solutions -1. RxBd1 -2. BxBc3 -3. RxNb1 -4. NxRb1 -5. NxBc3 -6. NxPa2 diff --git a/tools/puzzle_checker/games/3.txt b/tools/puzzle_checker/games/3.txt deleted file mode 100644 index 366fa28..0000000 --- a/tools/puzzle_checker/games/3.txt +++ /dev/null @@ -1,26 +0,0 @@ -*********** Game 3 ************ - -Generating a puzzle with 7 pieces with a maximum of 5 solutions - Total attempts: 22 - Total pieces placed: 239 - Success pieces placed: 154 - Total time (ms): 160 - - ♗ . ♖ ♙ - - . . . ♙ - - . . . ♙ - - . ♙ . ♗ - - - id: 140737595313588 - -Found 5 solutions -1. RxBa4 -2. RxPd4 -3. RxPd3 -4. RxPd2 -5. RxBd1 -6. RxPb1 diff --git a/tools/puzzle_checker/games/4.txt b/tools/puzzle_checker/games/4.txt deleted file mode 100644 index 5a9ea47..0000000 --- a/tools/puzzle_checker/games/4.txt +++ /dev/null @@ -1,26 +0,0 @@ -*********** Game 4 ************ - -Generating a puzzle with 7 pieces with a maximum of 5 solutions - Total attempts: 200 - Total pieces placed: 2059 - Success pieces placed: 1388 - Total time (ms): 929 - - ♙ ♘ . ♗ - - . ♖ ♙ ♘ - - . . . . - - . . ♙ . - - - id: 211152405031232 - -Found 1 solutions -1. RxNb4 -2. RxPa4 -3. RxBd4 -4. RxNd3 -5. RxPc3 -6. RxPc1 diff --git a/tools/puzzle_checker/games/5.txt b/tools/puzzle_checker/games/5.txt deleted file mode 100644 index 93cb42c..0000000 --- a/tools/puzzle_checker/games/5.txt +++ /dev/null @@ -1,26 +0,0 @@ -*********** Game 5 ************ - -Generating a puzzle with 7 pieces with a maximum of 5 solutions - Total attempts: 74 - Total pieces placed: 771 - Success pieces placed: 512 - Total time (ms): 437 - - ♗ ♙ . ♘ - - . ♖ . ♘ - - . . . . - - . ♗ ♗ . - - - id: 140792316316480 - -Found 4 solutions -1. BxRb3 -2. BxNd3 -3. NxBb3 -4. NxBc1 -5. NxBd3 -6. NxPb4 diff --git a/tools/puzzle_checker/games/6.txt b/tools/puzzle_checker/games/6.txt deleted file mode 100644 index 68c0fd6..0000000 --- a/tools/puzzle_checker/games/6.txt +++ /dev/null @@ -1,26 +0,0 @@ -*********** Game 6 ************ - -Generating a puzzle with 7 pieces with a maximum of 5 solutions - Total attempts: 1 - Total pieces placed: 9 - Success pieces placed: 7 - Total time (ms): 0 - - . ♙ . . - - . . . . - - ♗ . ♗ ♗ - - ♖ ♙ . ♘ - - - id: 2456822087717 - -Found 5 solutions -1. RxBa2 -2. RxBc2 -3. RxBd2 -4. RxNd1 -5. RxPb1 -6. RxPb4 diff --git a/tools/puzzle_checker/games/7.txt b/tools/puzzle_checker/games/7.txt deleted file mode 100644 index 1b08f5e..0000000 --- a/tools/puzzle_checker/games/7.txt +++ /dev/null @@ -1,26 +0,0 @@ -*********** Game 7 ************ - -Generating a puzzle with 7 pieces with a maximum of 5 solutions - Total attempts: 22 - Total pieces placed: 230 - Success pieces placed: 154 - Total time (ms): 109 - - ♖ . . ♙ - - . . . ♗ - - ♗ ♙ ♘ . - - . . ♖ . - - - id: 107752945007872 - -Found 2 solutions -1. RxNc2 -2. RxPb2 -3. RxBa2 -4. RxRa4 -5. RxPd4 -6. RxBd3 diff --git a/tools/puzzle_checker/games/8.txt b/tools/puzzle_checker/games/8.txt deleted file mode 100644 index 4b6d58d..0000000 --- a/tools/puzzle_checker/games/8.txt +++ /dev/null @@ -1,26 +0,0 @@ -*********** Game 8 ************ - -Generating a puzzle with 7 pieces with a maximum of 5 solutions - Total attempts: 63 - Total pieces placed: 639 - Success pieces placed: 441 - Total time (ms): 345 - - . . ♖ . - - . ♙ . . - - ♙ . ♗ . - - ♗ ♙ . ♗ - - - id: 3579962327044 - -Found 5 solutions -1. BxBc2 -2. RxBc2 -3. RxPa2 -4. RxBa1 -5. RxPb1 -6. RxPb3 diff --git a/tools/puzzle_checker/games/9.txt b/tools/puzzle_checker/games/9.txt deleted file mode 100644 index 7442e63..0000000 --- a/tools/puzzle_checker/games/9.txt +++ /dev/null @@ -1,26 +0,0 @@ -*********** Game 9 ************ - -Generating a puzzle with 7 pieces with a maximum of 5 solutions - Total attempts: 250 - Total pieces placed: 2557 - Success pieces placed: 1750 - Total time (ms): 1298 - - . . . . - - ♘ ♘ . ♙ - - . ♙ . ♗ - - ♙ . ♘ . - - - id: 22408723452320 - -Found 1 solutions -1. BxNc1 -2. NxBc1 -3. NxPd3 -4. NxPb2 -5. axNb2 -6. bxNa3 diff --git a/tools/puzzle_checker/gen_games.sh b/tools/puzzle_checker/gen_games.sh deleted file mode 100755 index 5274c40..0000000 --- a/tools/puzzle_checker/gen_games.sh +++ /dev/null @@ -1,9 +0,0 @@ -if [ ! -d games ]; then - mkdir games -fi - -for i in {1..10}; do - echo "*********** Game $i ************" >> games/$i.txt - echo "" >> games/$i.txt - sol_cli -g -n 7 --print >> games/$i.txt -done diff --git a/web/index.html b/web/index.html new file mode 100644 index 0000000..eada65f --- /dev/null +++ b/web/index.html @@ -0,0 +1,27 @@ + + + + + + Solitaire Chess + + + + + + + +