Craft Anything: understand how any software works, and craft your own.
Rust
Stop counting a video or music player as a game (#970)
Justin John6e0978a08598
diff --git a/crates/ai/src/rebuild/kinds/game.rs b/crates/ai/src/rebuild/kinds/game.rsindex 2984d144..f7d74dd6 100644--- a/crates/ai/src/rebuild/kinds/game.rs+++ b/crates/ai/src/rebuild/kinds/game.rs@@ -8,6 +8,26 @@ use craft_anything_engines::game;const ASSETS_NOW_OFF: &str ="Generated assets are now off for this project: don't make more with assets_image_generate or assets_model_generate. Keep the ones already in app/.";+/// Whether `at` starts a word, where a hyphen joins it to the word before: "(level editor)", but+/// not "low-level" or "multilevel".+fn starts_word(request: &str, at: usize) -> bool {+ request.get(..at).and_then(|s| s.chars().next_back()).is_none_or(|c| !c.is_alphanumeric() && c != '-')+}++/// A number of players as its own words: "2-player", "(four players)", but not "MPEG-2 player",+/// "mp2 player", "12 player" or "two playerctl".+fn says_player_count(request: &str) -> bool {+ // Any run of spaces or line breaks counts as one space: "2 player".+ let request = request.split_whitespace().collect::<Vec<_>>().join(" ");+ let ends_word = |rest: &str| rest.strip_prefix('s').unwrap_or(rest).chars().next().is_none_or(|c| !c.is_alphanumeric());+ ["2", "3", "4", "two", "three", "four"].iter().any(|n| {+ ["-player", " player"].iter().any(|player| {+ let phrase = format!("{n}{player}");+ request.match_indices(&phrase).any(|(at, _)| starts_word(&request, at) && request.get(at + phrase.len()..).is_some_and(ends_word))+ })+ })+}+pub struct GameKind;impl GameKind {@@ -33,7 +53,26 @@ impl TargetKind for GameKind {// say ("Clone <its title> 1:1" never says "game").if game::Builder::from_stack(cx.stack).is_some() {Some(200)- } else if cx.says(&["game", "gameplay", "steam", "level", "player", "游戏", "遊戲", "玩法", " spiel", "-spiel"]) {+ // Not plain "player": a video or music player is an app (#953).+ } else if says_player_count(&cx.request)+ || cx.request.match_indices("level").any(|(at, _)| starts_word(&cx.request, at))+ || cx.says(&[+ "game",+ "gameplay",+ "steam",+ "multiplayer",+ "multi-player",+ "multi player",+ "singleplayer",+ "single-player",+ "single player",+ "游戏",+ "遊戲",+ "玩法",+ " spiel",+ "-spiel",+ ])+ {Some(60)} else {Nonediff --git a/crates/ai/src/rebuild/tests.rs b/crates/ai/src/rebuild/tests.rsindex 14b76cad..a06d4950 100644--- a/crates/ai/src/rebuild/tests.rs+++ b/crates/ai/src/rebuild/tests.rs@@ -62,6 +62,46 @@ fn stack_choice() {assert_eq!(kind_of("Copy this tool", &folder, "Rust + egui (eframe)"), "app", "the app stack stays an app");}+#[test]+fn the_word_player_alone_is_not_a_game() {+ for request in [+ "A video player for my films",+ "a music player",+ "Um player de vídeo com canais, filmes e séries",+ "An MPEG-2 player",+ "an mpeg-2-player",+ "an mp2 player",+ "an mp4 player",+ "a 12 player scoreboard",+ "a music app with two playerctl shortcuts",+ "a low-level disk tool",+ "a multilevel menu",+ ] {+ assert_eq!(choose(request, &TargetRef::None).0, "app", "{request}");+ }+ assert_eq!(choose("Um player de vídeo desktop, use Electron", &TargetRef::None), ("app", "Electron"));+ for request in [+ "A multiplayer shooter",+ "A single-player adventure",+ "A single player adventure",+ "a 2-player chess board",+ "a two player chess board",+ "Build a (2-player) chess board",+ "a 2 player chess board",+ "chess for 2 players",+ "party fun for four players.",+ "a two\nplayer chess board",+ "a four-player party",+ "4 player dungeon crawl",+ "A game with one player",+ "A level editor",+ "Build a (level editor)",+ "Make this:\nlevel editor",+ ] {+ assert_eq!(choose(request, &TargetRef::None).0, "game", "{request}");+ }+}+#[test]fn german_requests_keep_their_project_kind() {for request in ["Ein einfaches Snake-Spiel", "Dasselbe Spiel mit einer Bestenliste"] {diff --git a/docs/ROADMAP.md b/docs/ROADMAP.mdindex df123e79..85444d01 100644--- a/docs/ROADMAP.md+++ b/docs/ROADMAP.md@@ -654,6 +654,10 @@ Owner: open · Status: in progressand hold it only to what it broke- [ ] A new project in Python, Go or the like still fails the build check ("No project to buildfound") and has no program for the screenshot check: `[[toolchain]]` could build it too+- [x] "player" alone doesn't make a request a game: a video or music player is an app (#953)+ — claimed: justinjohn0306, branch bugfix/953-player-not-a-game+- [ ] Game words can't tell these apart from games: "a low level disk tool", "an MPEG 2 player",+ "a single player app for movies". Telling them apart needs more than a list of words### R2.8 Clean room means clean roomOwner: maintainers · Status: in progress