This commit is contained in:
Jonas_Jones 2023-01-24 11:13:46 +01:00
parent 40e3b6cac1
commit 3801ab2697
9 changed files with 1463 additions and 1418 deletions

204
DOKU.txt
View file

@ -1,102 +1,102 @@
7987847, Werner, 7347119, Fajst, 7735965, Melikidze 7987847, Werner, 7347119, Fajst, 7735965, Melikidze
Mit diesem Programm kann man das Kartenspiel "Wizard" spielen. Mit diesem Programm kann man das Kartenspiel "Wizard" spielen.
Es wurde in Python 3.10 entwickelt und wird daher empfohlen. Es wurde in Python 3.10 entwickelt und wird daher empfohlen.
Beim Sart des Programms erscheinen im Terminal die Spielanweisungen, ebenso die empfohlene Terminal Größe, für den MAXIMALEN Spaß. Beim Sart des Programms erscheinen im Terminal die Spielanweisungen, ebenso die empfohlene Terminal Größe, für den MAXIMALEN Spaß.
Der User kann entscheiden, ob er die Spielregeln angezeigt bekommen möchte oder nicht. Falls ja kann er "y" in die Konsole schreiben. Nur Enter drücken genügt auch. Der User kann entscheiden, ob er die Spielregeln angezeigt bekommen möchte oder nicht. Falls ja kann er "y" in die Konsole schreiben. Nur Enter drücken genügt auch.
Die Regeln sehen wiefolgt aus: Die Regeln sehen wiefolgt aus:
How to play: How to play:
1. The goal is to play the highest card. 1. The goal is to play the highest card.
2. The trumpf color outweights all other colors. 2. The trumpf color outweights all other colors.
3. The player who wins the most amounts of tricks (Stiche) wins the game. 3. The player who wins the most amounts of tricks (Stiche) wins the game.
Press ENTER key to continue... Press ENTER key to continue...
Durch das drücken von ENTER, "bestätigt" man die Regeln. Durch das drücken von ENTER, "bestätigt" man die Regeln.
Entscheidet sich der User für "n", dann wird dieses übersprungen und man gelangt zum Game configurator. Entscheidet sich der User für "n", dann wird dieses übersprungen und man gelangt zum Game configurator.
Beim Game Configurator wird der User gefragt, mit wie vielen Spielern er das Spiel spielen möchte. Er kann sich zwischen 1-5 Spielern entscheiden. Beim Game Configurator wird der User gefragt, mit wie vielen Spielern er das Spiel spielen möchte. Er kann sich zwischen 1-5 Spielern entscheiden.
5 Spieler sind inkl. BOTS (d.h. z.B. 3 Spieler, 2 BOTS). 5 Spieler sind inkl. BOTS (d.h. z.B. 3 Spieler, 2 BOTS).
Eingaben außerhalb dieser Range werden Abgefangen. Eingaben außerhalb dieser Range werden Abgefangen.
Die Abfrage sieht wiefolgt aus: Die Abfrage sieht wiefolgt aus:
How many players are playing? How many players are playing?
→ [1 - 5] → [1 - 5]
Nach der Eingabe der Spieleranzahl, kann man zusätzlich BOTS hinzufügen. BOTS legen immer ihre erste Karte, die sie auf der Hand haben. Nach der Eingabe der Spieleranzahl, kann man zusätzlich BOTS hinzufügen. BOTS legen immer ihre erste Karte, die sie auf der Hand haben.
BOTS füllen die Menge der Spieler auf maximal 5. Es kann ebenso nur mit BOTS gespielt werden. BOTS füllen die Menge der Spieler auf maximal 5. Es kann ebenso nur mit BOTS gespielt werden.
Diese Abfrage sieht wiefolgt aus: Diese Abfrage sieht wiefolgt aus:
How many bots should be playing? How many bots should be playing?
→ [1 - 2] (Wenn z.B. bereits 3 Spieler ausgewählt wurden, dann können maximal nur 2 BOTS hinzugefügt werden, weil diese die Spieler auf maximal 5 ergänzen. → [1 - 2] (Wenn z.B. bereits 3 Spieler ausgewählt wurden, dann können maximal nur 2 BOTS hinzugefügt werden, weil diese die Spieler auf maximal 5 ergänzen.
Eingaben außerhalb der Range werden ebenfalls abgefangen. Eingaben außerhalb der Range werden ebenfalls abgefangen.
Nun können sich die Spieler einen Namen aussuchen. (In der Kürze liegt die Würze) Nun können sich die Spieler einen Namen aussuchen. (In der Kürze liegt die Würze)
In dem Spiel bekommen alle Spieler Karten, der Runde entsprechend. D.h. in Runde 4 bekommen alle Spieler 4 random Karten etc. In dem Spiel bekommen alle Spieler Karten, der Runde entsprechend. D.h. in Runde 4 bekommen alle Spieler 4 random Karten etc.
Zu Beginn der Runde wird die Trumpf Karte eingeblendet. Diese wird immer random zu beginn einer neuen Runde ermittelt. Zu Beginn der Runde wird die Trumpf Karte eingeblendet. Diese wird immer random zu beginn einer neuen Runde ermittelt.
Genau so bekommen die Spieler immer random Karten auf die Hand. Genau so bekommen die Spieler immer random Karten auf die Hand.
Nun kann der Spieler seine Karte aussuchen und diese auch legen. Nun kann der Spieler seine Karte aussuchen und diese auch legen.
Die Karten werden numeriert, d.h. um die erste Karte zu legen, schreibt man 1 in die Konsole etc. Die Karten werden numeriert, d.h. um die erste Karte zu legen, schreibt man 1 in die Konsole etc.
Ganz oben in der Mitte des Terminals wird angezeigt, welcher Spieler dran ist. Ebenso in welcher Runde man ist, und der wievielte Stich es in der jetzigen Runde ist. Ganz oben in der Mitte des Terminals wird angezeigt, welcher Spieler dran ist. Ebenso in welcher Runde man ist, und der wievielte Stich es in der jetzigen Runde ist.
Etwas drunter, Rechts sieht man, was die Trumpffarbe für diese Runde ist. Etwas drunter, Rechts sieht man, was die Trumpffarbe für diese Runde ist.
Links werden die Punkte des aktuellen Spielers angezeigt und darunter die Karten auf der Hand. Links werden die Punkte des aktuellen Spielers angezeigt und darunter die Karten auf der Hand.
Das Terminal würde dann in diesem speziellen Fall so aussehen: Das Terminal würde dann in diesem speziellen Fall so aussehen:
Player 'a' is playing in round NO. 1 and trick NO. 1 Player 'a' is playing in round NO. 1 and trick NO. 1
Points of player a: 0 Trumpf: Diamonds ♦ Points of player a: 0 Trumpf: Diamonds ♦
1 1
╔═══╗ ╔═══╗
║ ♠ ║ ║ ♠ ║
║ 5 ║ ║ 5 ║
╚═══╝ ╚═══╝
Choose a card by its number Choose a card by its number
→ [1 - 1] → [1 - 1]
Legen alle Spieler deren Karten, gewinnt den Stich derjenige, mit der Höheren Karte. Trumpf überwiegt jedoch, egal ob die gelegte Karte höher ist, als die Trumpffarbene Karte. Legen alle Spieler deren Karten, gewinnt den Stich derjenige, mit der Höheren Karte. Trumpf überwiegt jedoch, egal ob die gelegte Karte höher ist, als die Trumpffarbene Karte.
Am Ende eines Zyklus (jeder legt eine Karte in einer runde) wird angezeigt, welcher Spieler den Stich gewonnen hat. Ebenso werden die gelegten Karten der Spieler/BOTS angezeigt, Am Ende eines Zyklus (jeder legt eine Karte in einer runde) wird angezeigt, welcher Spieler den Stich gewonnen hat. Ebenso werden die gelegten Karten der Spieler/BOTS angezeigt,
und wieviele Punkte diese haben: und wieviele Punkte diese haben:
a: 1 points a: 0 points s: 1 points Bot 1: 1 points Bot 2: 0 points a: 1 points a: 0 points s: 1 points Bot 1: 1 points Bot 2: 0 points
╔═══╗ ╔═══╗ ╔═══╗ ╔═══╗ ╔═══╗ ╔═══╗ ╔═══╗ ╔═══╗ ╔═══╗ ╔═══╗
║ ♠ ║ ║ ♣ ║ ║ ♣ ║ ║ ♥ ║ ║ ♣ ║ ║ ♠ ║ ║ ♣ ║ ║ ♣ ║ ║ ♥ ║ ║ ♣ ║
║ 5 ║ ║10 ║ ║ 3 ║ ║ 2 ║ ║ 7 ║ ║ 5 ║ ║10 ║ ║ 3 ║ ║ 2 ║ ║ 7 ║
╚═══╝ ╚═══╝ ╚═══╝ ╚═══╝ ╚═══╝ ╚═══╝ ╚═══╝ ╚═══╝ ╚═══╝ ╚═══╝
╔═════════════════════════════════════════════════╗ ╔═════════════════════════════════════════════════╗
║ Congratulations! ║ ║ Congratulations! ║
║ Player 'Bot 2' won the trick! ║ ║ Player 'Bot 2' won the trick! ║
║ Press ENTER to continue... ║ ║ Press ENTER to continue... ║
╚═════════════════════════════════════════════════╝ ╚═════════════════════════════════════════════════╝
Diese Anzeige bleibt, bis der User ENTER drückt. Diese Anzeige bleibt, bis der User ENTER drückt.
Wenn BOTS an der Reihe sind, dann sieht es z.B. so aus: Wenn BOTS an der Reihe sind, dann sieht es z.B. so aus:
$$$$$$$\ $$\ $$$$$$$\ $$\
$$ __$$\ $$ | $$ __$$\ $$ |
$$ | $$ | $$$$$$\ $$$$$$\ $$ | $$ | $$$$$$\ $$$$$$\
$$$$$$$\ |$$ __$$\\_$$ _| $$$$$$$\ |$$ __$$\\_$$ _|
$$ __$$\ $$ / $$ | $$ | $$ __$$\ $$ / $$ | $$ |
$$ | $$ |$$ | $$ | $$ |$$\ $$ | $$ |$$ | $$ | $$ |$$\
$$$$$$$ |\$$$$$$ | \$$$$ | $$$$$$$ |\$$$$$$ | \$$$$ |
\_______/ \______/ \____/ \_______/ \______/ \____/
Am Ende des gesamten Spiels erscheint dieser Screen: Am Ende des gesamten Spiels erscheint dieser Screen:
Congratulations! Congratulations!
Player '<Player>' won the game! Player '<Player>' won the game!
Would you like to play again? Would you like to play again?
→ [Y/n] → [Y/n]
Der User hat die Möglichkeit, das Spiel erneut zu spielen, indem er y in die Konsole eingibt oder ENTER drückt. Der User hat die Möglichkeit, das Spiel erneut zu spielen, indem er y in die Konsole eingibt oder ENTER drückt.

View file

@ -1,258 +1,258 @@
'''EPR 07 Aufgabe 3''' '''EPR 07 Aufgabe 3'''
__author__ = "7987847, Werner, 7347119, Fajst, 7735965, Melikidze" __author__ = "7987847, Werner, 7347119, Fajst, 7735965, Melikidze"
from os import get_terminal_size, name, system from os import get_terminal_size, name, system
from sys import stdout from sys import stdout
class Terminal: class Terminal:
''' '''
Terminal class Terminal class
''' '''
def get_size(): def get_size():
''' '''
Returns the size of the terminal Returns the size of the terminal
output: output:
- columns: int - columns: int
number of columns number of columns
- lines: int - lines: int
number of lines number of lines
''' '''
return get_terminal_size().columns, get_terminal_size().lines return get_terminal_size().columns, get_terminal_size().lines
def get_lines(): def get_lines():
''' '''
Returns the number of lines of the terminal Returns the number of lines of the terminal
output: output:
- lines: int - lines: int
number of lines number of lines
''' '''
return get_terminal_size().lines return get_terminal_size().lines
def get_columns(): def get_columns():
''' '''
Returns the number of columns of the terminal Returns the number of columns of the terminal
output: output:
- columns: int - columns: int
number of columns number of columns
''' '''
return get_terminal_size().columns return get_terminal_size().columns
def clear(): def clear():
''' '''
Clears the terminal Clears the terminal
''' '''
system('cls' if name in ('nt', 'dos') else 'clear') system('cls' if name in ('nt', 'dos') else 'clear')
def curser_to_pos1(): def curser_to_pos1():
''' '''
Moves the curser to the first position Moves the curser to the first position
''' '''
for _ in range(self.get_lines() + 2): for _ in range(self.get_lines() + 2):
stdout.write("\033[F") stdout.write("\033[F")
class Matrix: class Matrix:
''' '''
Matrix class Matrix class
''' '''
def __init__(self): def __init__(self):
self.columns, self.lines = Terminal.get_size() self.columns, self.lines = Terminal.get_size()
self.clear() self.clear()
def clear(self): def clear(self):
''' '''
Clears the matrix Clears the matrix
''' '''
self.matrix = [] self.matrix = []
def refresh(self): def refresh(self):
''' '''
Refreshes the matrix Refreshes the matrix
''' '''
self.columns, self.lines = Terminal.get_size() self.columns, self.lines = Terminal.get_size()
self.clear() self.clear()
for i in range(self.lines): for i in range(self.lines):
self.matrix.append([]) self.matrix.append([])
for _ in range(self.columns): for _ in range(self.columns):
self.matrix[i].append(" ") self.matrix[i].append(" ")
def set_frame(self, x, y, dx, dy, rounded=True, double=False, title=None, def set_frame(self, x, y, dx, dy, rounded=True, double=False, title=None,
alligncenter=True): alligncenter=True):
''' '''
Sets a frame in the matrix Sets a frame in the matrix
input: input:
- x: int - x: int
x position of the frame x position of the frame
- y: int - y: int
y position of the frame y position of the frame
- dx: int - dx: int
width of the frame width of the frame
- dy: int - dy: int
height of the frame height of the frame
- rounded: bool - rounded: bool
if the frame is rounded if the frame is rounded
- double: bool - double: bool
if the frame is double if the frame is double
- title: str - title: str
title of the frame title of the frame
- alligncenter: bool - alligncenter: bool
if the title is alligned to the center if the title is alligned to the center
''' '''
if double: if double:
self.set( x, y, "") self.set( x, y, "")
self.set(x + dx, y, "") self.set(x + dx, y, "")
self.set(x, y + dy, "") self.set(x, y + dy, "")
self.set(x + dx, y + dy, "") self.set(x + dx, y + dy, "")
for i in range(1, dx): for i in range(1, dx):
self.set(x + i, y, "") self.set(x + i, y, "")
self.set(x + i, y + dy, "") self.set(x + i, y + dy, "")
for i in range(1, dy): for i in range(1, dy):
self.set(x, y + i, "") self.set(x, y + i, "")
self.set(x + dx, y + i, "") self.set(x + dx, y + i, "")
else: else:
if rounded: if rounded:
self.set(x, y, "") self.set(x, y, "")
self.set(x + dx, y, "") self.set(x + dx, y, "")
self.set(x, y + dy, "") self.set(x, y + dy, "")
self.set(x + dx, y + dy, "") self.set(x + dx, y + dy, "")
else: else:
self.set(x, y, "") self.set(x, y, "")
self.set(x + dx, y, "") self.set(x + dx, y, "")
self.set(x, y + dy, "") self.set(x, y + dy, "")
self.set(x + dx, y + dy, "") self.set(x + dx, y + dy, "")
for i in range(1, dx): for i in range(1, dx):
self.set(x + i, y, "") self.set(x + i, y, "")
self.set(x + i, y + dy, "") self.set(x + i, y + dy, "")
for i in range(1, dy): for i in range(1, dy):
self.set(x, y + i, "") self.set(x, y + i, "")
self.set(x + dx, y + i, "") self.set(x + dx, y + i, "")
if title is not None: if title is not None:
if alligncenter: if alligncenter:
self.set(x + int(dx / 2) - int(len(title) / 2) - 1, y, self.set(x + int(dx / 2) - int(len(title) / 2) - 1, y,
"" if not double else "") "" if not double else "")
self.set(x + int(dx / 2) + int(len(title) / 2), y, "" if self.set(x + int(dx / 2) + int(len(title) / 2), y, "" if
not double else "") not double else "")
self.set_string(x + int(dx / 2) - int(len(title) / 2), self.set_string(x + int(dx / 2) - int(len(title) / 2),
y, title) y, title)
else: else:
self.set(x + 1, y, "" if not double else "") self.set(x + 1, y, "" if not double else "")
self.set( x + len(title) + 2, y, "" if not double else self.set( x + len(title) + 2, y, "" if not double else
"") "")
self.set_string(x + 2, y, title) self.set_string(x + 2, y, title)
def set_square(self, x, y, dx, dy, char): def set_square(self, x, y, dx, dy, char):
''' '''
Sets a square in the matrix Sets a square in the matrix
input: input:
- x: int - x: int
x position of the square x position of the square
- y: int - y: int
y position of the square y position of the square
- dx: int - dx: int
width of the square width of the square
- dy: int - dy: int
height of the square height of the square
- char: str - char: str
character of the square character of the square
''' '''
for i in range(dx): for i in range(dx):
for j in range(dy): for j in range(dy):
self.set(x + i, y + j, char) self.set(x + i, y + j, char)
def set(self, x, y, value): def set(self, x, y, value):
''' '''
Sets a value in the matrix Sets a value in the matrix
input: input:
- x: int - x: int
x position of the value x position of the value
- y: int - y: int
y position of the value y position of the value
- value: str - value: str
value value
''' '''
try: try:
self.matrix[y][x] = value self.matrix[y][x] = value
except IndexError: except IndexError:
pass pass
def get(self, x, y): def get(self, x, y):
''' '''
Gets a value in the matrix Gets a value in the matrix
input: input:
- x: int - x: int
x position of the value x position of the value
- y: int - y: int
y position of the value y position of the value
output: output:
- value: str - value: str
value value
''' '''
return self.matrix[y][x] return self.matrix[y][x]
def print(self): def print(self):
''' '''
Prints the matrix Prints the matrix
''' '''
for i in range(self.lines): for i in range(self.lines):
for j in range(self.columns): for j in range(self.columns):
print(self.matrix[i][j], end = "") print(self.matrix[i][j], end = "")
print(end = "" if i < self.lines - 1 else "\r") print(end = "" if i < self.lines - 1 else "\r")
def set_string(self, x, y, chars): def set_string(self, x, y, chars):
''' '''
Sets a string in the matrix Sets a string in the matrix
input: input:
- x: int - x: int
x position of the string x position of the string
- y: int - y: int
y position of the string y position of the string
- chars: str - chars: str
string string
''' '''
for i in range(len(chars)): for i in range(len(chars)):
self.set(x + i, y, chars[i]) self.set(x + i, y, chars[i])
def set_string_center(self, y, chars): def set_string_center(self, y, chars):
''' '''
Sets a string in the matrix, alligned to the center Sets a string in the matrix, alligned to the center
input: input:
- y: int - y: int
y position of the string y position of the string
- chars: str - chars: str
string string
''' '''
self.set_string(int(Terminal.get_columns() / 2 - len(chars) / 2), self.set_string(int(Terminal.get_columns() / 2 - len(chars) / 2),
y, chars) y, chars)
def get_matrix(self): def get_matrix(self):
''' '''
Gets the matrix Gets the matrix
output: output:
- matrix: list - matrix: list
matrix matrix
''' '''
return self.matrix return self.matrix
def add_matrix(self, x, y, matrix): def add_matrix(self, x, y, matrix):
''' '''
Adds a matrix to the matrix Adds a matrix to the matrix
input: input:
- x: int - x: int
x position of the matrix x position of the matrix
- y: int - y: int
y position of the matrix y position of the matrix
- matrix: list - matrix: list
matrix matrix
''' '''
for i in range(len(matrix)): for i in range(len(matrix)):
for j in range(len(matrix[i])): for j in range(len(matrix[i])):
self.set(self, x + j, y + i, matrix[i][j]) self.set(self, x + j, y + i, matrix[i][j])
if __name__ == "__main__": if __name__ == "__main__":
term = Terminal() term = Terminal()
term.set_frame(0, 0, term.get_columns(), term.get_lines(), title="Test", term.set_frame(0, 0, term.get_columns(), term.get_lines(), title="Test",
alligncenter=True) alligncenter=True)
term.set_string_center(1, "Hello World!") term.set_string_center(1, "Hello World!")
term.print() term.print()

220
game.py
View file

@ -1,110 +1,110 @@
'''EPR 07 Aufgabe 3''' '''EPR 07 Aufgabe 3'''
__author__ = "7987847, Werner, 7347119, Fajst, 7735965, Melikidze" __author__ = "7987847, Werner, 7347119, Fajst, 7735965, Melikidze"
from random import randint from random import randint
RANKS = ['Ace', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'Jack', 'Queen', RANKS = ['Ace', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'Jack', 'Queen',
'King'] 'King']
SUITS = ['Spades', 'Hearts', 'Diamonds', 'Clubs'] SUITS = ['Spades', 'Hearts', 'Diamonds', 'Clubs']
def create_cards(): def create_cards():
''' '''
Creates a deck of cards Creates a deck of cards
output: output:
- card_deck: list - card_deck: list
list of cards list of cards
''' '''
card_deck = [] card_deck = []
# add every combination of suit and rank to the deck
for suit in SUITS: for suit in SUITS:
for rank in RANKS: for rank in RANKS:
card = {'rank': rank, 'suit': suit} card = {'rank': rank, 'suit': suit}
card_deck.append(card) card_deck.append(card)
return card_deck return card_deck
def deal_cards(card_deck:list, players:int, cards_per_player:int): def deal_cards(card_deck:list, players:int, cards_per_player:int):
''' '''
Deals cards to players Deals cards to players
input: input:
- card_deck: list - card_deck: list
list of cards list of cards
- players: int - players: int
number of players number of players
- cards_per_player: int - cards_per_player: int
number of cards per player number of cards per player
output: output:
- player_cards: tuple - player_cards: tuple
tuple of lists, each list contains the cards of a player tuple of lists, each list contains the cards of a player
''' '''
temp_cards = [] temp_cards = []
for player in range(players): for player in range(players):
temp_cards.append([]) temp_cards.append([])
for _ in range(cards_per_player): for _ in range(cards_per_player):
temp_cards[player].append(card_deck.pop(randint(0, temp_cards[player].append(card_deck.pop(randint(0,
len(card_deck)-1))) len(card_deck)-1)))
while len(temp_cards) < 5: while len(temp_cards) < 5:
temp_cards.append([]) temp_cards.append([])
return (temp_cards[0], temp_cards[1], temp_cards[2], temp_cards[3], return (temp_cards[0], temp_cards[1], temp_cards[2], temp_cards[3],
temp_cards[4]) temp_cards[4])
def compare_cards(cards_to_compare:list, trumpf_color:str): def compare_cards(cards_to_compare:list, trumpf_color:str):
''' '''
Compares the given cards and returns the winner Compares the given cards and returns the winner
input: input:
- cards_to_compare: list - cards_to_compare: list
list of cards to compare list of cards to compare
output: output:
- winner: int - winner: int
index of the winning card index of the winning card
''' '''
winner = 0 winner = 0
trumpf = [] trumpf = []
for i in cards_to_compare: for i in cards_to_compare:
if i.get('suit') == trumpf_color: if i.get('suit') == trumpf_color:
trumpf.append(cards_to_compare.index(i)) trumpf.append(cards_to_compare.index(i))
if len(trumpf) == 1: if len(trumpf) == 1:
return trumpf[0] return trumpf[0]
elif len(trumpf) > 1: elif len(trumpf) > 1:
winner = 0 winner = 0
for j in trumpf: for j in trumpf:
if RANKS.index(cards_to_compare[j].get('rank')) > RANKS.index( if RANKS.index(cards_to_compare[j].get('rank')) > RANKS.index(
cards_to_compare[winner].get('rank')): cards_to_compare[winner].get('rank')):
winner = j winner = j
winner = j winner = j
else: else:
winner = 0 winner = 0
for j in cards_to_compare: for j in cards_to_compare:
if RANKS.index(j.get('rank')) > RANKS.index( if RANKS.index(j.get('rank')) > RANKS.index(
cards_to_compare[winner].get('rank')): cards_to_compare[winner].get('rank')):
winner = cards_to_compare.index(j) winner = cards_to_compare.index(j)
print(winner, j, cards_to_compare) print(winner, j, cards_to_compare)
return winner return winner
if __name__ == '__main__': if __name__ == '__main__':
card_deck = create_cards() card_deck = create_cards()
print(card_deck) print(card_deck)
print(deal_cards(card_deck, 5, 5)) print(deal_cards(card_deck, 5, 5))
if __name__ == '__main__': if __name__ == '__main__':
# Testcases # Testcases
deck = create_cards() deck = create_cards()
print(deck) print(deck)
print(deal_cards(create_cards(), deck, 5)) print(deal_cards(create_cards(), deck, 5))
print(deal_cards(create_cards(), deck, 0)) print(deal_cards(create_cards(), deck, 0))
try: try:
print(deal_cards(create_cards(), deck, 100)) print(deal_cards(create_cards(), deck, 100))
except: except:
print('Exception') print('Exception')
print(compare_cards([{'rank': 'Ace', 'suit': 'Spades'}, {'rank': 'Ace', 'suit': 'Spades'}]), 'Spades') print(compare_cards([{'rank': 'Ace', 'suit': 'Spades'}, {'rank': 'Ace', 'suit': 'Spades'}]), 'Spades')
print(compare_cards([{'rank': 'Ace', 'suit': 'Spades'}, {'rank': 'Ace', 'suit': 'Hearts'}]), 'Hearts') print(compare_cards([{'rank': 'Ace', 'suit': 'Spades'}, {'rank': 'Ace', 'suit': 'Hearts'}]), 'Hearts')
print(compare_cards([{'rank': 'Ace', 'suit': 'Spades'}, {'rank': 'Ace', 'suit': 'Diamond'}]), 'Hearts') print(compare_cards([{'rank': 'Ace', 'suit': 'Spades'}, {'rank': 'Ace', 'suit': 'Diamond'}]), 'Hearts')

View file

@ -1,148 +1,148 @@
'''EPR 07 Aufgabe 3''' '''EPR 07 Aufgabe 3'''
__author__ = "7987847, Werner, 7347119, Fajst, 7735965, Melikidze" __author__ = "7987847, Werner, 7347119, Fajst, 7735965, Melikidze"
class BOT: class BOT:
''' '''
Bot class Bot class
''' '''
def __init__(self, name, bot_number, cards): def __init__(self, name, bot_number, cards):
self.name = name self.name = name
self.cards = cards self.cards = cards
self.points = 0 self.points = 0
self.trumpf = False self.trumpf = False
self.trumpf_color = None self.trumpf_color = None
self.bot_number = bot_number self.bot_number = bot_number
def play_card(self): def play_card(self):
''' '''
Plays a card Plays a card
output: output:
- card: dict - card: dict
card to play card to play
''' '''
return self.cards.pop(0) return self.cards.pop(0)
def add_points(self, points): def add_points(self, points):
''' '''
Adds points to the bot Adds points to the bot
input: input:
- points: int - points: int
points to add points to add
''' '''
self.points += points self.points += points
# Getters # Getters
def get_trumpf_color(self): def get_trumpf_color(self):
''' '''
Returns the trumpf color Returns the trumpf color
output: output:
- trumpf_color: str - trumpf_color: str
trumpf color trumpf color
''' '''
return self.trumpf_color return self.trumpf_color
def get_name(self): def get_name(self):
''' '''
Returns the name of the bot Returns the name of the bot
output: output:
- name: str - name: str
name of the bot name of the bot
''' '''
return self.name return self.name
def get_cards(self): def get_cards(self):
''' '''
Returns the cards of the bot Returns the cards of the bot
output: output:
- cards: list - cards: list
list of cards list of cards
''' '''
return self.cards return self.cards
def get_points(self): def get_points(self):
''' '''
Returns the points of the bot Returns the points of the bot
output: output:
- points: int - points: int
points of the bot points of the bot
''' '''
return self.points return self.points
def get_trumpf(self): def get_trumpf(self):
''' '''
Returns if the bot has trumpf Returns if the bot has trumpf
output: output:
- trumpf: bool - trumpf: bool
if the bot has trumpf if the bot has trumpf
''' '''
return self.trumpf return self.trumpf
def is_bot(self): def is_bot(self):
''' '''
Returns if the player is a bot Returns if the player is a bot
output: output:
- is_bot: bool - is_bot: bool
if the player is a bot if the player is a bot
''' '''
return True return True
def get_bot_number(self): def get_bot_number(self):
''' '''
Returns the bot number Returns the bot number
output: output:
- bot_number: int - bot_number: int
bot number bot number
''' '''
return self.bot_number return self.bot_number
# Setter # Setter
def set_trumpf(self, trumpf): def set_trumpf(self, trumpf):
''' '''
Sets if the bot has trumpf Sets if the bot has trumpf
input: input:
- trumpf: bool - trumpf: bool
if the bot has trumpf if the bot has trumpf
''' '''
self.trumpf = trumpf self.trumpf = trumpf
def set_cards(self, cards): def set_cards(self, cards):
''' '''
Sets the cards of the bot Sets the cards of the bot
input: input:
- cards: list - cards: list
list of cards list of cards
''' '''
self.cards = cards self.cards = cards
def set_points(self, points): def set_points(self, points):
''' '''
Sets the points of the bot Sets the points of the bot
input: input:
- points: int - points: int
points of the bot points of the bot
''' '''
self.points = points self.points = points
def set_trumpf_color(self, trumpf_color): def set_trumpf_color(self, trumpf_color):
''' '''
Sets the trumpf color of the bot Sets the trumpf color of the bot
input: input:
- trumpf_color: str - trumpf_color: str
trumpf color of the bot trumpf color of the bot
''' '''
self.trumpf_color = trumpf_color self.trumpf_color = trumpf_color
def __str__(self): def __str__(self):
return self.name return self.name
if __name__ == "__main__": if __name__ == "__main__":
import game import game
# Create a bot # Create a bot
bot = BOT("Bot", 1, game.create_cards()) bot = BOT("Bot", 1, game.create_cards())
print(bot.get_cards()) print(bot.get_cards())
print(bot.play_card()) print(bot.play_card())
print(bot.get_cards()) print(bot.get_cards())

View file

@ -1,94 +1,94 @@
'''EPR 07 Aufgabe 3''' '''EPR 07 Aufgabe 3'''
__author__ = "7987847, Werner, 7347119, Fajst, 7735965, Melikidze" __author__ = "7987847, Werner, 7347119, Fajst, 7735965, Melikidze"
class PLAYER: class PLAYER:
''' '''
Player class Player class
''' '''
def __init__(self, name, cards): def __init__(self, name, cards):
self.name = name self.name = name
self.cards = cards self.cards = cards
self.points = 0 self.points = 0
self.trumpf = False self.trumpf = False
self.trumpf_color = None self.trumpf_color = None
def get_name(self): def get_name(self):
''' '''
Returns the name of the player Returns the name of the player
output: output:
- name: str - name: str
name of the player name of the player
''' '''
return self.name return self.name
def is_bot(self): def is_bot(self):
''' '''
Returns if the player is a bot Returns if the player is a bot
output: output:
- is_bot: bool - is_bot: bool
if the player is a bot if the player is a bot
''' '''
return False return False
def pop_card(self, card:int): def pop_card(self, card:int):
''' '''
Removes a card from the players cards Removes a card from the players cards
input: input:
- card: int - card: int
index of the card index of the card
''' '''
return self.cards.pop(card) return self.cards.pop(card)
def get_cards(self): def get_cards(self):
''' '''
Returns the cards of the player Returns the cards of the player
output: output:
- cards: list - cards: list
list of cards of the player list of cards of the player
''' '''
return self.cards return self.cards
def add_points(self, points): def add_points(self, points):
''' '''
Adds points to the player Adds points to the player
input: input:
- points: int - points: int
points to add points to add
''' '''
self.points += points self.points += points
def get_points(self): def get_points(self):
''' '''
Returns the points of the player Returns the points of the player
output: output:
- points: int - points: int
points of the player points of the player
''' '''
return self.points return self.points
def add_card(self, card): def add_card(self, card):
''' '''
Adds a card to the players cards Adds a card to the players cards
input: input:
- card: dict - card: dict
card to add card to add
''' '''
self.cards.append(card) self.cards.append(card)
def set_cards(self, cards): def set_cards(self, cards):
''' '''
Sets the cards of the player Sets the cards of the player
input: input:
- cards: list - cards: list
list of cards list of cards
''' '''
self.cards = cards self.cards = cards
if __name__ == "__main__": if __name__ == "__main__":
import game import game
player = PLAYER("Bot", 1, game.create_cards()) player = PLAYER("Bot", 1, game.create_cards())
print(player.get_cards()) print(player.get_cards())
print(player.play_card()) print(player.play_card())
print(player.get_cards()) print(player.get_cards())

365
main.py
View file

@ -1,160 +1,205 @@
'''EPR 07 Aufgabe 3''' '''EPR 07 Aufgabe 3'''
__author__ = "7987847, Werner, 7347119, Fajst, 7735965, Melikidze" __author__ = "7987847, Werner, 7347119, Fajst, 7735965, Melikidze"
from time import sleep from time import sleep
from random import randint from random import randint
from cmd_interface import Matrix, Terminal from cmd_interface import Matrix, Terminal
import screen_handler import screen_handler
import game import game
from game_bot import BOT from game_bot import BOT
from game_player import PLAYER from game_player import PLAYER
screen = Matrix() # initialize screen
screen = Matrix()
NO = ["n", 'N', 'no', 'No', 'NO', 'nO','']
YES = ["y", 'Y', 'yes', 'Yes', 'YES', 'yES','yEs','YeS','yES', ''] NO = ["n", 'N', 'no', 'No', 'NO', 'nO','']
YES = ["y", 'Y', 'yes', 'Yes', 'YES', 'yES','yEs','YeS','yES', '']
PREVIOUS_CONFIG = None
PREVIOUS_CONFIG = None
def main(first_time:bool=True, previous_config = None):
''' def main(first_time:bool=True, previous_config = None):
The main function of the game '''
input: The main function of the game
- first_time: bool input:
if the game is started for the first time - first_time: bool
- previous_config: list if the game is started for the first time
previous config of the game - previous_config: list
previous config of the game
output:
- previous_config: list output:
previous config of the game - previous_config: list
''' previous config of the game
if first_time: '''
screen.refresh() # welcome screen - only shown on first start
screen.set_frame(int(Terminal.get_columns() / 2 - 25), if first_time:
int(Terminal.get_lines() / 2 - 10), 50, 20, rounded=True, screen.refresh()
title="Welcome to the game") screen.set_frame(int(Terminal.get_columns() / 2 - 25),
screen.set_string_center(int(Terminal.get_lines() /2 - 7), int(Terminal.get_lines() / 2 - 10), 50, 20, rounded=True,
"Follow these instructions") title="Welcome to the game")
screen.set_string_center(int(Terminal.get_lines() /2 - 6), screen.set_string_center(int(Terminal.get_lines() /2 - 7),
"for an enhanced gaming experience:") "Follow these instructions")
screen.set_string_center(int(Terminal.get_lines() /2 - 4), screen.set_string_center(int(Terminal.get_lines() /2 - 6),
"1. Make sure your terminal is") "for an enhanced gaming experience:")
screen.set_string_center(int(Terminal.get_lines() /2 - 3), screen.set_string_center(int(Terminal.get_lines() /2 - 4),
" fullscreen or at least 80x24") "1. Make sure your terminal is")
screen.set_string_center(int(Terminal.get_lines() /2), screen.set_string_center(int(Terminal.get_lines() /2 - 3),
"2. Make sure to not resize your") " fullscreen or at least 80x24")
screen.set_string_center(int(Terminal.get_lines() /2 + 1), screen.set_string_center(int(Terminal.get_lines() /2),
" terminal during gameplay") "2. Make sure to not resize your")
screen.set_string_center(int(Terminal.get_lines() /2 + 4), screen.set_string_center(int(Terminal.get_lines() /2 + 1),
"Your terminal currently has the size:") " terminal during gameplay")
screen.set_string_center(int(Terminal.get_lines() /2 + 5), screen.set_string_center(int(Terminal.get_lines() /2 + 4),
f"{Terminal.get_columns()}x{Terminal.get_lines()}") "Your terminal currently has the size:")
screen.set_string_center(int(Terminal.get_lines() /2 + 7), screen.set_string_center(int(Terminal.get_lines() /2 + 5),
"If your terminal is not fullscreen or") f"{Terminal.get_columns()}x{Terminal.get_lines()}")
screen.set_string_center(int(Terminal.get_lines() /2 + 8), screen.set_string_center(int(Terminal.get_lines() /2 + 7),
"at least 80x28, the game will pause") "If your terminal is not fullscreen or")
screen.set_string_center(int(Terminal.get_lines() /2 + 9), screen.set_string_center(int(Terminal.get_lines() /2 + 8),
"and display an error message until resolved") "at least 80x28, the game will pause")
if screen_handler.console_input( screen.set_string_center(int(Terminal.get_lines() /2 + 9),
"Would you like to check out the rules of the game?", "[Y/n]", "and display an error message until resolved")
screen) in YES: # ask if user wants to see the rules
screen_handler.game_rules(screen) if screen_handler.console_input(
screen.refresh() "Would you like to check out the rules of the game?", "[Y/n]",
if previous_config is not None and screen_handler.console_input( screen) in YES:
"Would you like to reuse the configuration from the last game?", screen_handler.game_rules(screen)
"[Y/n]", screen) in YES: screen.refresh()
pass # ask if user wants to reuse the previous config
else: # only shown if the game is not started for the first time
previous_config = screen_handler.config_sequence(screen) if previous_config is not None and screen_handler.console_input(
"Would you like to reuse the configuration from the last game?",
screen.refresh() "[Y/n]", screen) in YES:
screen.print() pass
else:
players = [] # else show config screen
for i in range(0, int(previous_config[1])): previous_config = screen_handler.config_sequence(screen)
players.append(PLAYER(screen_handler.console_input( # previous_config = ['', <Player count>, '<Bot Count>']
f'Name for Player {i + 1}: In der kürze liegt die Würze \
(In short lies the spice :) )', '', screen=screen), [])) screen.refresh()
for i in range(0, int(previous_config[2])): screen.print()
players.append(BOT(f'Bot {i + 1}', i + 1, []))
# game initialization
screen.refresh() # create players and bots
players = []
screen_handler.starting_screen(screen, players)
# create players
sleep(1) # Ask for player names, set cards to empty list
# PLAYER(name, cards)
screen.refresh() for i in range(0, int(previous_config[1])):
players.append(PLAYER(screen_handler.console_input(
max_turns = int(52 / len(players)) f'Name for Player {i + 1}: In der kürze liegt die Würze \
# debug to shorten game (In short lies the spice :) )', '', screen=screen), []))
# max_turns = 3 # create bots
# set cards to empty list
for turn in range(1, max_turns): # id is number of the bot starting from 1
SUITS = ['Spades', 'Hearts', 'Diamonds', 'Clubs'] # name is Bot <id>
SUITS_SYM = ["", "", "", ""] # BOT(name, id, cards)
trumpf_color = SUITS[randint(0, 3)] for i in range(0, int(previous_config[2])):
players.append(BOT(f'Bot {i + 1}', i + 1, []))
screen_handler.trumpf_screen(screen, trumpf_color)
sleep(2) screen.refresh()
# starting screen with player names
card_deck = game.create_cards() screen_handler.starting_screen(screen, players)
dealt_cards = game.deal_cards(card_deck, int(previous_config[1]) +
int(previous_config[2]), turn) sleep(1)
for player in players: screen.refresh()
player.set_cards(dealt_cards[players.index(player)])
# determine the amount of turns
cards = [] # 52 cards per card deck
for stiche in range(0, turn): max_turns = int(52 / len(players))
cards = [] # debug to shorten game
for player in players: # max_turns = 3
if player.is_bot():
cards.append(screen_handler.bot_interface(screen, player, # main game loop
turn, stiche + 1)) for turn in range(1, max_turns):
sleep(0.5) SUITS = ['Spades', 'Hearts', 'Diamonds', 'Clubs']
else: SUITS_SYM = ["", "", "", ""]
cards.append(screen_handler.player_interface( # determine trumpf color for this turn
screen, player, turn, stiche + 1, trumpf_color, # is determined randomly
SUITS_SYM[SUITS.index(trumpf_color)])) trumpf_color = SUITS[randint(0, 3)]
print(cards)
winner = game.compare_cards(cards, trumpf_color) # show trumpf screen
players[winner].add_points(1) screen_handler.trumpf_screen(screen, trumpf_color)
sleep(2)
screen_handler.stich_win_screen(screen, players[winner], players,
cards, trumpf_color, SUITS_SYM[SUITS.index(trumpf_color)]) # create and deal cards
card_deck = game.create_cards()
# deal_cards(card_deck, amount, turn)
# determine winner # dealt_cards is a tuple of lists
winner = players[0] dealt_cards = game.deal_cards(card_deck, int(previous_config[1]) +
for player in players: int(previous_config[2]), turn)
if player.get_points() > winner.get_points():
winner = player # set cards for each player
screen_handler.winner_screen(screen, winner, players) for player in players:
player.set_cards(dealt_cards[players.index(player)])
# trick loop
# cards is the list of played cards in the order of the players
cards = []
for stiche in range(0, turn):
return previous_config cards = []
# each player plays a card
for player in players:
# if player is a bot, use bot interface
if __name__ == "__main__": if player.is_bot():
try: cards.append(screen_handler.bot_interface(screen, player,
PREVIOUS_CONFIG = main() turn, stiche + 1))
while screen_handler.console_input("Would you like to play again?", sleep(0.5)
"[Y/n]", screen) in YES: # else use player interface
screen.refresh() else:
PREVIOUS_CONFIG = main(first_time=False, cards.append(screen_handler.player_interface(
previous_config=PREVIOUS_CONFIG) screen, player, turn, stiche + 1, trumpf_color,
except KeyboardInterrupt: SUITS_SYM[SUITS.index(trumpf_color)]))
pass # both the bot and the player interface return the played card
Terminal.clear() # determine winner of the trick
print("Thank you for playing!") winner = game.compare_cards(cards, trumpf_color)
players[winner].add_points(1)
# show trick winner
screen_handler.stich_win_screen(screen, players[winner], players,
cards, trumpf_color, SUITS_SYM[SUITS.index(trumpf_color)])
# determine winner
winner = players[0]
for player in players:
if player.get_points() > winner.get_points():
winner = player
screen_handler.winner_screen(screen, winner, players)
return previous_config
if __name__ == "__main__":
try:
# run the game
PREVIOUS_CONFIG = main()
# main() returns the previous config
# ask if user wants to play again
# repeat until user does not want to play again
while screen_handler.console_input("Would you like to play again?",
"[Y/n]", screen) in YES:
screen.refresh()
# run the game again with the previous config
PREVIOUS_CONFIG = main(first_time=False,
previous_config=PREVIOUS_CONFIG)
# if user presses ctrl + c (keyboard interrupt), exit the game
except KeyboardInterrupt:
pass
# clear the terminal and print a thank you message
Terminal.clear()
print("Thank you for playing!")

View file

@ -1,100 +1,100 @@
'''EPR 07 Aufgabe 1''' '''EPR 07 Aufgabe 1'''
__author__ = "7987847, Werner, 7347119, Fajst, 7735965, Melikidze" __author__ = "7987847, Werner, 7347119, Fajst, 7735965, Melikidze"
import re import re
# a) All character strings between < and the next >. # a) All character strings between < and the next >.
# The two < and > can also be output. Example: <a>, <span …>. # The two < and > can also be output. Example: <a>, <span …>.
# b) All (annual) numbers between 1900 and 2099. # b) All (annual) numbers between 1900 and 2099.
def extract_annual(text): def extract_annual(text):
''' '''
Extract all annual numbers between 1900 and 2099. Extract all annual numbers between 1900 and 2099.
Return a list of strings. Return a list of strings.
valid years are 1900-2099 valid years are 1900-2099
''' '''
# Extract all annual numbers between 1900 and 2099. # Extract all annual numbers between 1900 and 2099.
# Return a list of strings. # Return a list of strings.
# valid years are 1900-2099 # valid years are 1900-2099
return re.findall(r'19[0-9][0-9]|20[0-9][0-9]', text) return re.findall(r'19[0-9][0-9]|20[0-9][0-9]', text)
# return re.findall(r'\b(19|20)\d\d\b', text) # return re.findall(r'\b(19|20)\d\d\b', text)
def extract_tags(text): def extract_tags(text):
''' '''
Extract all tags. Extract all tags.
Return a list of strings. Return a list of strings.
''' '''
# Extract all tags. # Extract all tags.
# Return a list of strings. # Return a list of strings.
return re.findall(r'<[^>]+>', text) return re.findall(r'<[^>]+>', text)
def extract_strings(text): def extract_strings(text):
''' '''
Extract all strings outside that are between > and <. Extract all strings outside that are between > and <.
Return a list of strings. Return a list of strings.
''' '''
# Extract all strings outside that are between > and <. # Extract all strings outside that are between > and <.
# Return a list of strings. # Return a list of strings.
return re.findall(r'>([^<]+)<', text) return re.findall(r'>([^<]+)<', text)
def main(): def main():
''' '''
Main function. Main function.
''' '''
# open file # open file
with open('PythonEntwicklungG.txt', 'r') as file: with open('PythonEntwicklungG.txt', 'r') as file:
# read a list of lines into data # read a list of lines into data
data = file.readlines() data = file.readlines()
file.close() file.close()
data_extracted = [] data_extracted = []
for line in data: for line in data:
tag_list = extract_tags(line) tag_list = extract_tags(line)
if tag_list: if tag_list:
data_extracted.append(tag_list) data_extracted.append(tag_list)
strings_list = extract_strings(line) strings_list = extract_strings(line)
if strings_list: if strings_list:
data_extracted.append(strings_list) data_extracted.append(strings_list)
annual_list = extract_annual(line) annual_list = extract_annual(line)
if annual_list: if annual_list:
data_extracted.append(annual_list) data_extracted.append(annual_list)
for _ in data_extracted: for _ in data_extracted:
if type(_) == list: if type(_) == list:
for __ in _: for __ in _:
# check the type of the element # check the type of the element
try: try:
if type(int(__)) == int: if type(int(__)) == int:
# print with formatted tab spacing and color in Red # print with formatted tab spacing and color in Red
print( print(
f'{__:<110} <--- is an annual number', f'{__:<110} <--- is an annual number',
end='\t\n') end='\t\n')
elif type(__) == str: elif type(__) == str:
# check if the string is a tag # check if the string is a tag
if __.startswith('<') and __.endswith('>'): if __.startswith('<') and __.endswith('>'):
print( print(
f'{__:<110} <--- is a Tag string', f'{__:<110} <--- is a Tag string',
end='\t\n') end='\t\n')
else: else:
print(f'{__:<110} <--- is a string', print(f'{__:<110} <--- is a string',
end='\t\n') end='\t\n')
except ValueError: except ValueError:
if __.startswith('<') and __.endswith('>'): if __.startswith('<') and __.endswith('>'):
print(f'{__:<110} <--- is a Tag string', print(f'{__:<110} <--- is a Tag string',
end='\t\n') end='\t\n')
else: else:
print(f'{__:<110} <--- is a string', end='\t\n') print(f'{__:<110} <--- is a string', end='\t\n')
else: else:
print(_) print(_)
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -1,418 +1,418 @@
'''EPR 07 Aufgabe 3''' '''EPR 07 Aufgabe 3'''
__author__ = "7987847, Werner, 7347119, Fajst, 7735965, Melikidze" __author__ = "7987847, Werner, 7347119, Fajst, 7735965, Melikidze"
from time import sleep from time import sleep
from cmd_interface import Matrix, Terminal from cmd_interface import Matrix, Terminal
from game_player import PLAYER from game_player import PLAYER
from game_bot import BOT from game_bot import BOT
def console_input(text:str, input_str:str, screen:Matrix, fullscreen=False): def console_input(text:str, input_str:str, screen:Matrix, fullscreen=False):
''' '''
Prints a text and waits for user input Prints a text and waits for user input
input: input:
- text: str - text: str
text to print text to print
- input_str: str - input_str: str
input string input string
- screen: Matrix - screen: Matrix
screen to print on screen to print on
- fullscreen: bool - fullscreen: bool
if the screen is fullscreen if the screen is fullscreen
output: output:
- input: str - input: str
user input user input
''' '''
screen.set_string(2, Terminal.get_lines() - 2, text) screen.set_string(2, Terminal.get_lines() - 2, text)
screen.set(0, Terminal.get_lines() - 2, "") screen.set(0, Terminal.get_lines() - 2, "")
screen.set_string(0, Terminal.get_lines() - 3, screen.set_string(0, Terminal.get_lines() - 3,
"╭─────────────────────────── ── ── ─ ─ ─") "╭─────────────────────────── ── ── ─ ─ ─")
if fullscreen: if fullscreen:
screen.set_string(0, Terminal.get_lines() - 3, screen.set_string(0, Terminal.get_lines() - 3,
"├─────────────────────────── ── ── ─ ─ ─") "├─────────────────────────── ── ── ─ ─ ─")
screen.set_string(0, Terminal.get_lines() - 1, screen.set_string(0, Terminal.get_lines() - 1,
" ─ ─ ─ ── ── ") " ─ ─ ─ ── ── ")
screen.print() screen.print()
return input("╰→ " + input_str + " ") return input("╰→ " + input_str + " ")
def game_rules(screen:Matrix): def game_rules(screen:Matrix):
''' '''
Prints the game rules Prints the game rules
input: input:
- screen: Matrix - screen: Matrix
screen to print on screen to print on
''' '''
screen.refresh() screen.refresh()
screen.set_frame(0, 0, Terminal.get_columns() - 1, screen.set_frame(0, 0, Terminal.get_columns() - 1,
Terminal.get_lines() - 1, rounded=True, title="Game Rules") Terminal.get_lines() - 1, rounded=True, title="Game Rules")
screen.set_string(2, int(Terminal.get_lines() /2 - 6), "How to play:") screen.set_string(2, int(Terminal.get_lines() /2 - 6), "How to play:")
screen.set_string(2, int(Terminal.get_lines() /2 - 5), screen.set_string(2, int(Terminal.get_lines() /2 - 5),
"1. The goal is to play the highest card.") "1. The goal is to play the highest card.")
screen.set_string(2, int(Terminal.get_lines() /2 - 4), screen.set_string(2, int(Terminal.get_lines() /2 - 4),
"2. The trumpf color outweights all other colors.") "2. The trumpf color outweights all other colors.")
screen.set_string(2, int(Terminal.get_lines() /2 - 3), screen.set_string(2, int(Terminal.get_lines() /2 - 3),
"3. The player who wins the most amounts of tricks\ "3. The player who wins the most amounts of tricks\
(Stiche) wins the game.") (Stiche) wins the game.")
screen.set_string(2, int(Terminal.get_lines() /2 + 3), screen.set_string(2, int(Terminal.get_lines() /2 + 3),
"Press ENTER key to continue...") "Press ENTER key to continue...")
screen.print() screen.print()
input() input()
def config_sequence(screen:Matrix): def config_sequence(screen:Matrix):
''' '''
Prints the game configuration sequence Prints the game configuration sequence
input: input:
- screen: Matrix - screen: Matrix
screen to print on screen to print on
output: output:
- config: list - config: list
list of the game configuration list of the game configuration
''' '''
screen.refresh() screen.refresh()
screen.set_frame(int(Terminal.get_columns() / 2 - 25), screen.set_frame(int(Terminal.get_columns() / 2 - 25),
int(Terminal.get_lines() / 2 - 10), 50, 20, rounded=True, int(Terminal.get_lines() / 2 - 10), 50, 20, rounded=True,
title="Game Configuration") title="Game Configuration")
screen.set_string_center(int(Terminal.get_lines() /2 - 6), screen.set_string_center(int(Terminal.get_lines() /2 - 6),
"Please answer the questions below:") "Please answer the questions below:")
config = ['', '1', '1'] config = ['', '1', '1']
question_possible_asnwers = ['0 - 5', ''] question_possible_asnwers = ['0 - 5', '']
previous_question = "" previous_question = ""
question_no = 0 question_no = 0
for i in ['How many players are playing?', for i in ['How many players are playing?',
'How many bots should be playing?']: 'How many bots should be playing?']:
wrong_input = True wrong_input = True
while wrong_input: while wrong_input:
screen.set_string(int(Terminal.get_columns() / 2 - 24), screen.set_string(int(Terminal.get_columns() / 2 - 24),
int(Terminal.get_lines() /2 - 4 + question_no), int(Terminal.get_lines() /2 - 4 + question_no),
" ") " ")
screen.set_string(int(Terminal.get_columns() / 2 - 24), screen.set_string(int(Terminal.get_columns() / 2 - 24),
int(Terminal.get_lines() /2 - 2 + question_no), int(Terminal.get_lines() /2 - 2 + question_no),
" ") " ")
screen.set_string_center(int(Terminal.get_lines() /2 - 4 +\ screen.set_string_center(int(Terminal.get_lines() /2 - 4 +\
question_no), previous_question + " " + config[question_no]) question_no), previous_question + " " + config[question_no])
screen.set_string_center(int(Terminal.get_lines() /2 - 2 +\ screen.set_string_center(int(Terminal.get_lines() /2 - 2 +\
question_no), i) question_no), i)
screen.set_frame(int(Terminal.get_columns() / 2 - 24), screen.set_frame(int(Terminal.get_columns() / 2 - 24),
int(Terminal.get_lines() / 2 - 3 + question_no), int(Terminal.get_lines() / 2 - 3 + question_no),
48, 2,double=True) 48, 2,double=True)
input = console_input(i, "[" +\ input = console_input(i, "[" +\
question_possible_asnwers[question_no] + "]", screen) question_possible_asnwers[question_no] + "]", screen)
if input.isdigit(): if input.isdigit():
if int(question_possible_asnwers[question_no].split(" - ")[0])\ if int(question_possible_asnwers[question_no].split(" - ")[0])\
<= int(input) <=\ <= int(input) <=\
int(question_possible_asnwers[question_no].split(" - "\ int(question_possible_asnwers[question_no].split(" - "\
)[1]): )[1]):
wrong_input = False wrong_input = False
config[question_no + 1] = input config[question_no + 1] = input
previous_question = i previous_question = i
question_no += 1 question_no += 1
question_possible_asnwers[1] = f"{'0' if config[1] == '5' else '2' if config[1] == '0' else '1'} -\ question_possible_asnwers[1] = f"{'0' if config[1] == '5' else '2' if config[1] == '0' else '1'} -\
{5 - int(config[1])}" {5 - int(config[1])}"
return config return config
def starting_screen(screen:Matrix, players:list): def starting_screen(screen:Matrix, players:list):
''' '''
Prints the starting screen Prints the starting screen
input: input:
- screen: Matrix - screen: Matrix
screen to print on screen to print on
- players: list - players: list
list of the players list of the players
''' '''
screen.refresh() screen.refresh()
screen.set_frame(int(Terminal.get_columns() / 2 - 25), screen.set_frame(int(Terminal.get_columns() / 2 - 25),
int(Terminal.get_lines() / 2 - 10), 50, 20, rounded=True, int(Terminal.get_lines() / 2 - 10), 50, 20, rounded=True,
title="Preparing...") title="Preparing...")
screen.set_string_center(int(Terminal.get_lines() /2 - 6), screen.set_string_center(int(Terminal.get_lines() /2 - 6),
"The game is starting...") "The game is starting...")
screen.set_string_center(int(Terminal.get_lines() /2 - 4), screen.set_string_center(int(Terminal.get_lines() /2 - 4),
"Here are the players:") "Here are the players:")
for i in range(len(players)): for i in range(len(players)):
screen.set_string_center(int(Terminal.get_lines() /2 - 3 + i), screen.set_string_center(int(Terminal.get_lines() /2 - 3 + i),
players[i].get_name()) players[i].get_name())
screen.print() screen.print()
def add_bot_font(screen:Matrix, bot:int): def add_bot_font(screen:Matrix, bot:int):
''' '''
Adds the bot font to the screen Adds the bot font to the screen
input: input:
- screen: Matrix - screen: Matrix
screen to print on screen to print on
- bot: int - bot: int
bot number bot number
''' '''
line_1 = "$$$$$$$\ $$\ " line_1 = "$$$$$$$\ $$\ "
line_2 = "$$ __$$\ $$ | " line_2 = "$$ __$$\ $$ | "
line_3 = "$$ | $$ | $$$$$$\ $$$$$$\ " line_3 = "$$ | $$ | $$$$$$\ $$$$$$\ "
line_4 = "$$$$$$$\ |$$ __$$\\_$$ _| " line_4 = "$$$$$$$\ |$$ __$$\\_$$ _| "
line_5 = "$$ __$$\ $$ / $$ | $$ | " line_5 = "$$ __$$\ $$ / $$ | $$ | "
line_6 = "$$ | $$ |$$ | $$ | $$ |$$\ " line_6 = "$$ | $$ |$$ | $$ | $$ |$$\ "
line_7 = "$$$$$$$ |\$$$$$$ | \$$$$ | " line_7 = "$$$$$$$ |\$$$$$$ | \$$$$ | "
line_8 = "\_______/ \______/ \____/ " line_8 = "\_______/ \______/ \____/ "
if bot == 1: if bot == 1:
screen.set_string_center(4, line_1 + " $$\ ") screen.set_string_center(4, line_1 + " $$\ ")
screen.set_string_center(5, line_2 + " $$$$ | ") screen.set_string_center(5, line_2 + " $$$$ | ")
screen.set_string_center(6, line_3 + " \_$$ | ") screen.set_string_center(6, line_3 + " \_$$ | ")
screen.set_string_center(7, line_4 + " $$ | ") screen.set_string_center(7, line_4 + " $$ | ")
screen.set_string_center(8, line_5 + " $$ | ") screen.set_string_center(8, line_5 + " $$ | ")
screen.set_string_center(9, line_6 + " $$ | ") screen.set_string_center(9, line_6 + " $$ | ")
screen.set_string_center(10, line_7 + " $$$$$$\ ") screen.set_string_center(10, line_7 + " $$$$$$\ ")
screen.set_string_center(11, line_8 + " \______|") screen.set_string_center(11, line_8 + " \______|")
elif bot == 2: elif bot == 2:
screen.set_string_center(4, line_1 + " $$$$$$\ ") screen.set_string_center(4, line_1 + " $$$$$$\ ")
screen.set_string_center(5, line_2 + "$$ __$$\ ") screen.set_string_center(5, line_2 + "$$ __$$\ ")
screen.set_string_center(6, line_3 + "\__/ $$ |") screen.set_string_center(6, line_3 + "\__/ $$ |")
screen.set_string_center(7, line_4 + " $$$$$$ |") screen.set_string_center(7, line_4 + " $$$$$$ |")
screen.set_string_center(8, line_5 + "$$ ____/ ") screen.set_string_center(8, line_5 + "$$ ____/ ")
screen.set_string_center(9, line_6 + "$$ | ") screen.set_string_center(9, line_6 + "$$ | ")
screen.set_string_center(10, line_7 + "$$$$$$$$\ ") screen.set_string_center(10, line_7 + "$$$$$$$$\ ")
screen.set_string_center(11, line_8 + "\________|") screen.set_string_center(11, line_8 + "\________|")
elif bot == 3: elif bot == 3:
screen.set_string_center(4, line_1 + " $$$$$$\ ") screen.set_string_center(4, line_1 + " $$$$$$\ ")
screen.set_string_center(5, line_2 + "$$ ___$$\ ") screen.set_string_center(5, line_2 + "$$ ___$$\ ")
screen.set_string_center(6, line_3 + "\_/ $$ |") screen.set_string_center(6, line_3 + "\_/ $$ |")
screen.set_string_center(7, line_4 + " $$$$$ / ") screen.set_string_center(7, line_4 + " $$$$$ / ")
screen.set_string_center(8, line_5 + " \___$$\ ") screen.set_string_center(8, line_5 + " \___$$\ ")
screen.set_string_center(9, line_6 + "$$\ $$ |") screen.set_string_center(9, line_6 + "$$\ $$ |")
screen.set_string_center(10, line_7 + "\$$$$$$ |") screen.set_string_center(10, line_7 + "\$$$$$$ |")
screen.set_string_center(11, line_8 + " \______/ ") screen.set_string_center(11, line_8 + " \______/ ")
elif bot == 4: elif bot == 4:
screen.set_string_center(4, line_1 + "$$\ $$\ ") screen.set_string_center(4, line_1 + "$$\ $$\ ")
screen.set_string_center(5, line_2 + "$$ | $$ |") screen.set_string_center(5, line_2 + "$$ | $$ |")
screen.set_string_center(6, line_3 + "$$ | $$ |") screen.set_string_center(6, line_3 + "$$ | $$ |")
screen.set_string_center(7, line_4 + " $$$$$$$$ |") screen.set_string_center(7, line_4 + " $$$$$$$$ |")
screen.set_string_center(8, line_5 + "\_____$$ |") screen.set_string_center(8, line_5 + "\_____$$ |")
screen.set_string_center(9, line_6 + " $$ |") screen.set_string_center(9, line_6 + " $$ |")
screen.set_string_center(10, line_7 + " $$ |") screen.set_string_center(10, line_7 + " $$ |")
screen.set_string_center(11, line_8 + " \__|") screen.set_string_center(11, line_8 + " \__|")
elif bot == 5: elif bot == 5:
screen.set_string_center(4, line_1 + "$$$$$$$\ ") screen.set_string_center(4, line_1 + "$$$$$$$\ ")
screen.set_string_center(5, line_2 + "$$ ____| ") screen.set_string_center(5, line_2 + "$$ ____| ")
screen.set_string_center(6, line_3 + "$$ | ") screen.set_string_center(6, line_3 + "$$ | ")
screen.set_string_center(7, line_4 + "$$$$$$$\ ") screen.set_string_center(7, line_4 + "$$$$$$$\ ")
screen.set_string_center(8, line_5 + "\_____$$\ ") screen.set_string_center(8, line_5 + "\_____$$\ ")
screen.set_string_center(9, line_6 + "$$\ $$ |") screen.set_string_center(9, line_6 + "$$\ $$ |")
screen.set_string_center(10, line_7 + "\$$$$$$ |") screen.set_string_center(10, line_7 + "\$$$$$$ |")
screen.set_string_center(11, line_8 + " \______/ ") screen.set_string_center(11, line_8 + " \______/ ")
screen.print() screen.print()
def draw_player_cards(screen:Matrix, cards:list, players = None): def draw_player_cards(screen:Matrix, cards:list, players = None):
''' '''
Draws the cards of the players Draws the cards of the players
input: input:
- screen: Matrix - screen: Matrix
screen to print on screen to print on
- cards: list - cards: list
list of the cards list of the cards
- players: list - players: list
list of the players list of the players
''' '''
card1 = "╔═══╗" card1 = "╔═══╗"
card2 = "║ X ║" card2 = "║ X ║"
card3 = "║ X ║" card3 = "║ X ║"
card4 = "╚═══╝" card4 = "╚═══╝"
SUITS = ["", "", "", ""] SUITS = ["", "", "", ""]
RANKS = ["A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"] RANKS = ["A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"]
y = 5 y = 5
x = 0 x = 0
for i in range(len(cards)): for i in range(len(cards)):
card = cards[i] card = cards[i]
if Terminal.get_columns() < x + 10: if Terminal.get_columns() < x + 10:
y += 7 y += 7
x = 0 x = 0
if card.get("suit") == "Spades": if card.get("suit") == "Spades":
card2 = "║ ♠ ║" card2 = "║ ♠ ║"
elif card.get("suit") == "Hearts": elif card.get("suit") == "Hearts":
card2 = "║ ♥ ║" card2 = "║ ♥ ║"
elif card.get("suit") == "Diamonds": elif card.get("suit") == "Diamonds":
card2 = "║ ♦ ║" card2 = "║ ♦ ║"
elif card.get("suit") == "Clubs": elif card.get("suit") == "Clubs":
card2 = "║ ♣ ║" card2 = "║ ♣ ║"
if card.get("rank") == "Ace": if card.get("rank") == "Ace":
card3 = "║ A ║" card3 = "║ A ║"
elif card.get("rank") == "Jack": elif card.get("rank") == "Jack":
card3 = "║ J ║" card3 = "║ J ║"
elif card.get("rank") == "Queen": elif card.get("rank") == "Queen":
card3 = "║ Q ║" card3 = "║ Q ║"
elif card.get("rank") == "King": elif card.get("rank") == "King":
card3 = "║ K ║" card3 = "║ K ║"
elif card.get("rank") == "10": elif card.get("rank") == "10":
card3 = "║10 ║" card3 = "║10 ║"
else: else:
card3 = f"{card.get('rank')}" card3 = f"{card.get('rank')}"
if players is not None: if players is not None:
screen.set_string(3 + x, y - 1, " " + players[i].get_name() + ": \ screen.set_string(3 + x, y - 1, " " + players[i].get_name() + ": \
" + str(players[i].get_points()) + " points") " + str(players[i].get_points()) + " points")
else: else:
screen.set_string(3 + x, y - 1, " " + str(i + 1)) screen.set_string(3 + x, y - 1, " " + str(i + 1))
screen.set_string(3 + x, y, card1) screen.set_string(3 + x, y, card1)
screen.set_string(3 + x, y + 1, card2) screen.set_string(3 + x, y + 1, card2)
screen.set_string(3 + x, y + 2, card3) screen.set_string(3 + x, y + 2, card3)
screen.set_string(3 + x, y + 3, card4) screen.set_string(3 + x, y + 3, card4)
if players is not None: if players is not None:
x += 16 x += 16
x += 6 x += 6
def player_interface(screen:Matrix, player:PLAYER, round_no:int, stich:int, def player_interface(screen:Matrix, player:PLAYER, round_no:int, stich:int,
trumpf:str, trumpf_sym:str): trumpf:str, trumpf_sym:str):
''' '''
Draws the interface for the player Draws the interface for the player
input: input:
- screen: Matrix - screen: Matrix
screen to print on screen to print on
- player: PLAYER - player: PLAYER
player object player object
- round_no: int - round_no: int
number of the round number of the round
- stich: int - stich: int
number of the stich number of the stich
- trumpf: str - trumpf: str
trumpf of the round trumpf of the round
- trumpf_sym: str - trumpf_sym: str
symbol of the trumpf symbol of the trumpf
''' '''
screen.refresh() screen.refresh()
screen.set_frame(0, 0, Terminal.get_columns() - 1, screen.set_frame(0, 0, Terminal.get_columns() - 1,
Terminal.get_lines() - 1, rounded=True, title=f"Player \ Terminal.get_lines() - 1, rounded=True, title=f"Player \
'{player.get_name()}' is playing in round NO. \ '{player.get_name()}' is playing in round NO. \
{round_no} and trick NO. {stich}") {round_no} and trick NO. {stich}")
screen.set_string(Terminal.get_columns() - len(trumpf + " ") - 2, screen.set_string(Terminal.get_columns() - len(trumpf + " ") - 2,
2, "Trumpf: " + trumpf + " " + trumpf_sym) 2, "Trumpf: " + trumpf + " " + trumpf_sym)
screen.set_string(2, 2, f"Points of player {player.get_name()}: \ screen.set_string(2, 2, f"Points of player {player.get_name()}: \
{player.get_points()}") {player.get_points()}")
draw_player_cards(screen, player.get_cards()) draw_player_cards(screen, player.get_cards())
screen.print() screen.print()
wrong_input = True wrong_input = True
while wrong_input: while wrong_input:
chosen_card = console_input("Choose a card by its number", "[1 - " +\ chosen_card = console_input("Choose a card by its number", "[1 - " +\
str(len(player.get_cards())) + "]", screen, fullscreen=True) str(len(player.get_cards())) + "]", screen, fullscreen=True)
if chosen_card.isdigit(): if chosen_card.isdigit():
if int(chosen_card) > 0 and int(chosen_card) <=\ if int(chosen_card) > 0 and int(chosen_card) <=\
len(player.get_cards()): len(player.get_cards()):
wrong_input = False wrong_input = False
return player.pop_card(int(chosen_card) - 1) return player.pop_card(int(chosen_card) - 1)
def bot_interface(screen:Matrix, bot:BOT, round_no:int, stich:int): def bot_interface(screen:Matrix, bot:BOT, round_no:int, stich:int):
''' '''
Draws the interface for the bot Draws the interface for the bot
input: input:
- screen: Matrix - screen: Matrix
screen to print on screen to print on
- bot: BOT - bot: BOT
bot object bot object
- round_no: int - round_no: int
number of the round number of the round
- stich: int - stich: int
number of the stich number of the stich
''' '''
screen.refresh() screen.refresh()
screen.set_frame(0, 0, Terminal.get_columns() - 1,\ screen.set_frame(0, 0, Terminal.get_columns() - 1,\
Terminal.get_lines() - 1, rounded=True, title=f"Bot {bot.get_name()} \ Terminal.get_lines() - 1, rounded=True, title=f"Bot {bot.get_name()} \
is playing in round NO. {round_no}, trick NO. {stich}") is playing in round NO. {round_no}, trick NO. {stich}")
add_bot_font(screen, bot.get_bot_number()) add_bot_font(screen, bot.get_bot_number())
screen.print() screen.print()
return bot.play_card() return bot.play_card()
def winner_screen(screen, winner, players:list): def winner_screen(screen, winner, players:list):
''' '''
Draws the screen for the winner Draws the screen for the winner
input: input:
- screen: Matrix - screen: Matrix
screen to print on screen to print on
- winner: PLAYER - winner: PLAYER
player object player object
- players: list - players: list
list of all players list of all players
''' '''
screen.refresh() screen.refresh()
screen.set_frame(int(Terminal.get_columns() / 2 - 25), screen.set_frame(int(Terminal.get_columns() / 2 - 25),
int(Terminal.get_columns() / 2 - 25), 50, 20, rounded=True, int(Terminal.get_columns() / 2 - 25), 50, 20, rounded=True,
title=f"Player '{winner.get_name()}' won the game!") title=f"Player '{winner.get_name()}' won the game!")
screen.set_string_center(int(Terminal.get_columns() / 2), "Congratulations!") screen.set_string_center(int(Terminal.get_columns() / 2), "Congratulations!")
screen.print() screen.print()
def trumpf_screen(screen:Matrix, trumpf:str): def trumpf_screen(screen:Matrix, trumpf:str):
''' '''
Draws the screen for the trumpf Draws the screen for the trumpf
input: input:
- screen: Matrix - screen: Matrix
screen to print on screen to print on
- trumpf: str - trumpf: str
trumpf of the round trumpf of the round
''' '''
screen.refresh() screen.refresh()
screen.set_frame(int(Terminal.get_columns() / 2 - 25), screen.set_frame(int(Terminal.get_columns() / 2 - 25),
int(Terminal.get_lines() / 2 - 10), 50, 20, int(Terminal.get_lines() / 2 - 10), 50, 20,
rounded=True, title="Trumpf") rounded=True, title="Trumpf")
screen.set_string_center( int(Terminal.get_lines() / 2 - 1), screen.set_string_center( int(Terminal.get_lines() / 2 - 1),
"The trumpf is:") "The trumpf is:")
screen.set_string_center( int(Terminal.get_lines() / 2), trumpf) screen.set_string_center( int(Terminal.get_lines() / 2), trumpf)
screen.print() screen.print()
def stich_win_screen(screen:Matrix, winner, players:list, cards:list, def stich_win_screen(screen:Matrix, winner, players:list, cards:list,
trumpf:str, trumpf_sym:str): trumpf:str, trumpf_sym:str):
''' '''
Draws the screen for the stich winner Draws the screen for the stich winner
input: input:
- screen: Matrix - screen: Matrix
screen to print on screen to print on
- winner: PLAYER - winner: PLAYER
player object player object
- players: list - players: list
list of all players list of all players
- cards: list - cards: list
list of all cards list of all cards
- trumpf: str - trumpf: str
trumpf of the round trumpf of the round
- trumpf_sym: str - trumpf_sym: str
symbol of the trumpf symbol of the trumpf
''' '''
screen.refresh() screen.refresh()
screen.set_frame(0, 0, Terminal.get_columns() - 1, screen.set_frame(0, 0, Terminal.get_columns() - 1,
Terminal.get_lines() - 1, rounded=True, title=f"Player \ Terminal.get_lines() - 1, rounded=True, title=f"Player \
'{winner.get_name()}' won the trick!") '{winner.get_name()}' won the trick!")
screen.set_frame(int(Terminal.get_columns() / 2 - 25), 19, 50, 4, screen.set_frame(int(Terminal.get_columns() / 2 - 25), 19, 50, 4,
double=True) double=True)
screen.set_string_center(20, "Congratulations!") screen.set_string_center(20, "Congratulations!")
screen.set_string_center(21, f"Player '{winner.get_name()}'\ screen.set_string_center(21, f"Player '{winner.get_name()}'\
won the trick!") won the trick!")
screen.set_string_center(22, "Press ENTER to continue...") screen.set_string_center(22, "Press ENTER to continue...")
screen.set_string(Terminal.get_columns() - len(trumpf + " ") - 2, screen.set_string(Terminal.get_columns() - len(trumpf + " ") - 2,
2, "Trumpf: " + trumpf + " " + trumpf_sym) 2, "Trumpf: " + trumpf + " " + trumpf_sym)
draw_player_cards(screen, cards, players) draw_player_cards(screen, cards, players)
screen.print() screen.print()
input() input()
if __name__ == "__main__": if __name__ == "__main__":
# Create a new screen # Create a new screen
screen = Matrix(Terminal.get_columns(), Terminal.get_lines()) screen = Matrix(Terminal.get_columns(), Terminal.get_lines())
screen.set_frame(0, 0, Terminal.get_columns() - 1, screen.set_frame(0, 0, Terminal.get_columns() - 1,
Terminal.get_lines() - 1, rounded=True, title="Welcome \ Terminal.get_lines() - 1, rounded=True, title="Welcome \
to the game!") to the game!")
screen.set_string_center(2, "Welcome to the game!") screen.set_string_center(2, "Welcome to the game!")
screen.set_string_center(3, "Press ENTER to start the game...") screen.set_string_center(3, "Press ENTER to start the game...")
screen.print() screen.print()
input() input()

View file

@ -1,29 +1,29 @@
__author__ = "7987847, Werner, 7347119, Fajst, 7735965, Melikidze" __author__ = "7987847, Werner, 7347119, Fajst, 7735965, Melikidze"
================================================================================================================ ================================================================================================================
a) The context-free grammar generates words that consist of variables (V), which can be any lowercase letter from a to z, a) The context-free grammar generates words that consist of variables (V), which can be any lowercase letter from a to z,
and operators (O), which can be +, -, *, or /. These variables and operators are combined using parentheses (T). and operators (O), which can be +, -, *, or /. These variables and operators are combined using parentheses (T).
Specifically, the grammar generates words by either replacing the start symbol T with a variable (V), Specifically, the grammar generates words by either replacing the start symbol T with a variable (V),
or by replacing T with an opening parenthesis followed by a combination of a T, an operator (O), and another T, followed by a closing parenthesis. or by replacing T with an opening parenthesis followed by a combination of a T, an operator (O), and another T, followed by a closing parenthesis.
b) The word "(a + ((x - z) / y))" can be generated by the context-free grammar. One possible order of derivation rules to create this word is as follows: b) The word "(a + ((x - z) / y))" can be generated by the context-free grammar. One possible order of derivation rules to create this word is as follows:
T -> (TOT) T -> (TOT)
T -> V T -> V
O -> + O -> +
T -> (TOT) T -> (TOT)
T -> (TOT) T -> (TOT)
T -> V T -> V
O -> - O -> -
T -> V T -> V
O -> / O -> /
T -> V T -> V
The word "((p) + (o))" can also be generated by the context-free grammar. One possible order of derivation rules to create this word is as follows: The word "((p) + (o))" can also be generated by the context-free grammar. One possible order of derivation rules to create this word is as follows:
T -> (TOT) T -> (TOT)
T -> V T -> V
O -> + O -> +
T -> (TOT) T -> (TOT)
T -> V T -> V