Skip to content

Add utility-based strategic AI (ai_utility.js + ai_strategic.js)#6

Draft
chrisraff with Copilot wants to merge 2 commits into
masterfrom
copilot/add-ai-strategy-for-scoring
Draft

Add utility-based strategic AI (ai_utility.js + ai_strategic.js)#6
chrisraff with Copilot wants to merge 2 commits into
masterfrom
copilot/add-ai-strategy-for-scoring

Conversation

Copilot AI commented Mar 13, 2026

Copy link
Copy Markdown
Contributor

Implements a new AI strategy that scores board states by utility and selects attacks by expected value, plus a reusable BoardUtility library for graph/board analysis.

ai_utility.js — shared library (BoardUtility)

  • Win-probability table: iterative bottom-up convolution of d6 sum distributions → WIN_PROB[a][d] precomputed at load time. Correctly models that the attacker rolls attack_dice − 1 dice.
  • board_score(game, arm, dice, pn): four-factor utility:
    • +3.0 × my_largest_connected_region — drives dice income
    • −2.0 × max_opponent_connected_region — their income threat
    • +0.4 × frontier_dice — dice that can actually attack (locked interior dice contribute 0)
    • −0.5 × exposed_opponent_strong_dice — opponent armies ≥5 dice bordering me
  • get_largest_component(game, arm, pn) and BFS helpers operate on detached arm/dice arrays so simulated states never touch the live game object.

ai_strategic.js — the AI

Each turn, for every legal attack:

EV = p_win × score(win_state) + (1 − p_win) × score(loss_state) + income_bonus
  • Win/loss states are evaluated via in-place mutation + restore on local snapshots — no array copies per iteration.
  • income_bonus = max(0, my_conn/opp_conn_max − 1) × 0.3: when my connected region significantly outpaces opponents', marginally negative-EV attacks become worth taking because dice income means faster recovery.
  • Attack only if EV > baseline_score; return 0 (end turn) otherwise.

Integration

  • index.html: loads ai_utility.jsai_strategic.js before game.js
  • game.js: player slot 4 switched from ai_default to ai_strategic

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI self-assigned this Mar 13, 2026
Co-authored-by: chrisraff <22504698+chrisraff@users.noreply.github.com>
Copilot AI changed the title [WIP] Add AI strategy for scoring board states by utility Add utility-based strategic AI (ai_utility.js + ai_strategic.js) Mar 14, 2026
Copilot AI requested a review from chrisraff March 14, 2026 00:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants