import numpy as np
import pandas as pd
import plotnine as p9
from dataclasses import dataclassIntroduction
During a lunch conversation with some friends, the discussion brought us to reminisce about a childhood game we all used to play: “Guess Who?” (or “¿Quién es quién?” in Spanish). We then argued about the rules of the game and wondered wether a winning strategy could be made or if it was just a matter of luck.

This game is a classic board game where players ask yes/no questions to guess the identity of a character chosen by their opponent. The game is played with a set of characters, each with distinct features, and players take turns asking questions to narrow down the possibilities.
Given this simple setup, a computational implementation of the game seemed like a fairly straightforward task, so I decided to give it a try and here we are.
The goal is to be able to run many simulations of the game with different parameters and strategies and from there infer the best way to play the game. We could try to make some informed guesses and we will elucidate them later, but for now let’s just focus on the implementation of the game and the simulation of the different strategies.
Preamble
Imports
Pre-sets
# Theme for plotnine matching color scheme and font of the website
body_color = '#4C3F2E'
links_color = '#9b8b75d5'
p9.theme_set(
p9.theme_bw() +
p9.theme(
panel_grid_major=p9.element_line(
size=0.5,
color=body_color,
linetype='dashed'),
panel_grid_minor=p9.element_blank(),
legend_background=p9.element_blank(),
plot_background=p9.element_blank(),
panel_background=p9.element_rect(fill="#DBD1B6"),
panel_border=p9.element_rect(color=body_color),
text=p9.element_text(family='Georgia', color=body_color),
))<plotnine.themes.theme.theme at 0x161383e80>
Game Implementation
@dataclass
class Character:
name: str
hair_color: str
eye_color: str
wears_glasses: bool
has_beard: bool
has_hat: bool
has_scarf: bool
def __repr__(self):
return f"Character(name={self.name}, hair={self.hair_color}, eye_color={self.eye_color}, wears_glasses={self.wears_glasses}, has_beard={self.has_beard}, has_hat={self.has_hat}, has_scarf={self.has_scarf})"
def __str__(self):
return f"{self.name} ({self.hair_color}, {self.eye_color}, {self.wears_glasses}, {self.has_beard}, {self.has_hat}, {self.has_scarf})"Character(
name="Alice",
hair_color="brown",
eye_color="blue",
wears_glasses=True,
has_beard=False,
has_hat=False,
has_scarf=False
)Character(name=Alice, hair=brown, eye_color=blue, wears_glasses=True, has_beard=False, has_hat=False, has_scarf=False)