Add Yabasic Bulls and Cows example (bulls_cows.yab) to Projects

This commit is contained in:
Luxferre committed 2026-11-02 16:27:45 +02:00
1 parent 699444d717
commit 8ae2dd3b39
6 files changed
+457 -4

No files matched your search

+1 -1
View File
@@ -8,7 +8,7 @@ It uses a pure **X11 (`Xlibre` + `sxmo-de-dwm`)** stack (no Wayland) with **Adre
## 2. Repository layout ## 2. Repository layout
- `src/sxmo-dwm/`: patched `dwm` window manager (`240x320` vertical `bstack` layout, 24px Pango status bar, desktop `"Menu"`/`"Names"` softkey bar, C-level `evdev` `SW_LID` slider and universal key wake handling, `*` + `#` screenshot chord via `bananarchy-screenshot`, live `.Xresources` reload, and `.so` plugin loader via `dwm_plugin.h`). - `src/sxmo-dwm/`: patched `dwm` window manager (`240x320` vertical `bstack` layout, 24px Pango status bar, desktop `"Menu"`/`"Names"` softkey bar, C-level `evdev` `SW_LID` slider and universal key wake handling, `*` + `#` screenshot chord via `bananarchy-screenshot`, live `.Xresources` reload, and `.so` plugin loader via `dwm_plugin.h`).
- `src/sxmo-dmenu/`: zero-lag resident DWM menu plugin (`dmenu.so`) and `/tmp/dwm_plugin_dmenu.sock` client (`dmenu` / `xdmenu`), featuring built-in Sxmo menus (`sys`, `applications`, `scripts`, `modem`, `config`, `power`, `audio`, `notifications`, `wm`, `timezone`, `games`, `st`, `nano`, `sthotkeys`) and `fcitx5-t9` XIM input. - `src/sxmo-dmenu/`: zero-lag resident DWM menu plugin (`dmenu.so`) and `/tmp/dwm_plugin_dmenu.sock` client (`dmenu` / `xdmenu`), featuring built-in Sxmo menus (`sys`, `applications`, `scripts`, `modem`, `config`, `power`, `audio`, `notifications`, `wm`, `timezone`, `games`, `st`, `nano`, `sthotkeys`) and `fcitx5-t9` XIM input.
- `src/neoui/`: **NeoUI** `240x320` UI SDK (`neoui.h` -> `/usr/include/neoui.h`, `neoui.cpp` -> `/usr/lib/libneoui.so`) providing both a C-compatible FFI (`neoui_*`) and C++20 classes (`ThemeSpec`, `PluginTheme`, `NeoWindow`) for `.Xresources` / `~/.xthemes/*.xth` theme resolution, Xlib/Xft/Pango window and offscreen `Pixmap` double buffering, standardized OS shell widgets, keypad/softkey chord handling, and multi-tap input (paired with Yabasic FFI libraries `neoui.yab` and `neonet.yab` + demos `neoui_demo.yab` and `neonet_demo.yab` in `overlay/rootfs/home/user/Projects/`). - `src/neoui/`: **NeoUI** `240x320` UI SDK (`neoui.h` -> `/usr/include/neoui.h`, `neoui.cpp` -> `/usr/lib/libneoui.so`) providing both a C-compatible FFI (`neoui_*`) and C++20 classes (`ThemeSpec`, `PluginTheme`, `NeoWindow`) for `.Xresources` / `~/.xthemes/*.xth` theme resolution, Xlib/Xft/Pango window and offscreen `Pixmap` double buffering, standardized OS shell widgets, keypad/softkey chord handling, and multi-tap input (paired with Yabasic FFI libraries `neoui.yab` and `neonet.yab` + examples `neoui_demo.yab`, `neonet_demo.yab`, and `bulls_cows.yab` in `overlay/rootfs/home/user/Projects/`).
- `src/dwm-plugins/`: preloaded C++20 `240x320` DWM plugins linked against `libneoui.so` and shared headers: - `src/dwm-plugins/`: preloaded C++20 `240x320` DWM plugins linked against `libneoui.so` and shared headers:
- `theme.h`: header forwarding to `../neoui/neoui.h` for unified `.Xresources` / `~/.xthemes/*.xth` parsing, proportional font sizing (`theme.baseFontSize`), automatic shade derivation, and live Xft/Pango theme reloading (`PluginTheme`). - `theme.h`: header forwarding to `../neoui/neoui.h` for unified `.Xresources` / `~/.xthemes/*.xth` parsing, proportional font sizing (`theme.baseFontSize`), automatic shade derivation, and live Xft/Pango theme reloading (`PluginTheme`).
- `phone_data.h`: shared X11 geometry (`240x296` below the 24px bar), FIFO IPC (`/tmp/dwm_plugin_<name>.fifo`), softkey chord detection, Sxmo TSV contact/call/SMS parsers, and `libjpeg`/`libpng` helpers. - `phone_data.h`: shared X11 geometry (`240x296` below the 24px bar), FIFO IPC (`/tmp/dwm_plugin_<name>.fifo`), softkey chord detection, Sxmo TSV contact/call/SMS parsers, and `libjpeg`/`libpng` helpers.
+2
View File
@@ -37,6 +37,8 @@ Release versions follow the `<year-letter><MM><DD>` format (where `2026` is `a`,
- Skipped `dwm` `drawbar()` Xorg/Glamor/SPI redraws and `sxmo_hook_statusbar.sh` process spawns whenever `bl_power != 0` or `/tmp/bananarchy_screen_locked` exists (with immediate bar refresh on wake/unlock) and wrapped background spawns in double-fork subshells `( ... & )` across `bananarchy-x11-session.sh`, `sxmo_modemmonitor.sh`, `sxmo_hook_start.sh`, `sxmo_hook_postwake.sh`, and `msm-modem-uim-selection` to eliminate zombie child accumulation. - Skipped `dwm` `drawbar()` Xorg/Glamor/SPI redraws and `sxmo_hook_statusbar.sh` process spawns whenever `bl_power != 0` or `/tmp/bananarchy_screen_locked` exists (with immediate bar refresh on wake/unlock) and wrapped background spawns in double-fork subshells `( ... & )` across `bananarchy-x11-session.sh`, `sxmo_modemmonitor.sh`, `sxmo_hook_start.sh`, `sxmo_hook_postwake.sh`, and `msm-modem-uim-selection` to eliminate zombie child accumulation.
- **Literal caller ID contact matching (`sxmo_contacts.sh`, `sxmo_common.sh`, `sxmo_modemsendsms.sh`)**: - **Literal caller ID contact matching (`sxmo_contacts.sh`, `sxmo_common.sh`, `sxmo_modemsendsms.sh`)**:
- Replaced unescaped `grep -i "$NUMBER"` contact lookups with literal matching so carrier service numbers containing regex metacharacters (such as `*121#`) never match arbitrary contact entries. - Replaced unescaped `grep -i "$NUMBER"` contact lookups with literal matching so carrier service numbers containing regex metacharacters (such as `*121#`) never match arbitrary contact entries.
- **Yabasic Bulls and Cows example (`~/Projects/bulls_cows.yab`)**:
- Added a playable Bulls and Cows 4-digit code-breaking game written in Yabasic using the NeoUI SDK (`neoui.yab`) to `/home/user/Projects/bulls_cows.yab`.
--- ---
+1 -1
View File
@@ -26,7 +26,7 @@ This manual covers flashing, operating, and customizing **Bananarchy Linux** (`2
- **Patched `dwm`** provides a `240x320` vertical bottom-stack (`bstack`) layout, a 24px top status bar, a transparent `"Menu"` / `"Names"` desktop softkey bar, a Conky desktop clock and status widget (which refreshes automatically when changing time, timezone, or wallpaper, or when logging out), and `< 2 ms` handling of physical slider (`SW_LID`) and wake keys. - **Patched `dwm`** provides a `240x320` vertical bottom-stack (`bstack`) layout, a 24px top status bar, a transparent `"Menu"` / `"Names"` desktop softkey bar, a Conky desktop clock and status widget (which refreshes automatically when changing time, timezone, or wallpaper, or when logging out), and `< 2 ms` handling of physical slider (`SW_LID`) and wake keys.
2. **Preloaded resident DWM plugins (`< 2 ms` wakeup)**: 2. **Preloaded resident DWM plugins (`< 2 ms` wakeup)**:
- Core phone applications (`dmenu`, `xdrawer`, `dialer`, `calllog`, `callscreen`, `contacts`, `sms`, `files`, `camera`, `themes`, `passcode`, `modem`, `networks`, `ringtones`, `wallpapers`, `music`, `sip`, `email`, `irc`, `tox`, `smallweb`, `gps`, `locker`) run as preloaded resident daemons (`dwm-plugin <name> --preload`) that sleep at 0% CPU and open instantaneously over FIFO/socket IPC. - Core phone applications (`dmenu`, `xdrawer`, `dialer`, `calllog`, `callscreen`, `contacts`, `sms`, `files`, `camera`, `themes`, `passcode`, `modem`, `networks`, `ringtones`, `wallpapers`, `music`, `sip`, `email`, `irc`, `tox`, `smallweb`, `gps`, `locker`) run as preloaded resident daemons (`dwm-plugin <name> --preload`) that sleep at 0% CPU and open instantaneously over FIFO/socket IPC.
- All UI elements — including the `dunst` notification daemon (`bananarchy-sync-dunst-theme`) — share the **NeoUI SDK (`libneoui.so` + `/usr/include/neoui.h`)** and a single **XRDB theming engine** (`~/.xthemes/*.xth` -> `~/.Xresources`) with 20 preinstalled color schemes, proportional font sizing (`theme.baseFontSize`), and live reload without restarting X11. NeoUI exposes both C++20 classes and a C-compatible FFI (`neoui_*`) for building custom native or scripted (`yabasic` via `~/Projects/neoui.yab` and `~/Projects/neoui_demo.yab`, paired with **NeoNet** in `~/Projects/neonet.yab` and `~/Projects/neonet_demo.yab` for `libcurl` HTTP/HTTPS and TCP/TLS/UDP socket networking) `240x320` GUI applications — see [SDK.md](./SDK.md) for the complete API reference and examples. - All UI elements — including the `dunst` notification daemon (`bananarchy-sync-dunst-theme`) — share the **NeoUI SDK (`libneoui.so` + `/usr/include/neoui.h`)** and a single **XRDB theming engine** (`~/.xthemes/*.xth` -> `~/.Xresources`) with 20 preinstalled color schemes, proportional font sizing (`theme.baseFontSize`), and live reload without restarting X11. NeoUI exposes both C++20 classes and a C-compatible FFI (`neoui_*`) for building custom native or scripted (`yabasic` via `~/Projects/neoui.yab`, `~/Projects/neoui_demo.yab`, and `~/Projects/bulls_cows.yab`, paired with **NeoNet** in `~/Projects/neonet.yab` and `~/Projects/neonet_demo.yab` for `libcurl` HTTP/HTTPS and TCP/TLS/UDP socket networking) `240x320` GUI applications — see [SDK.md](./SDK.md) for the complete API reference and examples.
3. **First-class terminal (`st`) and 6-mode `fcitx5-t9` keypad input**: 3. **First-class terminal (`st`) and 6-mode `fcitx5-t9` keypad input**:
- `st` is patched with HarfBuzz OpenType ligature shaping (`Fira Code` default) and live `.Xresources` reload. - `st` is patched with HarfBuzz OpenType ligature shaping (`Fira Code` default) and live `.Xresources` reload.
- `fcitx5-t9` provides 6 keypad input modes (`abc`, `Abc`, `ABC`, `Sym`, `Ctl`, `123` + `*` long-press `Ctrl+` latch) in a fixed bottom candidate bar (`Y = 290, H = 30`). - `fcitx5-t9` provides 6 keypad input modes (`abc`, `Abc`, `ABC`, `Sym`, `Ctl`, `123` + `*` long-press `Ctrl+` latch) in a fixed bottom candidate bar (`Y = 290, H = 30`).
+1 -1
View File
@@ -50,7 +50,7 @@ Instead of spawning slow shell scripts for everyday phone tasks, Bananarchy runs
- **6-mode `fcitx5-t9` keypad input**: press `#` to cycle between `abc`, `Abc`, `ABC`, `Sym` (all 32 ASCII punctuation symbols), `Ctl` (`Ctrl` sequences, arrows, `PageUp`/`PageDown`, `F1`–`F12`), and `123` numeric modes with a fixed bottom candidate bar. - **6-mode `fcitx5-t9` keypad input**: press `#` to cycle between `abc`, `Abc`, `ABC`, `Sym` (all 32 ASCII punctuation symbols), `Ctl` (`Ctrl` sequences, arrows, `PageUp`/`PageDown`, `F1`–`F12`), and `123` numeric modes with a fixed bottom candidate bar.
- **First-class Linux terminal (`st`)**: patched with HarfBuzz OpenType ligatures (`Fira Code` as the default system and terminal font), XIM T9 input, and live theme reloading. - **First-class Linux terminal (`st`)**: patched with HarfBuzz OpenType ligatures (`Fira Code` as the default system and terminal font), XIM T9 input, and live theme reloading.
- **On-device development, scripting, 3D demos, and gaming**: preinstalled `gcc`/`g++`, `make`, `git`, GNU `coreutils`, GNU `bc`/`dc`, `mandoc`, `nano`, `ed`, `sqlite3`, `lua` (`5.5` and `5.4`), `yabasic` (with full `yabasic-doc` manual and HTML documentation), `perl`, `tcl`, the [Janet](https://janet-lang.org/) language and `jpm`, the [Bantam](https://bantam.luxferre.top/) coding agent, `frotz` (interactive fiction), OpenGL / OpenGL ES hardware diagnostics and demos (`glxinfo`, `eglinfo`, `glxgears`, `glteapot`, `es2gears_x11`), standalone X11 keypad games (`Snake`, `Tetris`, and `Scoundrel` roguelike solitaire), a full-featured Gambatte-based Game Boy / Game Boy Color emulator (`gambatte` / `gbemu`) with readjustable keypad controls (`B=8`, `Turbo B=5`, `A=9`, `Turbo A=6`, `D-pad`, `Start=2`, `Select=3`, `Palette=*`), 10 color palettes, save states, and file manager `.gb`/`.gbc` integration, and **ReMEdy (`remedy` / `j2me`)**, a native `240x320` J2ME (MIDP 2.0 / CLDC 1.1) emulator with Adreno 304 hardware-accelerated JSR-184 M3G 3D graphics, NeoUI-themed high-level LCDUI widgets, socket/HTTP networking (`Connector`), `RecordStore` (RMS) persistence, MMAPI audio, readjustable keypad controls, and `.jar`/`.jad` file manager integration. - **On-device development, scripting, 3D demos, and gaming**: preinstalled `gcc`/`g++`, `make`, `git`, GNU `coreutils`, GNU `bc`/`dc`, `mandoc`, `nano`, `ed`, `sqlite3`, `lua` (`5.5` and `5.4`), `yabasic` (with full `yabasic-doc` manual and HTML documentation), `perl`, `tcl`, the [Janet](https://janet-lang.org/) language and `jpm`, the [Bantam](https://bantam.luxferre.top/) coding agent, `frotz` (interactive fiction), OpenGL / OpenGL ES hardware diagnostics and demos (`glxinfo`, `eglinfo`, `glxgears`, `glteapot`, `es2gears_x11`), standalone X11 keypad games (`Snake`, `Tetris`, and `Scoundrel` roguelike solitaire), a full-featured Gambatte-based Game Boy / Game Boy Color emulator (`gambatte` / `gbemu`) with readjustable keypad controls (`B=8`, `Turbo B=5`, `A=9`, `Turbo A=6`, `D-pad`, `Start=2`, `Select=3`, `Palette=*`), 10 color palettes, save states, and file manager `.gb`/`.gbc` integration, and **ReMEdy (`remedy` / `j2me`)**, a native `240x320` J2ME (MIDP 2.0 / CLDC 1.1) emulator with Adreno 304 hardware-accelerated JSR-184 M3G 3D graphics, NeoUI-themed high-level LCDUI widgets, socket/HTTP networking (`Connector`), `RecordStore` (RMS) persistence, MMAPI audio, readjustable keypad controls, and `.jar`/`.jad` file manager integration.
- **NeoUI `240x320` UI SDK (`libneoui.so` + `/usr/include/neoui.h` + `neoui.yab`) and NeoNet (`neonet.yab`)**: unified C-compatible FFI and C++20 UI SDK wrapping Xlib, Xft, Pango, `libjpeg`/`libpng`, `.Xresources` / `~/.xthemes/*.xth` live theme resolution, offscreen `Pixmap` double buffering, standardized OS shell widgets (headers, tabs, softkey bars, list/toggle/slider rows, input boxes, progress bars, scrollbars, modals, popup menus, and toasts), keypad/softkey chord handling, and multi-tap text entry—usable from C, C++, or Yabasic (`~/Projects/neoui.yab` and `~/Projects/neoui_demo.yab`), paired with **NeoNet (`~/Projects/neonet.yab` and `~/Projects/neonet_demo.yab`)** for `libcurl`-based HTTP/HTTPS requests with custom headers and TCP/TLS/UDP socket exchange in Yabasic. See [SDK.md](./SDK.md) for full documentation. - **NeoUI `240x320` UI SDK (`libneoui.so` + `/usr/include/neoui.h` + `neoui.yab`) and NeoNet (`neonet.yab`)**: unified C-compatible FFI and C++20 UI SDK wrapping Xlib, Xft, Pango, `libjpeg`/`libpng`, `.Xresources` / `~/.xthemes/*.xth` live theme resolution, offscreen `Pixmap` double buffering, standardized OS shell widgets (headers, tabs, softkey bars, list/toggle/slider rows, input boxes, progress bars, scrollbars, modals, popup menus, and toasts), keypad/softkey chord handling, and multi-tap text entry—usable from C, C++, or Yabasic (`~/Projects/neoui.yab`, `~/Projects/neoui_demo.yab`, and `~/Projects/bulls_cows.yab`), paired with **NeoNet (`~/Projects/neonet.yab` and `~/Projects/neonet_demo.yab`)** for `libcurl`-based HTTP/HTTPS requests with custom headers and TCP/TLS/UDP socket exchange in Yabasic. See [SDK.md](./SDK.md) for full documentation.
--- ---
+2 -1
View File
@@ -5,7 +5,7 @@
They encapsulate all low-level X11 (`Xlib`), `Xft`, `Pango`, `libjpeg-turbo`, `libpng`, `.Xresources` / `~/.xthemes/*.xth` live theme resolution, offscreen `Pixmap` double buffering, standardized OS shell widgets, FIFO IPC, softkey chord handling (`Left+Right` softkey -> `xdrawer`), multi-tap T9 keypad input, and HTTP/HTTPS/TCP/TLS/UDP networking behind: They encapsulate all low-level X11 (`Xlib`), `Xft`, `Pango`, `libjpeg-turbo`, `libpng`, `.Xresources` / `~/.xthemes/*.xth` live theme resolution, offscreen `Pixmap` double buffering, standardized OS shell widgets, FIFO IPC, softkey chord handling (`Left+Right` softkey -> `xdrawer`), multi-tap T9 keypad input, and HTTP/HTTPS/TCP/TLS/UDP networking behind:
1. A **C-compatible FFI (`neoui_*`)** designed for both C programs and foreign-function interfaces (such as **Yabasic** `frnfn_call` / `frnfn_call$`, LuaJIT FFI, Janet, Python `ctypes`, etc.). 1. A **C-compatible FFI (`neoui_*`)** designed for both C programs and foreign-function interfaces (such as **Yabasic** `frnfn_call` / `frnfn_call$`, LuaJIT FFI, Janet, Python `ctypes`, etc.).
2. A **C++20 SDK (`namespace bananarchy`)** providing `ThemeSpec`, `PluginTheme`, `NeoWindow`, and direct Pango/Xft/image helpers used across all 14 built-in Bananarchy DWM plugins. 2. A **C++20 SDK (`namespace bananarchy`)** providing `ThemeSpec`, `PluginTheme`, `NeoWindow`, and direct Pango/Xft/image helpers used across all 14 built-in Bananarchy DWM plugins.
3. A **Yabasic UI wrapper library (`neoui.yab`)** preinstalled in `/home/user/Projects/neoui.yab` (and symlinked at `/usr/lib/neoui.yab`), paired with a full showcase application (`/home/user/Projects/neoui_demo.yab`). 3. A **Yabasic UI wrapper library (`neoui.yab`)** preinstalled in `/home/user/Projects/neoui.yab` (and symlinked at `/usr/lib/neoui.yab`), paired with a full showcase application (`/home/user/Projects/neoui_demo.yab`) and a playable Bulls and Cows code-breaking game (`/home/user/Projects/bulls_cows.yab`).
4. A **Yabasic networking wrapper library (`neonet.yab`)** preinstalled in `/home/user/Projects/neonet.yab` (and symlinked at `/usr/lib/neonet.yab`), wrapping `libcurl.so.4` and musl `libc` via `libffi` for one-line HTTP/HTTPS requests with custom headers as well as raw TCP, TLS, and UDP socket data exchange, paired with a combined NeoNet + NeoUI demo application (`/home/user/Projects/neonet_demo.yab`). 4. A **Yabasic networking wrapper library (`neonet.yab`)** preinstalled in `/home/user/Projects/neonet.yab` (and symlinked at `/usr/lib/neonet.yab`), wrapping `libcurl.so.4` and musl `libc` via `libffi` for one-line HTTP/HTTPS requests with custom headers as well as raw TCP, TLS, and UDP socket data exchange, paired with a combined NeoNet + NeoUI demo application (`/home/user/Projects/neonet_demo.yab`).
--- ---
@@ -19,6 +19,7 @@ They encapsulate all low-level X11 (`Xlib`), `Xft`, `Pango`, `libjpeg-turbo`, `l
| `/home/user/Projects/neoui.yab` | `overlay/rootfs/home/user/Projects/neoui.yab` | Yabasic native C FFI wrapper module for NeoUI (`import neoui`) | | `/home/user/Projects/neoui.yab` | `overlay/rootfs/home/user/Projects/neoui.yab` | Yabasic native C FFI wrapper module for NeoUI (`import neoui`) |
| `/usr/lib/neoui.yab` | `overlay/rootfs/usr/lib/neoui.yab` | Symlink to `/home/user/Projects/neoui.yab` so `import neoui` works from any working directory | | `/usr/lib/neoui.yab` | `overlay/rootfs/usr/lib/neoui.yab` | Symlink to `/home/user/Projects/neoui.yab` so `import neoui` works from any working directory |
| `/home/user/Projects/neoui_demo.yab` | `overlay/rootfs/home/user/Projects/neoui_demo.yab` | Interactive 3-tab Yabasic showcase demonstrating all NeoUI widgets, multi-tap input, custom drawing, modals, and live theme reload | | `/home/user/Projects/neoui_demo.yab` | `overlay/rootfs/home/user/Projects/neoui_demo.yab` | Interactive 3-tab Yabasic showcase demonstrating all NeoUI widgets, multi-tap input, custom drawing, modals, and live theme reload |
| `/home/user/Projects/bulls_cows.yab` | `overlay/rootfs/home/user/Projects/bulls_cows.yab` | Playable Bulls and Cows 4-digit code-breaking game written in Yabasic using NeoUI widgets, scrollable guess history, modals, and haptic feedback |
| `/home/user/Projects/neonet.yab` | `overlay/rootfs/home/user/Projects/neonet.yab` | Yabasic native `libcurl` + socket FFI wrapper module for NeoNet (`import neonet`) | | `/home/user/Projects/neonet.yab` | `overlay/rootfs/home/user/Projects/neonet.yab` | Yabasic native `libcurl` + socket FFI wrapper module for NeoNet (`import neonet`) |
| `/usr/lib/neonet.yab` | `overlay/rootfs/usr/lib/neonet.yab` | Symlink to `/home/user/Projects/neonet.yab` so `import neonet` works from any working directory | | `/usr/lib/neonet.yab` | `overlay/rootfs/usr/lib/neonet.yab` | Symlink to `/home/user/Projects/neonet.yab` so `import neonet` works from any working directory |
| `/home/user/Projects/neonet_demo.yab` | `overlay/rootfs/home/user/Projects/neonet_demo.yab` | Interactive 3-tab Yabasic showcase combining NeoNet and NeoUI (`1:HTTP/S`, `2:Sockets`, `3:Tools`) | | `/home/user/Projects/neonet_demo.yab` | `overlay/rootfs/home/user/Projects/neonet_demo.yab` | Interactive 3-tab Yabasic showcase combining NeoNet and NeoUI (`1:HTTP/S`, `2:Sockets`, `3:Tools`) |
+450
View File
@@ -0,0 +1,450 @@
#!/usr/bin/yabasic
// ============================================================================
// bulls_cows.yab - Bulls and Cows game for Bananarchy NeoUI (Yabasic)
// ============================================================================
// Classic code-breaking game: guess the secret 4-digit code (unique digits).
// Bulls = correct digit in the correct position.
// Cows = correct digit in the wrong position.
// You have 10 attempts. Each guess must use 4 distinct digits.
//
// Controls:
// 0-9 keys : Append a digit to your guess (duplicates rejected)
// OK (Enter): Submit your guess / confirm a dialog choice
// Space / Right Softkey (F2): Delete last digit, or Quit if guess is empty
// Left Softkey (F1): Open the Action Menu (New Game / About / Quit)
// Up / Down: Scroll the guess history
//
// Note: this build of yabasic has no function returns and no RNG seeding,
// so randomness uses a small LCG seeded from the wall clock (time$).
// ============================================================================
import neoui
if neoui_init("bulls_cows", 0) = 0 then
print "Failed to initialize NeoUI X11 window"
exit 1
fi
// ----------------------------------------------------------------------------
// Constants & state
// ----------------------------------------------------------------------------
MAX_GUESSES = 10
CODE_LEN = 4
secret$ = ""
guess_count = 0
game_over = 0
won = 0
dim history_guess$(MAX_GUESSES)
dim history_result$(MAX_GUESSES)
current_guess$ = ""
history_scroll = 0
// Modal state: 0 = none, 1 = action menu, 2 = new-game confirm, 3 = game over
modal_mode = 0
menu_sel = 0
confirm_new = 0
// PRNG state (LCG, kept small to stay within exact double integer range)
cur = 1
rd_val = 0
// Evaluation result globals (yabasic here has no function returns)
ev_bulls = 0
ev_cows = 0
dis_found = 0
// ----------------------------------------------------------------------------
// Random number generator (LCG, modulus 32768 -> product stays well under 2^53)
// ----------------------------------------------------------------------------
sub seed_rng()
local i, c
seed = 0
t$ = time$
for i = 1 to len(t$)
c = asc(mid$(t$, i, 1))
if c >= 48 and c <= 57 then
seed = mod(seed * 7 + (c - 48), 100000)
fi
next i
if seed = 0 then seed = 1 fi
cur = mod(seed, 32768)
end sub
sub next_rand()
cur = mod(cur * 11035 + 12345, 32768)
end sub
sub rand_digit()
next_rand()
rd_val = mod(int(cur / 100), 10)
end sub
// ----------------------------------------------------------------------------
// Game logic
// ----------------------------------------------------------------------------
sub generate_secret()
local i, d, bit, found, used
secret$ = ""
used = 0
for i = 1 to CODE_LEN
found = 0
while found = 0
rand_digit()
d = rd_val
bit = 1
for j = 1 to d
bit = bit * 2
next j
if mod(int(used / bit), 2) = 0 then
used = used + bit
secret$ = secret$ + str$(d)
found = 1
fi
wend
next i
end sub
sub reset_game()
seed_rng()
generate_secret()
guess_count = 0
game_over = 0
won = 0
current_guess$ = ""
history_scroll = 0
modal_mode = 0
menu_sel = 0
confirm_new = 0
end sub
sub digit_in_string(d$, s$)
local i
dis_found = 0
for i = 1 to len(s$)
if mid$(s$, i, 1) = d$ then
dis_found = 1
fi
next i
end sub
sub append_digit(d)
local d$
if game_over then
return
fi
if len(current_guess$) >= CODE_LEN then
neoui_show_toast("Guess is full! Press OK.", 1200)
return
fi
d$ = str$(d)
digit_in_string(d$, current_guess$)
if dis_found = 1 then
neoui_show_toast("Digit already used", 1000)
return
fi
current_guess$ = current_guess$ + d$
end sub
sub backspace_guess()
if len(current_guess$) > 0 then
current_guess$ = left$(current_guess$, len(current_guess$) - 1)
fi
end sub
sub evaluate(g$)
local bulls, cows, i, j
bulls = 0
cows = 0
for i = 1 to CODE_LEN
if mid$(g$, i, 1) = mid$(secret$, i, 1) then
bulls = bulls + 1
else
for j = 1 to CODE_LEN
if i <> j then
if mid$(g$, i, 1) = mid$(secret$, j, 1) then
cows = cows + 1
fi
fi
next j
fi
next i
ev_bulls = bulls
ev_cows = cows
end sub
sub submit_guess()
local result$
if game_over then
return
fi
if len(current_guess$) < CODE_LEN then
neoui_show_toast("Enter " + str$(CODE_LEN) + " digits first!", 1500)
return
fi
evaluate(current_guess$)
result$ = str$(ev_bulls) + "B " + str$(ev_cows) + "C"
history_guess$(guess_count) = current_guess$
history_result$(guess_count) = result$
guess_count = guess_count + 1
current_guess$ = ""
if ev_bulls = CODE_LEN then
won = 1
game_over = 1
modal_mode = 3
confirm_new = 1
neoui_vibrate(120)
elsif guess_count >= MAX_GUESSES then
game_over = 1
modal_mode = 3
confirm_new = 1
else
neoui_show_toast(result$, 1200)
fi
end sub
// ----------------------------------------------------------------------------
// Rendering
// ----------------------------------------------------------------------------
sub render_header()
local badge$
if game_over then
badge$ = "Done"
else
badge$ = "Try " + str$(guess_count + 1) + "/" + str$(MAX_GUESSES)
fi
neoui_draw_header(neoui_icon$("gamepad"), neoui.TEXT_YELLOW, "Bulls & Cows", badge$)
end sub
sub render_secret_area()
local y, i, mask$
y = 40
if game_over then
neoui_draw_text(neoui.FONT_SMALL, neoui.TEXT_MUTED, 8, y, 14, "Secret code:", 224)
neoui_draw_text(neoui.FONT_LARGE, neoui.TEXT_GREEN, 8, y + 16, 22, secret$, 224)
else
mask$ = ""
for i = 1 to CODE_LEN
mask$ = mask$ + "?"
next i
neoui_draw_text(neoui.FONT_SMALL, neoui.TEXT_MUTED, 8, y, 14, "Secret code:", 224)
neoui_draw_text(neoui.FONT_LARGE, neoui.TEXT_LIGHT, 8, y + 16, 22, mask$, 224)
fi
end sub
sub render_input_area()
local y, prompt$
y = 84
if game_over then
prompt$ = "Game finished"
else
prompt$ = "Your guess (4 unique digits)"
fi
neoui_draw_input_box(8, y, 224, 40, 0, prompt$, current_guess$, "0-9 keys to type", 0)
end sub
sub render_history()
local y, i, start_idx, end_idx, visible, result$
y = 136
neoui_draw_text(neoui.FONT_SMALL, neoui.TEXT_YELLOW, 8, y, 14, "Guess history:", 224)
y = y + 20
visible = 4
if guess_count <= visible then
start_idx = 0
else
start_idx = guess_count - visible + history_scroll
if start_idx < 0 then start_idx = 0 fi
if start_idx > guess_count - visible then start_idx = guess_count - visible fi
fi
end_idx = start_idx + visible - 1
if end_idx > guess_count - 1 then end_idx = guess_count - 1 fi
for i = start_idx to end_idx
if i >= 0 and i < guess_count then
result$ = history_result$(i)
neoui_draw_list_row(i - start_idx, y, 26, 0, neoui_icon$("list"), neoui.TEXT_BLUE, "#" + str$(i + 1) + " " + history_guess$(i), result$, "")
y = y + 26
fi
next i
if guess_count > visible then
neoui_draw_scrollbar(234, 156, 104, guess_count, visible, -history_scroll)
fi
end sub
sub render_hint()
if game_over then
if won then
neoui_draw_text_centered(neoui.FONT_SMALL, neoui.TEXT_GREEN, 8, 264, 224, 16, "Solved in " + str$(guess_count) + " tries! OK = New game")
else
neoui_draw_text_centered(neoui.FONT_SMALL, neoui.TEXT_RED, 8, 264, 224, 16, "Out of tries! Code was " + secret$ + " - OK = New game")
fi
else
neoui_draw_text_centered(neoui.FONT_SMALL, neoui.TEXT_MUTED, 8, 264, 224, 16, "0-9 type OK go Up/Dn scroll")
fi
end sub
sub render_all()
neoui_begin_frame()
render_header()
render_secret_area()
render_input_area()
render_history()
render_hint()
if modal_mode = 1 then
neoui_draw_menu_popup("New Game|About|Quit Game", neoui_icon$("refresh") + "|" + neoui_icon$("info") + "|" + neoui_icon$("close"), menu_sel, 3)
neoui_draw_softkeys("Close", "Select", "Back")
elsif modal_mode = 2 then
neoui_draw_confirm_dialog("Start New Game?", "Abandon the current", "round and guess a new code?", "Cancel", "New Game", confirm_new)
neoui_draw_softkeys("Cancel", "Confirm", "Back")
elsif modal_mode = 3 then
if won then
neoui_draw_confirm_dialog("You Win!", "Cracked the code in", str$(guess_count) + " tries!", "Quit", "Play Again", confirm_new)
else
neoui_draw_confirm_dialog("Game Over", "The code was " + secret$, "Better luck next time!", "Quit", "Play Again", confirm_new)
fi
neoui_draw_softkeys("Quit", "Confirm", "Back")
else
neoui_draw_softkeys("Menu", "Submit", "Del/Quit")
fi
neoui_end_frame()
end sub
// ----------------------------------------------------------------------------
// Main loop
// ----------------------------------------------------------------------------
reset_game()
render_all()
running = 1
while running
ev = neoui_poll_event(250)
if ev = neoui.EV_CLOSE_REQ then
running = 0
elsif ev = neoui.EV_EXPOSE or ev = neoui.EV_THEME_RELOAD then
render_all()
elsif ev = neoui.EV_SOFTKEY_LEFT then
if modal_mode = 0 then
modal_mode = 1
menu_sel = 0
else
modal_mode = 0
fi
render_all()
elsif ev = neoui.EV_SOFTKEY_RIGHT then
if modal_mode <> 0 then
modal_mode = 0
render_all()
elsif len(current_guess$) > 0 then
backspace_guess()
render_all()
else
running = 0
fi
elsif ev = neoui.EV_KEY_PRESS then
k = neoui_event_key()
if modal_mode = 1 then
if k = neoui.KEY_UP then
menu_sel = mod(menu_sel + 2, 3)
elsif k = neoui.KEY_DOWN then
menu_sel = mod(menu_sel + 1, 3)
elsif k = neoui.KEY_BACK then
modal_mode = 0
elsif k = neoui.KEY_OK then
modal_mode = 0
if menu_sel = 0 then
confirm_new = 1
modal_mode = 2
elsif menu_sel = 1 then
neoui_show_toast("Bulls & Cows: guess the 4-digit code!", 2200)
elsif menu_sel = 2 then
running = 0
fi
fi
render_all()
elsif modal_mode = 2 then
if k = neoui.KEY_LEFT or k = neoui.KEY_RIGHT or k = neoui.KEY_UP or k = neoui.KEY_DOWN then
confirm_new = 1 - confirm_new
elsif k = neoui.KEY_BACK then
modal_mode = 0
elsif k = neoui.KEY_OK then
modal_mode = 0
if confirm_new then
reset_game()
neoui_show_toast("New game started!", 1500)
fi
fi
render_all()
elsif modal_mode = 3 then
if k = neoui.KEY_LEFT or k = neoui.KEY_RIGHT or k = neoui.KEY_UP or k = neoui.KEY_DOWN then
confirm_new = 1 - confirm_new
elsif k = neoui.KEY_BACK then
modal_mode = 0
elsif k = neoui.KEY_OK then
modal_mode = 0
if confirm_new then
reset_game()
neoui_show_toast("New game started!", 1500)
else
running = 0
fi
fi
render_all()
else
if k = neoui.KEY_OK then
submit_guess()
elsif k = neoui.KEY_BACK then
running = 0
elsif k = neoui.KEY_UP then
if history_scroll < 0 then
history_scroll = history_scroll + 1
fi
elsif k = neoui.KEY_DOWN then
if guess_count > 5 and history_scroll > -(guess_count - 5) then
history_scroll = history_scroll - 1
fi
elsif k = neoui.KEY_SPACE then
backspace_guess()
elsif k = neoui.KEY_0 then
append_digit(0)
elsif k = neoui.KEY_1 then
append_digit(1)
elsif k = neoui.KEY_2 then
append_digit(2)
elsif k = neoui.KEY_3 then
append_digit(3)
elsif k = neoui.KEY_4 then
append_digit(4)
elsif k = neoui.KEY_5 then
append_digit(5)
elsif k = neoui.KEY_6 then
append_digit(6)
elsif k = neoui.KEY_7 then
append_digit(7)
elsif k = neoui.KEY_8 then
append_digit(8)
elsif k = neoui.KEY_9 then
append_digit(9)
fi
render_all()
fi
fi
wend
neoui_shutdown()