carre_magic_logic 1.0.0 copy "carre_magic_logic: ^1.0.0" to clipboard
carre_magic_logic: ^1.0.0 copied to clipboard

Pure Dart game engine and rule logic for Carré Magique (magic square board game), including moves, captures, promotions, and Minimax AI.

example/main.dart

import 'package:carre_magic_logic/carre_magic_logic.dart';

void main() async {
  print('=== Carré Magique — démo logique pure ===\n');

  // 1. Partie initiale
  var state = InitializeGame.call();
  print(
      'Plateau initial : ${state.board.countPieces(PlayerColor.white)} blancs, '
      '${state.board.countPieces(PlayerColor.black)} noirs');
  print('Trait : ${state.currentPlayer.displayName}\n');

  // 2. Un coup humain : (3,0) → (2,0)
  final moves = GetValidMoves.forState(state, const Position(row: 3, col: 0));
  print('Coups pour (3,0) : $moves');
  state = ApplyMove.call(state, moves.first);
  print('Après coup : trait = ${state.currentPlayer.displayName}, '
      'historique = ${state.moveHistory.length}\n');

  // 3. IA répond (niveau medium)
  final aiMove = await ComputeAiMove.call(state, AiDifficulty.medium);
  print('IA joue : $aiMove');
  if (aiMove != null) {
    state = ApplyMove.call(state, aiMove);
    state = MinimaxEngine.resolvePendingPromotion(state);
    print('Après IA : trait = ${state.currentPlayer.displayName}, '
        'status = ${state.status}\n');
  }

  // 4. Sérialisation
  final json = state.toJson();
  final restored = GameStateJson.fromJson(json);
  print('Codec OK ? ${restored == state}');

  // 5. Évaluation
  final score = BoardEvaluator.evaluate(state, AiConfig.medium.evalWeights);
  print('Score (POV noirs) : $score');
}
0
likes
160
points
84
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Pure Dart game engine and rule logic for Carré Magique (magic square board game), including moves, captures, promotions, and Minimax AI.

Repository (GitHub)
View/report issues

Topics

#game #game-engine #board-game #ai #minimax

License

MIT (license)

More

Packages that depend on carre_magic_logic