• Blog
  • Docs
  • Pricing
  • We’re hiring!
Log inSign up
pchinjr

pchinjr

cat-wars

Cat Wars 2029 trading game MVP
Public
Like
cat-wars
Home
Code
6
README.md
auth.ts
config.ts
H
main.ts
rules.ts
rules_test.ts
Environment variables
Branches
1
Pull requests
Remixes
History
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Sign up now
Code
/
README.md
Code
/
README.md
Search
…
Viewing readonly version of main branch: v133
View latest version
README.md

Cat Wars 2029

A retro-styled browser trading game inspired by the Drug Wars gameplay loop.

Players move between real U.S. city markets, buy/sell illegal cat breeds, manage heat risk, and survive escalating debt pressure.

Stack

  • Runtime: Val Town HTTP Val (main.ts)
  • Web framework: Hono
  • Persistence: Val-scoped SQLite via https://esm.town/v/std/sqlite/main.ts
  • Binary/media: Val Town blob (avatar path still supports blob keys, UI uses pixel presets)
  • Frontend: server-rendered HTML + vanilla JS

Project Files

  • main.ts: HTTP routes, DB bootstrap/migrations, rendering, and game actions
  • auth.ts: session cookie parsing, session token lifecycle, authenticated user lookup
  • config.ts: static game config (markets, breeds, pixel avatar metadata)
  • rules.ts: pure game logic helpers (borrow terms and heat streak cap)
  • rules_test.ts: script-based regression tests for rules.ts

Core Gameplay Loop

  1. Register or log in.
  2. Check market prices for each breed.
  3. Buy cats where prices are low.
  4. Travel to another city (travel advances day and raises heat).
  5. Sell for profit.
  6. Manage debt before deadline.

Travel Economics

  • There is no fixed dollar travel fee.
  • Each travel action increments day by 1.
  • Travel raises heat and may trigger a DHS bust.
  • Bust outcomes can reduce cash (fine) and inventory (seizure).

Market Forces And Fast-Profit Playstyle

  • High-volatility breeds (Sphynx, Bengal) produce the largest swings.
  • Early borrowing increases buying power but fees escalate per borrow tier.
  • Low-risk travel hubs (Seattle, Austin) help reduce bust frequency while hunting good exits.
  • Over-traveling increases bust risk and can erase profits quickly.

Debt System

  • Debt has a due day (debt_due_day).
  • Borrowing:
    • increases cash and debt
    • applies escalating fee by borrow tier (capped)
    • extends due window, capped to at most 90 days ahead
  • Missing debt deadline while debt > 0 triggers bankruptcy:
    • inventory wiped
    • run reset to baseline state

Heat and Bust Rules

  • Travel increases heat and can trigger a DHS bust event.
  • Bust events may seize inventory and fine cash.
  • Heat cannot stay at 100% for more than 2 consecutive turns; on the 3rd turn it is forced down to 95%.

Schema

users

Account identity and avatar key.

sessions

Cookie-token sessions with expiry.

player_state

Current market, cash, debt, heat, day, cargo, debt due day, borrow tier, and heat max streak.

markets

City list and enforcement risk profile.

breeds

Base economy metadata for each cat breed.

inventory

Owned quantity per breed per user.

market_day_prices

Shared daily per-market prices across all users (multiplayer-ready market tape).

user_market_prices (legacy)

Deprecated table kept only for migration compatibility. Active writes no longer target this table.

schema_migrations

Tracks one-way migration IDs that have been applied.

API Surface

Auth/session

  • POST /api/register
  • POST /api/login
  • POST /api/logout
  • GET /api/me

Economy/actions

  • POST /api/buy
  • POST /api/sell
  • POST /api/travel
  • POST /api/borrow
  • POST /api/pay-debt

Avatar/presets

  • POST /api/avatar/preset
  • GET /api/pixel-avatar/:avatarId
  • GET /api/avatar/:userId

Migrations

initDb() creates base tables and then runs idempotent tracked migrations:

  • 2026-03-02-add-player_state-debt_due_day
  • 2026-03-02-add-player_state-borrow_count
  • 2026-03-02-add-player_state-heat_max_streak
  • 2026-03-02-backfill-debt_due_day
  • 2026-03-02-create-market-day-prices
  • 2026-03-02-backfill-market-day-prices-from-user-market-prices
  • 2026-03-02-clear-user-market-prices-legacy

Applied migrations are recorded in schema_migrations.

Testing

Run the script file directly in Val Town:

  • rules_test.ts

It validates:

  • borrow fee escalation and cap behavior
  • debt-ceiling clamping
  • due-date 90-day cap
  • heat 100% streak cooldown behavior

Runtime Guarantees

  • Market prices are shared by day + market for all users.
  • Price history retention is enforced by deleting rows older than MARKET_PRICE_RETENTION_DAYS (currently 45) relative to the active max player day.
  • Mutating routes (travel, borrow, pay-debt, buy, sell) centralize write coordination and use sqlite.batch for multi-write updates where possible.
  • Full cross-statement transaction boundaries are pending a runtime-safe transaction primitive in Val Town's sqlite helper.

Current Status

  • Val is public: pchinjr/cat-wars
  • Auth/session logic extracted into auth.ts
  • Static game config extracted into config.ts
  • Core deterministic rules extracted into rules.ts
  • Regression coverage added for extracted rules via rules_test.ts

Next Suggested Improvements

  1. Add tests for route-level behaviors (/api/travel, /api/borrow, bankruptcy reset).
  2. Introduce a tiny data-access layer to remove inline SQL from route handlers.
  3. Add structured event logging for travel, bust, borrow, and bankruptcy actions.
  4. Add multiplayer-ready turn clock abstraction for synchronized city market ticks.
FeaturesVersion controlCode intelligenceCLIMCP
Use cases
TeamsAI agentsSlackGTM
DocsShowcaseTemplatesNewestTrendingAPI examplesNPM packages
PricingNewsletterBlogAboutCareers
We’re hiring!
Brandhi@val.townStatus
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Open Source Pledge
Terms of usePrivacy policyAbuse contact
© 2026 Val Town, Inc.