Skip to content

yuyuranium/mancala

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mancala

Simple Mancala game and strategies written in C

Build

make

Game play

After building, run the game with build/mancala

You can either:

  • Specify 2 strategies to match, or
  • Specify 2 player name to match (2P), or
  • Specify 1 strategy and play with it (1P), or
  • Specify 0 strategies and let the game randomly pick 2 strategies to match

Available options

  • -h, --help: Print the help message
  • -q, --quiet: Suppress the output of every round

Example output

./build/mancala chaotic minimal_first
# chaotic vs. minimal_first

[Round 0]
                5     4     3     2     1     0   
              ┌───┐ ┌───┐ ┌───┐ ┌───┐ ┌───┐ ┌───┐ 
        ┌───┐ │  4│ │  4│ │  4│ │  4│ │  4│ │  4│ ┌───┐ 
        │   │ └───┘ └───┘ └───┘ └───┘ └───┘ └───┘ │   │ 
chaotic │  0│                                     │  0│ minimal_first
─────── │   │ ┌───┐ ┌───┐ ┌───┐ ┌───┐ ┌───┐ ┌───┐ │   │ 
        └───┘ │  4│ │  4│ │  4│ │  4│ │  4│ │  4│ └───┘ 
              └───┘ └───┘ └───┘ └───┘ └───┘ └───┘ 
                0     1     2     3     4     5   

>>> chaotic selects 2


[Round 1]
                5     4     3     2     1     0   
              ┌───┐ ┌───┐ ┌───┐ ┌───┐ ┌───┐ ┌───┐ 
        ┌───┐ │  5│ │  5│ │  5│ │  0│ │  4│ │  4│ ┌───┐ 
        │   │ └───┘ └───┘ └───┘ └───┘ └───┘ └───┘ │   │ 
chaotic │  1│                                     │  0│ minimal_first
─────── │   │ ┌───┐ ┌───┐ ┌───┐ ┌───┐ ┌───┐ ┌───┐ │   │ 
        └───┘ │  4│ │  4│ │  4│ │  4│ │  4│ │  4│ └───┘ 
              └───┘ └───┘ └───┘ └───┘ └───┘ └───┘ 
                0     1     2     3     4     5   

>>> chaotic selects 1

...

                5     4     3     2     1     0   
              ┌───┐ ┌───┐ ┌───┐ ┌───┐ ┌───┐ ┌───┐ 
        ┌───┐ │  0│ │  0│ │  0│ │  0│ │  0│ │  0│ ┌───┐ 
        │   │ └───┘ └───┘ └───┘ └───┘ └───┘ └───┘ │   │ 
chaotic │ 18│                                     │ 30│ minimal_first
        │   │ ┌───┐ ┌───┐ ┌───┐ ┌───┐ ┌───┐ ┌───┐ │   │ ═════════════
        └───┘ │  0│ │  0│ │  0│ │  0│ │  0│ │  0│ └───┘ 
              └───┘ └───┘ └───┘ └───┘ └───┘ └───┘ 
                0     1     2     3     4     5   

>>> The winner is minimal_first

Understand the symbols

  • Left/rightmost box: the players' store
  • Numbers above/under the pocket: the pocket index
  • Underline: the active player of the round
  • Double underline: the winner

Add your own strategy

  1. Define your strategy in src/strategies.inc

    E.g., STRATEGY(my_strategy)

  2. Implement and assign your strategy in a C source file

    E.g., in src/my_strategy.c:

    #include "strategy.h"
    
    static int strategy(const mancala_t *game, player_t player)
    {
        /* Implement your strategy here */
    }
    
    strategy_t my_strategy = &strategy;

Match

Use Makefile target, match to run two strategies against each other for multiple times and see the result. The script will alternates the first player.

make match

Available options

  • P1: player 1; defaults to chaotic
  • P2: player 2; defaults to minimal_first
  • ROUNDS: Number of rounds to run; defaults to 100

E.g., matching minimal_first and maximal_first for 1000 times

make match P1=minimal_first P2=maximal_first ROUNDS=1000

About

Simple Mancala game and strategies written in C

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published