Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python - Spot it! Cards

Tags:

python

I am trying to simulate deck of "Spot it!" cards with Python. For those who do not know what "Spot it!" is- it is a popular card game in which there is 55 cards in a deck and each card has 8 random symbols on it (for example a ball, a wave, etc). And each card has exactly 1 symbol in common with any other card. Basically, players draw a card and compare it with the one "common card" (which is visible for everyone) and the player who spots the symbol he/she has in common with the "common card" first, wins.

But I am trying only to generate the deck of cards, not the game itself.

So, let's say I have these items:

a list of symbols:

symbols = ["pelikan", "palma", "rukavnik", "morskyKon", "mraznicka", "kormidlo", "lehatko", "drink", "vedro", "Aloha", "koral", "nanuk", "opalovaciKrem", "Splash!", "plutva", "morskaPanna", "meduza", "krab", "stopa", "Wipeout", "pistol", "zralociaPlutva", "plachetnica", "raketa", "slnko", "sandala", "melon", "harpuna", "stolicka", "zachranneKoleso", "lietajuciTanier", "ryba", "hrad", "kalamar", "fotoaparat", "osuska", "naramok", "sarkan", "kotva", "fakla", "kamene", "snehoveGule", "motyka", "kosatka", "plavky", "odtlacokMusle", "klobuk", "ponorka", "morskyJez", "more", "musla", "slnecnik", "potapacskeOkuliare", "slnecneOkuliare", "majak", "vlna", "lopta"]

a deck of (for now, 6) cards, where each key of the dictionary represents a card and a value of each key is a list of 8 symbols, which is empty for now:

cardDeck = {1: [], 2: [], 3: [], 4:[], 5: [], 6:[]}

generating random symbols for each card so that there are no duplicates

import random
for card, symboly in cardDeck.items():
    symboly = []
    for i in range(8):
        symbol = random.choice(symbols)
        while symbol in symboly:
            symbol = random.choice(symbols)
        symboly.append(symbol)
    cardDeck.update({card : set(symboly)})

And this is where I am stuck - I know what to do, but I don't know if it's possible to do this in Python and if yes, how. I realise that I need to do combinations (every possible pairs) from all cards and then for each combination keep randomly picking symbols until it has exactly 1 common symbol (i.e. the length of intersection of each combination is 1). From what I know, combinations can be easily made by itertools.combinations(cardDeck, 2). Then I was trying execute what I wrote about above, but I somehow dont know how to write it in Python. (I am still more-less learning it and I thought this would be interesting to try in Python.)

Any ideas very much appreciated guys. Thanks in advance.

like image 903
puk789 Avatar asked Feb 11 '23 08:02

puk789


2 Answers

Ok - just did a whole lot of reading on this, and here's the gist:

The game can be understood as the physical expression of a finite projective plane of order 7; 57 cards and 57 symbols, where every pair of cards shares a symbol and every pair of symbols shares a card. For unknown reasons, the manufacturer decided to arbitrarily discard two cards.

(More generally, you can* produce a finite projective plane of any order N == p ** n where p is a prime number and n is a positive integer; the result will have N ** 2 + N + 1 cards, and the same number of symbols, and N+1 symbols will appear on each card.) *This is strongly conjectured, but has only been definitely proven for N <= 11.

What you want to generate is a 57 * 57 incidence matrix - which symbols occur on which cards - which obeys the following rules:

  1. Each row contains exactly 8 1s;
  2. Each column contains exactly 8 1s;
  3. Each pair of rows has exactly 1 1 in common;
  4. Each pair of columns has exactly 1 1 in common.

Edit:

I wrote an algorithm which I calculated would take about 150 days to produce the needed result - it's trickier than it looks ;-)

I then did a bit more searching, and found out the the SAGE math package will do exactly what you need (and MUCH faster):

import sage

sol = sage.combinat.designs.block_design.projective_plane(7)

for row in sol.incidence_matrix().rows():
    print(row)

which takes half a second to produce a solution:

(1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
(1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1)

It is then pretty straight-forward to convert this to the card-game you want:

symbols = sorted(
    [
        "pelikan", "palma", "rukavnik", "morskyKon", "mraznicka", "kormidlo",
        "lehatko", "drink", "vedro", "Aloha", "koral", "nanuk", "opalovaciKrem",
        "Splash!", "plutva", "morskaPanna", "meduza", "krab", "stopa", "Wipeout",
        "pistol", "zralociaPlutva", "plachetnica", "raketa", "slnko", "sandala",
        "melon", "harpuna", "stolicka", "zachranneKoleso", "lietajuciTanier", "ryba",
        "hrad", "kalamar", "fotoaparat", "osuska", "naramok", "sarkan", "kotva",
        "fakla", "kamene", "snehoveGule", "motyka", "kosatka", "plavky",
        "odtlacokMusle", "klobuk", "ponorka", "morskyJez", "more", "musla",
        "slnecnik", "potapacskeOkuliare", "slnecneOkuliare", "majak", "vlna", "lopta"
    ],
    key = str.lower
)

cards = [
    [symbol for symbol, use_it in zip(symbols, row) if use_it]
    for row in sorted(sol.incidence_matrix().rows())
]

which produces

[
    ['Aloha', 'drink', 'fakla', 'fotoaparat', 'harpuna', 'hrad', 'kalamar', 'kamene'],
    ['Aloha', 'klobuk', 'koral', 'kormidlo', 'kosatka', 'kotva', 'krab', 'lehatko'],
    ['Aloha', 'lietajuciTanier', 'lopta', 'majak', 'meduza', 'melon', 'more', 'morskaPanna'],
    ['Aloha', 'morskyJez', 'morskyKon', 'motyka', 'mraznicka', 'musla', 'nanuk', 'naramok'],
    ['Aloha', 'odtlacokMusle', 'opalovaciKrem', 'osuska', 'palma', 'pelikan', 'pistol', 'plachetnica'],
    ['Aloha', 'plavky', 'plutva', 'ponorka', 'potapacskeOkuliare', 'raketa', 'rukavnik', 'ryba'],
    ['Aloha', 'sandala', 'sarkan', 'slnecneOkuliare', 'slnecnik', 'slnko', 'snehoveGule', 'Splash!'],
    ['Aloha', 'stolicka', 'stopa', 'vedro', 'vlna', 'Wipeout', 'zachranneKoleso', 'zralociaPlutva'],
    ['drink', 'klobuk', 'lietajuciTanier', 'morskyJez', 'odtlacokMusle', 'plavky', 'sandala', 'stolicka'],
    ['drink', 'koral', 'majak', 'mraznicka', 'pelikan', 'rukavnik', 'Splash!', 'zralociaPlutva'],
    ['drink', 'kormidlo', 'melon', 'naramok', 'opalovaciKrem', 'potapacskeOkuliare', 'snehoveGule', 'zachranneKoleso'],
    ['drink', 'kosatka', 'morskaPanna', 'motyka', 'pistol', 'plutva', 'slnko', 'vedro'],
    ['drink', 'kotva', 'lopta', 'nanuk', 'osuska', 'ryba', 'slnecnik', 'stopa'],
    ['drink', 'krab', 'meduza', 'morskyKon', 'plachetnica', 'raketa', 'slnecneOkuliare', 'Wipeout'],
    ['drink', 'lehatko', 'more', 'musla', 'palma', 'ponorka', 'sarkan', 'vlna'],
    ['fakla', 'klobuk', 'morskaPanna', 'nanuk', 'pelikan', 'potapacskeOkuliare', 'slnecneOkuliare', 'vlna'],
    ['fakla', 'koral', 'lopta', 'morskyKon', 'opalovaciKrem', 'plutva', 'sarkan', 'stolicka'],
    ['fakla', 'kormidlo', 'meduza', 'musla', 'pistol', 'ryba', 'sandala', 'zralociaPlutva'],
    ['fakla', 'kosatka', 'more', 'morskyJez', 'osuska', 'raketa', 'Splash!', 'zachranneKoleso'],
    ['fakla', 'kotva', 'lietajuciTanier', 'mraznicka', 'plachetnica', 'ponorka', 'snehoveGule', 'vedro'],
    ['fakla', 'krab', 'majak', 'naramok', 'palma', 'plavky', 'slnko', 'stopa'],
    ['fakla', 'lehatko', 'melon', 'motyka', 'odtlacokMusle', 'rukavnik', 'slnecnik', 'Wipeout'],
    ['fotoaparat', 'klobuk', 'more', 'mraznicka', 'opalovaciKrem', 'ryba', 'slnko', 'Wipeout'],
    ['fotoaparat', 'koral', 'lietajuciTanier', 'naramok', 'pistol', 'raketa', 'slnecnik', 'vlna'],
    ['fotoaparat', 'kormidlo', 'majak', 'motyka', 'osuska', 'ponorka', 'slnecneOkuliare', 'stolicka'],
    ['fotoaparat', 'kosatka', 'melon', 'nanuk', 'plachetnica', 'plavky', 'sarkan', 'zralociaPlutva'],
    ['fotoaparat', 'kotva', 'morskaPanna', 'morskyKon', 'palma', 'rukavnik', 'sandala', 'zachranneKoleso'],
    ['fotoaparat', 'krab', 'lopta', 'musla', 'odtlacokMusle', 'potapacskeOkuliare', 'Splash!', 'vedro'],
    ['fotoaparat', 'lehatko', 'meduza', 'morskyJez', 'pelikan', 'plutva', 'snehoveGule', 'stopa'],
    ['harpuna', 'klobuk', 'melon', 'morskyKon', 'pistol', 'ponorka', 'Splash!', 'stopa'],
    ['harpuna', 'koral', 'morskaPanna', 'musla', 'osuska', 'plavky', 'snehoveGule', 'Wipeout'],
    ['harpuna', 'kormidlo', 'lopta', 'morskyJez', 'plachetnica', 'rukavnik', 'slnko', 'vlna'],
    ['harpuna', 'kosatka', 'meduza', 'mraznicka', 'palma', 'potapacskeOkuliare', 'slnecnik', 'stolicka'],
    ['harpuna', 'kotva', 'more', 'naramok', 'odtlacokMusle', 'plutva', 'slnecneOkuliare', 'zralociaPlutva'],
    ['harpuna', 'krab', 'lietajuciTanier', 'motyka', 'pelikan', 'ryba', 'sarkan', 'zachranneKoleso'],
    ['harpuna', 'lehatko', 'majak', 'nanuk', 'opalovaciKrem', 'raketa', 'sandala', 'vedro'],
    ['hrad', 'klobuk', 'meduza', 'naramok', 'osuska', 'rukavnik', 'sarkan', 'vedro'],
    ['hrad', 'koral', 'more', 'motyka', 'plachetnica', 'potapacskeOkuliare', 'sandala', 'stopa'],
    ['hrad', 'kormidlo', 'lietajuciTanier', 'nanuk', 'palma', 'plutva', 'Splash!', 'Wipeout'],
    ['hrad', 'kosatka', 'majak', 'morskyKon', 'odtlacokMusle', 'ryba', 'snehoveGule', 'vlna'],
    ['hrad', 'kotva', 'melon', 'musla', 'pelikan', 'raketa', 'slnko', 'stolicka'],
    ['hrad', 'krab', 'morskaPanna', 'morskyJez', 'opalovaciKrem', 'ponorka', 'slnecnik', 'zralociaPlutva'],
    ['hrad', 'lehatko', 'lopta', 'mraznicka', 'pistol', 'plavky', 'slnecneOkuliare', 'zachranneKoleso'],
    ['kalamar', 'klobuk', 'majak', 'musla', 'plachetnica', 'plutva', 'slnecnik', 'zachranneKoleso'],
    ['kalamar', 'koral', 'melon', 'morskyJez', 'palma', 'ryba', 'slnecneOkuliare', 'vedro'],
    ['kalamar', 'kormidlo', 'morskaPanna', 'mraznicka', 'odtlacokMusle', 'raketa', 'sarkan', 'stopa'],
    ['kalamar', 'kosatka', 'lopta', 'naramok', 'pelikan', 'ponorka', 'sandala', 'Wipeout'],
    ['kalamar', 'kotva', 'meduza', 'motyka', 'opalovaciKrem', 'plavky', 'Splash!', 'vlna'],
    ['kalamar', 'krab', 'more', 'nanuk', 'pistol', 'rukavnik', 'snehoveGule', 'stolicka'],
    ['kalamar', 'lehatko', 'lietajuciTanier', 'morskyKon', 'osuska', 'potapacskeOkuliare', 'slnko', 'zralociaPlutva'],
    ['kamene', 'klobuk', 'lopta', 'motyka', 'palma', 'raketa', 'snehoveGule', 'zralociaPlutva'],
    ['kamene', 'koral', 'meduza', 'nanuk', 'odtlacokMusle', 'ponorka', 'slnko', 'zachranneKoleso'],
    ['kamene', 'kormidlo', 'more', 'morskyKon', 'pelikan', 'plavky', 'slnecnik', 'vedro'],
    ['kamene', 'kosatka', 'lietajuciTanier', 'musla', 'opalovaciKrem', 'rukavnik', 'slnecneOkuliare', 'stopa'],
    ['kamene', 'kotva', 'majak', 'morskyJez', 'pistol', 'potapacskeOkuliare', 'sarkan', 'Wipeout'],
    ['kamene', 'krab', 'melon', 'mraznicka', 'osuska', 'plutva', 'sandala', 'vlna'],
    ['kamene', 'lehatko', 'morskaPanna', 'naramok', 'plachetnica', 'ryba', 'Splash!', 'stolicka']
]
like image 96
Hugh Bothwell Avatar answered Feb 16 '23 02:02

Hugh Bothwell


You can construct the incidence matrix for finite Desarguesian projective planes without trial-and-error. Here's some Python code I've written which has been tested in both Python 2.7 and Python 3.6:

def incidence_matrix(p = 7): # p can be any prime

    # Generate all p^3 - 1 points in affine space, minus the origin:
    points = [(a,b,c) for a in range(p) for b in range(p) for c in range(p)][1::]

    # Quotient by the equivalence relation to give the projective plane points:
    scale = lambda t, k : tuple([((k * v) % p) for v in t])
    canonise = lambda t : (sorted([scale(t, k) for k in range(1, p)])[0])
    points = list(set(map(canonise, points)))

    # We identify each point with its dual line by taking orthogonal complements.
    # A line is incident with a point if the pole of the line is orthogonal to
    # the point, which can be evaluated straightforwardly:
    innerprod = lambda x, y : (sum([a*b for (a, b) in zip(x, y)]) % p)
    imatrix = [[1 if (innerprod(x, y) == 0) else 0 for x in points] for y in points]

    # Output the incidence matrix:
    return imatrix

For projective planes of order-p^n, where n >= 2, it's similar but slightly more complicated: instead of working in the integers modulo p, you need to operate in the finite field F_(p^n). Fortunately for your case, 7 is prime, so the simpler code above will suffice.

like image 43
Adam P. Goucher Avatar answered Feb 16 '23 02:02

Adam P. Goucher