Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jul 25, 2025

Problem

AI players were sometimes competing against their own teammates for intelligence cards, leading to wasteful "suicide" behavior where teammates would fight each other instead of cooperating against enemies.

Example scenario from the issue:

  • Blue faction's LaoHan (老汉) has 0 black cards
  • Red faction teammate has 2 black, 1 red cards
  • Intelligence card is red-black dual-color
  • LaoHan intercepting gives +20 points, Red faction getting it gives -12 points
  • Only 8-point difference, but personality fluctuations (coefficientA, coefficientB) caused teammates to compete

Root Cause

Each AI player independently calculated intelligence card values using their own personality coefficients (random multiplier 0.8-1.2, additive -15 to +15). Small value differences could flip due to personality variations, causing teammates to compete for marginal gains.

Solution

Added minimal teammate coordination logic in RobotPlayer.shouldAvoidTeammateCompetition():

private fun shouldAvoidTeammateCompetition(fsm: FightPhaseIdle, result: FightPhaseResult): Boolean {
    // Only coordinate for modest benefits (deltaValue ≤ 50)
    if (result.deltaValue > 50) return false
    
    // Check if teammates could benefit more
    for (teammate in teammates) {
        val teammateDelta = calculateTeammateBenefit(teammate, fsm)
        
        // Give teammate priority if they benefit significantly more (+20 buffer)
        if (teammateDelta > result.deltaValue + 20) return true
        
        // Avoid competition when both have modest positive benefits  
        if (result.deltaValue < 40 && teammateDelta > 10 && 
            teammate.calFightPhase(fsm)?.deltaValue ?: 0 > 10) return true
    }
    return false
}

Key Features

  • Preserves high-stakes competition: Allows fighting for valuable opportunities (>50 points)
  • Teammate priority system: 20-point buffer gives teammates precedence when they benefit more
  • Prevents wasteful competition: Stops internal fights over marginal gains
  • Identity-aware: Uses existing isPartnerOrSelf() logic correctly
  • Maintains personality: Keeps individual AI behavior while adding coordination
  • Zero breaking changes: Purely additive logic with full backward compatibility

Testing

  • ✅ Builds successfully with all existing tests passing
  • ✅ Code style compliant with ktlint formatting
  • ✅ Handles the specific scenario described in the issue
  • ✅ Preserves competitive behavior for high-value situations

Fixes #372.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@Copilot Copilot AI changed the title [WIP] AI有时候会自杀 Fix AI teammate competition causing "suicide" behavior in intelligence card disputes Jul 25, 2025
@Copilot Copilot AI requested a review from CuteReimu July 25, 2025 04:13
Copilot finished work on behalf of CuteReimu July 25, 2025 04:13
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.

AI有时候会自杀
2 participants