Skip to content

Commit

Permalink
添加多項改進
Browse files Browse the repository at this point in the history
- 支援 Kubernetes
- 開始重構核心包
  • Loading branch information
igncp committed Jun 10, 2024
1 parent 4e14b25 commit 235ad5e
Show file tree
Hide file tree
Showing 59 changed files with 1,481 additions and 538 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ on:
push:
branches:
- "main"
workflow_dispatch:

name: Checks

jobs:
check:
if: github.repository == 'igncp/mahjong' || github.event_name == 'workflow_dispatch'
name: Check
runs-on: ubuntu-latest
steps:
Expand Down
109 changes: 109 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion docs/TODO.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
## Features to add

- More complex and complete game mechanics
- System for testing games
- More user features, robust implementations (modules)
- Better UI (using canvas, no antd), interactive options
- Better UI (using canvas, no antd), interactive options, animations

## Later Improvements

Expand Down
12 changes: 6 additions & 6 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
else rust.dev-hook
);
packages = with pkgs;
[bun patchelf postgresql nodejs_20] # without nodejs_20 prettier throws an error
[bun patchelf postgresql nodejs_22] # without nodejs_22 prettier throws an error
++ (
if is-docker-ci
then []
Expand Down
4 changes: 4 additions & 0 deletions mahjong_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,9 @@ lazy_static = "1.4.0"
rand = "0.8.5"
rustc-hash = "1.1.0"
serde = { version = "1.0.167", features = ["derive"] }
serde_json = "1.0.100"
uuid = { version = "1.4.0", features = ["v4", "fast-rng", "macro-diagnostics", "js"] }
wasm-bindgen = "0.2.87"

[dev-dependencies]
pretty_assertions = "1.4.0"
41 changes: 28 additions & 13 deletions mahjong_core/src/ai/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl<'a> StandardAI<'a> {
}
}

let player_hand = self.game.table.hands.get(&meld.player_id).unwrap();
let player_hand = self.game.table.hands.0.get(&meld.player_id).unwrap();
let missing_tile = meld
.tiles
.iter()
Expand Down Expand Up @@ -127,9 +127,16 @@ impl<'a> StandardAI<'a> {

if tile_drawn.is_some() {
if self.sort_on_draw {
let mut hand = self.game.table.hands.get(&current_player).unwrap().clone();
let mut hand = self
.game
.table
.hands
.0
.get(&current_player)
.unwrap()
.clone();
hand.sort_default();
self.game.table.hands.insert(current_player, hand);
self.game.table.hands.0.insert(current_player, hand);
}

return PlayActionResult {
Expand All @@ -139,9 +146,9 @@ impl<'a> StandardAI<'a> {
}
}

let player_tiles = self.game.table.hands.get(&current_player).unwrap();
if player_tiles.0.len() == 14 {
let mut tiles_without_meld = player_tiles
let player_hand = self.game.table.hands.0.get(&current_player).unwrap();
if player_hand.len() == self.game.style.tiles_after_claim() {
let mut tiles_without_meld = player_hand
.0
.iter()
.filter(|tile| tile.set_id.is_none())
Expand Down Expand Up @@ -228,9 +235,16 @@ impl<'a> StandardAI<'a> {

if tile_drawn.is_some() {
if self.sort_on_draw {
let mut hand = self.game.table.hands.get(&current_player).unwrap().clone();
let mut hand = self
.game
.table
.hands
.0
.get(&current_player)
.unwrap()
.clone();
hand.sort_default();
self.game.table.hands.insert(current_player, hand);
self.game.table.hands.0.insert(current_player, hand);
}

return PlayActionResult {
Expand All @@ -239,8 +253,8 @@ impl<'a> StandardAI<'a> {
};
}
} else if self.can_pass_turn {
let player_tiles = self.game.table.hands.get(&current_player).unwrap();
if player_tiles.0.len() == 13 {
let player_hand = self.game.table.hands.0.get(&current_player).unwrap();
if player_hand.len() < self.game.style.tiles_after_claim() {
let success = self.game.round.next(&self.game.table.hands);

if success {
Expand All @@ -253,7 +267,7 @@ impl<'a> StandardAI<'a> {
}
}

if self.game.table.draw_wall.is_empty() && self.can_draw_round {
if self.game.table.draw_wall.0.is_empty() && self.can_draw_round {
let round_passed = self.game.pass_null_round();

if round_passed {
Expand All @@ -272,8 +286,9 @@ impl<'a> StandardAI<'a> {

pub fn get_is_after_discard(&self) -> bool {
let current_player = self.game.get_current_player();
let current_hand = self.game.table.hands.get(&current_player).unwrap();
let current_hand = self.game.table.hands.get(&current_player);

current_hand.0.len() == 13 && self.game.round.tile_claimed.is_some()
current_hand.len() < self.game.style.tiles_after_claim()
&& self.game.round.tile_claimed.is_some()
}
}
3 changes: 2 additions & 1 deletion mahjong_core/src/ai/test_ai.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#[cfg(test)]
mod test {
use crate::{ai::sort_by_is_mahjong, meld::PossibleMeld};
use pretty_assertions::assert_eq;

#[test]
fn it_puts_melds_with_mahjong_at_the_beginning() {
Expand All @@ -10,7 +11,7 @@ mod test {
tiles: vec![],
discard_tile: None,
};
let mut melds = vec![
let mut melds = [
PossibleMeld {
player_id: "1".to_string(),
..default_meld.clone()
Expand Down
Loading

0 comments on commit 235ad5e

Please sign in to comment.