haive.games.nim.example

Comprehensive Nim Game Examples - Mathematical Strategy and Game Theory Demonstration.

This module provides 8 comprehensive examples demonstrating the mathematical properties and strategic aspects of the Nim game, from basic gameplay to advanced analysis, perfect play algorithms, and educational game theory concepts.

The examples cover: 1. Basic Standard Nim gameplay with optimal strategy 2. Misère Nim with endgame analysis 3. Mathematical analysis of positions using nim-sum 4. Game theory demonstration with P/N positions 5. Multiple pile variants and strategic considerations 6. Performance analysis and algorithm benchmarking 7. Educational game theory tutorial 8. Advanced tournament and ML integration

Each example includes detailed explanations of the mathematical concepts, strategic reasoning, and implementation details for educational purposes.

Functions

binary_representation(piles)

Display binary representation of piles for educational purposes.

calculate_nim_sum(piles)

Calculate the nim-sum (XOR) of pile sizes.

example_1_basic_standard_nim()

Example 1: Basic Standard Nim with Optimal Play Strategy.

example_2_misere_nim()

Example 2: Misère Nim with Endgame Analysis.

example_3_mathematical_analysis()

Example 3: Mathematical Analysis of Nim Positions.

example_4_game_theory_positions()

Example 4: Game Theory Demonstration with P/N Positions.

example_5_multiple_pile_variants()

Example 5: Multiple Pile Variants and Strategic Considerations.

example_6_performance_analysis()

Example 6: Performance Analysis and Algorithm Benchmarking.

example_7_educational_tutorial()

Example 7: Educational Game Theory Tutorial.

example_8_advanced_integration()

Example 8: Advanced Tournament and ML Integration.

main()

Main entry point.

parse_args()

Parse command line arguments.

print_section_header(title[, subtitle])

Print a formatted section header.

print_subsection(title)

Print a formatted subsection header.

run_all_examples()

Run all examples sequentially.

Module Contents

haive.games.nim.example.binary_representation(piles)[source]

Display binary representation of piles for educational purposes.

Parameters:

piles (list[int])

Return type:

None

haive.games.nim.example.calculate_nim_sum(piles)[source]

Calculate the nim-sum (XOR) of pile sizes.

Parameters:

piles (list[int])

Return type:

int

async haive.games.nim.example.example_1_basic_standard_nim()[source]

Example 1: Basic Standard Nim with Optimal Play Strategy.

Demonstrates the fundamental concepts of Nim including: - Standard game rules - Nim-sum calculation - Optimal move selection - Strategic reasoning

async haive.games.nim.example.example_2_misere_nim()[source]

Example 2: Misère Nim with Endgame Analysis.

Demonstrates: - Misère rules (last player loses) - Strategy differences from standard Nim - Endgame analysis with single-stone piles - Transition from normal to misère strategy

async haive.games.nim.example.example_3_mathematical_analysis()[source]

Example 3: Mathematical Analysis of Nim Positions.

Demonstrates: - Nim-sum calculation methods - Position classification (P/N positions) - Optimal move calculation - Mathematical proofs and theorems

async haive.games.nim.example.example_4_game_theory_positions()[source]

Example 4: Game Theory Demonstration with P/N Positions.

Demonstrates: - P-positions (Previous player wins) - N-positions (Next player wins) - Move sequences and transitions - Winning and losing strategies

async haive.games.nim.example.example_5_multiple_pile_variants()[source]

Example 5: Multiple Pile Variants and Strategic Considerations.

Demonstrates: - Games with different numbers of piles - Large pile configurations - Strategic complexity analysis - Computational efficiency

async haive.games.nim.example.example_6_performance_analysis()[source]

Example 6: Performance Analysis and Algorithm Benchmarking.

Demonstrates: - Algorithm efficiency measurement - Performance scaling with problem size - Optimization techniques - Benchmarking results

async haive.games.nim.example.example_7_educational_tutorial()[source]

Example 7: Educational Game Theory Tutorial.

Demonstrates: - Step-by-step learning progression - Mathematical concepts explanation - Interactive analysis - Teaching optimal play

async haive.games.nim.example.example_8_advanced_integration()[source]

Example 8: Advanced Tournament and ML Integration.

Demonstrates: - Tournament systems - Statistical analysis - Machine learning integration concepts - Advanced configuration options

async haive.games.nim.example.main()[source]

Main entry point.

haive.games.nim.example.parse_args()[source]

Parse command line arguments.

haive.games.nim.example.print_section_header(title, subtitle='')[source]

Print a formatted section header.

Parameters:
Return type:

None

haive.games.nim.example.print_subsection(title)[source]

Print a formatted subsection header.

Parameters:

title (str)

Return type:

None

async haive.games.nim.example.run_all_examples()[source]

Run all examples sequentially.