Skip to main content
QUICK REVIEW

[Paper Review] Evolving winning strategies for Nim-like games

Mihai Oltean|arXiv (Cornell University)|Aug 21, 2021
Artificial Intelligence in GamesComputer Science9 references10 citations
TL;DR

This paper proposes an evolutionary approach using Multi Expression Programming (MEP) to automatically discover winning strategies for Nim-like games. By evolving mathematical expressions that classify game positions as P-positions (losing) or N-positions (winning), the method successfully learns the standard XOR-based winning condition in Nim, achieving high success rates across multiple experimental configurations.

ABSTRACT

An evolutionary approach for computing the winning strategy for Nim-like games is proposed in this paper. The winning strategy is computed by using the Multi Expression Programming (MEP) technique - a fast and efficient variant of the Genetic Programming (GP). Each play strategy is represented by a mathematical expression that contains mathematical operators (such as +, -, *, mod, div, and , or, xor, not) and operands (encoding the current game state). Several numerical experiments for computing the winning strategy for the Nim game are performed. The computational effort needed for evolving a winning strategy is reported. The results show that the proposed evolutionary approach is very suitable for computing the winning strategy for Nim-like games.

Motivation & Objective

  • To develop an evolutionary method for discovering winning strategies in Nim-like games without relying on prior theoretical knowledge.
  • To apply Multi Expression Programming (MEP) as a fast and efficient alternative to traditional Genetic Programming for symbolic regression in game theory.
  • To evolve mathematical expressions that correctly classify game states as P-positions (losing) or N-positions (winning) in the Nim game.
  • To evaluate the impact of key algorithmic parameters—population size, generations, and chromosome length—on the success rate of strategy discovery.
  • To demonstrate the generalizability of the approach to other impartial games based on P/N-position theory.

Proposed method

  • Each individual in the population is represented as a chromosome of fixed length, where each gene encodes a terminal (game state variable) or a function (e.g., +, -, *, xor, mod, and, or, not).
  • The MEP representation uses a linear, stack-based encoding where function arguments are referenced by index, ensuring syntactic validity and enabling efficient evaluation of multiple expressions per chromosome.
  • Fitness is assigned based on the accuracy of the evolved expression in classifying all 70 unique game configurations of a (4,4,4,4) Nim game as P- or N-positions.
  • The evolutionary process uses binary tournament selection, 0.9 crossover probability, and 2 mutations per chromosome to maintain diversity and guide convergence.
  • The search is guided toward expressions that return 0 for P-positions and non-zero for N-positions, effectively solving a symbolic regression task with a binary classification target.
  • The method traverses the game tree to identify P/N positions dynamically, avoiding the need for pre-labeled datasets.

Experimental results

Research questions

  • RQ1Can Multi Expression Programming evolve a correct and generalizable winning strategy for the Nim game without prior knowledge of the Grundy-Sprague theory?
  • RQ2How do population size, number of generations, and chromosome length affect the success rate of discovering the winning strategy?
  • RQ3Can the evolved expressions match or generalize beyond the known XOR-based solution for Nim?
  • RQ4Is the MEP-based approach scalable and effective for other impartial games with P/N-position structures?
  • RQ5To what extent can evolutionary computation discover symbolic rules in combinatorial games when theoretical solutions are not known in advance?

Key findings

  • With a population size of 140, the method achieved a success rate of 37 out of 50 runs, demonstrating a strong positive correlation between population size and success rate.
  • After 100 generations, 41 out of 50 runs successfully discovered the winning strategy, indicating high convergence stability under standard settings.
  • The optimal chromosome length was found to be 35 genes, yielding 25 successful runs out of 50, suggesting a trade-off between expression complexity and search efficiency.
  • MEP successfully evolved alternative correct formulas, such as $a_1 \text{ xor } a_2 \text{ xor } a_3 - a_4$, which are mathematically valid due to the properties of the XOR operator.
  • The method achieved high success even with minimal configurations (e.g., 20 individuals), showing robustness and efficiency in small-scale search spaces.
  • The approach is generalizable to other impartial games that rely on P/N-position classification, as the underlying logic of game tree traversal and state evaluation is transferable.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.