Implementation of game concede functionality, game initiator settings, and enhanced game management features to improve the player experience and provide better control over game creation and gameplay.

Specification

  • on /Drafts a button that either player can press at anytime to conceed in which case tehy lose and the other player winds.
  • on /Admin there is Admin is (Black or white)
    • Change that text to Game Initiator is:
    • Call field GameInitatorGoesFirst
    • Save to settings/Load from
    • Have default true
  • on /Player a checkbox “I play first” that is loaded from GameInitatorGoesFirst
    • But the player can change it locally, not to the database
    • That is used to determine who plays first when a game is started

Requirements Implemented

1. Game Concede Functionality

  • Concede button on /Drafts page for both players
  • Confirmation dialog to prevent accidental concessions
  • Instant game ending with opponent declared winner
  • Chat notification of concession to all players

2. Game Initiator Settings

  • Admin setting “Game Initiator goes first” on /Admin page
  • Player checkbox “I play first” on /Player page
  • Default behavior - Game initiator goes first by default
  • Local player control - Players can override their preference without affecting others

3. Enhanced Game Management

  • Database persistence for game initiator settings
  • Settings service integration for loading/saving preferences
  • Real-time updates when settings change

Technical Implementation

Database Changes

AppSettings Model

public sealed class AppSettings
{
    // ... existing fields ...
    
    [Required]
    public bool GameInitiatorGoesFirst { get; set; } = true;
}

SettingsService Enhancements

New Properties

private bool _gameInitiatorGoesFirst = true;

public bool GameInitiatorGoesFirst
{
    get
    {
        lock (_lock)
        {
            return _gameInitiatorGoesFirst;
        }
    }
}

New Methods

public async Task<bool> GetGameInitiatorGoesFirstAsync(CancellationToken cancellationToken = default)
{
    // Load setting from database
}

public async Task<bool> UpdateGameInitiatorGoesFirstAsync(bool newValue, CancellationToken cancellationToken = default)
{
    // Save setting to database
}

DraftsService Enhancements

Concede Functionality

public (bool ok, string? msg) SetGameWinner(string gameId, int winnerPlayer, int userId, string userName)
{
    // Validate game state and user
    // Add concession message to chat
    // Mark game as finished with specified winner
    // Notify all players
}

UI Components

Admin Page Updates (/Admin)

  • Changed label from “Admin is” to “Game Initiator is:”
  • Added checkbox “Game Initiator goes first” in settings
  • Database persistence for the setting
  • Default value set to true

Player Page Updates (/Player)

  • Added “Game Settings” section with “I play first” checkbox
  • Local override capability for player preference
  • SettingsService integration to load default value
  • Game creation integration with player’s choice

DraftsGame Page Updates (/Drafts)

  • Concede buttons for both game creator and second player
  • Confirmation dialog with clear messaging
  • Red styling for concede buttons to indicate destructive action
  • Game state validation before allowing concession

User Experience

Concede Flow

  1. Player clicks “Concede” button (red, clearly marked)
  2. Confirmation dialog appears: “Are you sure you want to concede? You will lose and the other player will win.”
  3. Player confirms with “Yes, Concede” button
  4. Game ends immediately with opponent declared winner
  5. Chat message appears: “[PlayerName] conceded. Player [X] wins!”
  6. Game over overlay shows winner/loser status

Game Initiator Settings Flow

  1. Admin sets default in Admin settings page
  2. Players see default when loading Player page
  3. Players can override locally with “I play first” checkbox
  4. Game creation uses player’s choice to determine who goes first
  5. Setting persists for admin changes, player changes are local

API Changes

SettingsService Methods

  • GetGameInitiatorGoesFirstAsync() - Load game initiator setting
  • UpdateGameInitiatorGoesFirstAsync(bool) - Update game initiator setting

DraftsService Methods

  • SetGameWinner(string gameId, int winnerPlayer, int userId, string userName) - Concede game
  • /drafts?creator={playerNumber} - Specify who goes first when creating game

Security Considerations

Concede Validation

  • Game state validation - Only active games can be conceded
  • User validation - Only game participants can concede
  • Thread safety - All operations are thread-safe
  • Audit trail - Concession messages logged in chat

Settings Validation

  • Admin-only changes - Only admins can change default setting
  • Input validation - Proper validation of all inputs
  • Database constraints - Required field validation

Testing Checklist

Concede Functionality

  • Concede button appears for both players
  • Confirmation dialog works correctly
  • Game ends with correct winner
  • Chat message appears for concession
  • Game over overlay shows correct status
  • Cannot concede finished games
  • Cannot concede abandoned games

Game Initiator Settings

  • Admin can change default setting
  • Setting persists in database
  • Player page loads default correctly
  • Player can override locally
  • Game creation respects player choice
  • Navigation parameters work correctly

Edge Cases

  • Concede works on slow connections
  • Settings load correctly on first visit
  • Database failures handled gracefully
  • Concurrent access handled properly

Migration Notes

Database Migration

  • New field GameInitiatorGoesFirst added to AppSettings table
  • Default value set to true for existing installations
  • No breaking changes to existing functionality

Backward Compatibility

  • Existing games continue to work as before
  • Default behavior maintains current expectations
  • No API breaking changes

Future Enhancements

Planned Features

  • Concede with reason - Allow players to add concession reason
  • Concede statistics - Track concession rates and patterns
  • Game initiator history - Track who initiates games
  • Tournament mode - Special rules for tournament games

Potential Improvements

  • Animated concede button - Visual feedback for destructive action
  • Concede timeout - Prevent abuse of concede feature
  • Concede undo - Allow opponent to reject concession (rare cases)
  • Concede analytics - Dashboard for concession statistics

Implementation Status

✅ Complete Implementation

  • Game concede functionality
  • Game initiator settings
  • Admin and Player page updates
  • Database persistence
  • UI enhancements
  • Security validation
  • Documentation

Status: ✅ All requirements implemented and tested


 TopicSubtopic
   
 This Category Links 
Category:Artificial Intelligence Index:Artificial Intelligence
<  Prev:   Checkers-Drafts Game