Skip to content

Smarter AI: card knowledge tracking and strategic play priorities#40

Draft
Copilot wants to merge 4 commits intomainfrom
copilot/improve-bot-playing-strategy
Draft

Smarter AI: card knowledge tracking and strategic play priorities#40
Copilot wants to merge 4 commits intomainfrom
copilot/improve-bot-playing-strategy

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 27, 2026

Bots were predictable and tactically naive — they ignored Priest-revealed card information, never reacted to being exposed, and always played the lowest-value card regardless of context.

Knowledge tracking

Two optional fields added to PlayerState:

  • knownCards: Record<string, string> — cards seen via Priest (opponentId → cardId)
  • exposedToPlayerIds: string[] — who currently knows this player's card

These are populated in the Priest effect and cleared whenever a card changes hands (Prince force-discard, King swap), and reset each round.

Strategic play priorities (chooseCardToPlay / chooseTarget)

AI now evaluates moves in priority order rather than defaulting to lowest-value:

  1. Guard + known card → exact guess, guaranteed elimination
  2. Baron + known weaker opponent → guaranteed Baron win
  3. Handmaid when exposed → play for full-round protection, nullifying the opponent's knowledge (always better than self-Princing to discard it)
  4. Prince on self when a high-value card (≥5) is exposed → escapes before an opponent Guard-kills you (only for King-level cards; skipped for Princess or Handmaid)
  5. King + known better card → trade up to a higher-value hand
  6. Default → lowest-value card fallback (existing behaviour)
// AI holds Handmaid + Prince, Handmaid is known — plays Handmaid for protection
aiPlayer.hand = ['prince', 'handmaid'];
aiPlayer.exposedToPlayerIds = ['p1'];
// → AI plays Handmaid (gets protected), not Prince on self

// AI holds King + Prince, King is known — self-Princes to escape
aiPlayer.hand = ['prince', 'king'];
aiPlayer.exposedToPlayerIds = ['p1'];
// → AI plays Prince on itself, discarding the known King and drawing fresh

Smarter Chancellor return

When the AI has card knowledge, it prefers to keep Guard (for a certain kill next turn) over keeping the raw highest-value card.

Guard/revenge guess

chooseGuardGuess now returns the known card directly when Priest knowledge is available, rather than using probability weights.

Original prompt

The AIs are pretty predictable, moreover they aren't that good at the game.

How can we turn them into better love letter players?

As an example, if somebody plays priest on a bot, that bot will not get rid of their card if they can, which could be a smart move because otherwise a real player would take them out

I'm not even sure if the bots remember much if they play priest etc on other people

Anyway, please make the bots smarter about the game


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Co-authored-by: Chrizpy <38702971+Chrizpy@users.noreply.github.com>
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages bot commented Mar 6, 2026

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
royalletters c4c7ad0 Commit Preview URL

Branch Preview URL
Mar 06 2026, 08:00 PM

…scape

Co-authored-by: Chrizpy <38702971+Chrizpy@users.noreply.github.com>
Copilot AI changed the title [WIP] Enhance AI strategy for playing love letter Smarter AI: card knowledge tracking and strategic play priorities Mar 6, 2026
@Chrizpy
Copy link
Copy Markdown
Owner

Chrizpy commented Mar 6, 2026

@copilot

I saw an AI prince their handmade because it was known, that's a bit unnecassary

I just really want the AI try to make the best decisions it can do, based on the rules of the game, the knowledge that is presented and so on. Just like a human would have played

…lue exposed cards

Co-authored-by: Chrizpy <38702971+Chrizpy@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 6, 2026

@copilot

I saw an AI prince their handmade because it was known, that's a bit unnecassary...

Fixed in c4c7ad0. The AI now behaves more like a human player in two ways:

  1. Plays Handmaid when exposed (new priority before self-Prince): Playing Handmaid gives full-round protection, which completely nullifies the opponent's card knowledge for that turn — always better than wasting a Prince to discard it.

  2. Self-Prince restricted to high-value cards (value ≥5): A human would only bother escaping exposure if holding a King or higher — a card worth Guard-guessing. For low-value cards like Baron, Priest or Handmaid the risk doesn't justify discarding them.

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