Buzzword bingo (also known as bullshit bingo) is a game that finally achieved wild popularity on 22 February 1994, when it was featured in a Dilbert comic strip in which the characters play during an office meeting.
Buzzword bingo is generally played in situations where audience members feel that the speaker, in an effort to mask a lack of actual knowledge, is relying too heavily on buzzwords rather than providing relevant details. Lectures by boring professors or business meetings led by guest speakers or notable company personalities from higher up the pay scale are often viewed as a good opportunity for buzzword bingo, as the language used by these speakers often includes predictable references to arcane concepts, which are perfect for use in the creation of buzzword bingo cards. The idea is that each participant prepares a list of stop words or buzzwords that he expects the speaker will use. These words are written on a bingo card containing a square grid of $$n$$ rows and $$n$$ columns ($$n \in \mathbb{N}$$). For example, the following bingo card could be used to play buzzword bingo in a lecture about genetics.
A participant may tick off a word on his card if it is uttered by the speaker. The goal of the game is to tick off all words in a given row or column, and then yell "Bingo!". Having the courage to actually yell "Bingo!" is an important element of the game. In order to avoid the reprimands that would likely result from doing so, participants may resort to looking at one another and silently mouthing the word "Bingo". An alternate variation requires the person who has achieved bingo to raise his or her hand and use the word "Bingo" within the context of a comment or question.
Write a class BuzzBingo that can be used to instantiate objects that represent the bingo card as used in a buzzword bingo game. The objects of the class BuzzBingo must at least support the following methods.
An initialization method that takes an integer $$n \in \mathbb{N}$$ and a sequence (a list or a tuple) of words. The method must assure that the newly created object of the class BuzzBingo represents a bingo card whose $$n \times n$$ grid is filled with the given sequence of words from left to right and from top to bottom, that allows to cancel words at a later stage. Of course, upon initialization none of the words on the bingo cards is cancelled. In case the number of words in the given sequence does not correspond to the number of squares in the grid, the initialization method must raise an AssertionError with the message invalid card.
The methodes __str__ en __repr__ that both return the same string representation of the object. This string represents a rectangular grid that indicates which words on the bingo card have been cancelled. Words that have been cancelled are represented by the letter x and words that have not been cancelled are represented by a dash (-).
A method cancelWord that can be used to cancel a word on the bingo card. The word to be cancelled must passed as an argument to the method. Apart from the fact that the method must make sure that the object remembers that the given word has been cancelled, it must also return a tuple $$(r, c)$$ that indicates that the given word was found on row $$r$$ and column $$c$$ on the bingo card. The rows of the grid are indexed from left to right, and the columns from top to bottom, starting at zero. In case the given word is not found on the bingo card, the method must raise an AssertionError with the message word not found on card. In case the given word was already cancelled, the method must raise an AssertionError with the message word was already cancelled. In both messages, the given word must be filled in at the position of word.
A method cancelWords that can be used to cancel a sequence of words on the bingo card. The words to be cancelled must passed to the method as a list or a tuple. The method must return a list containig the position where each of the given words was found on the bingo card. The same tuple returned by the method cancelWord must be used to indicate where a word was found on the card.
A method won that can be used to check whether the game has been won based on the words cancelled on the bingo card. The method must return a Boolean value that indicates whether or not the bingo card has a row or a column in which all words have been cancelled.
>>> bingo = BuzzBingo(4, [
... 'cell', 'bacteria', 'PCR', 'virus',
... 'allele', 'chromosome', 'DNA', 'meiosis',
... 'protein', 'phenotype', 'gene', 'mutation',
... 'genome', 'recessive', 'RNA', 'mitosis'
... ])
>>> bingo
----
----
----
----
>>> bingo.won()
False
>>> bingo.cancelWord('phenotype')
(2, 1)
>>> print(bingo)
----
----
-x--
----
>>> bingo.won()
False
>>> bingo.cancelWord('dominant')
Traceback (most recent call last):
AssertionError: dominant not found on card
>>> bingo.cancelWord('phenotype')
Traceback (most recent call last):
AssertionError: phenotype was already cancelled
>>> bingo.cancelWords(['PCR', 'chromosome', 'protein'])
[(0, 2), (1, 1), (2, 0)]
>>> bingo
--x-
-x--
xx--
----
>>> bingo.won()
False
>>> bingo.cancelWords(('recessive', 'bacteria', 'mitosis'))
[(3, 1), (0, 1), (3, 3)]
>>> print(bingo)
-xx-
-x--
xx--
-x-x
>>> bingo.won()
True
>>> bingo = BuzzBingo(2, ('cell', 'bacteria', 'PCR'))
Traceback (most recent call last):
AssertionError: invalid card
>>> bingo = BuzzBingo(2, ['cell', 'bacteria', 'PCR', 'virus', 'allele'])
Traceback (most recent call last):
AssertionError: invalid card