mirror of
https://github.com/JonasunderscoreJones/EPR-Gruppenabgabe-07.git
synced 2025-10-22 22:29:19 +02:00
comments
This commit is contained in:
parent
40e3b6cac1
commit
3801ab2697
9 changed files with 1463 additions and 1418 deletions
204
DOKU.txt
204
DOKU.txt
|
@ -1,102 +1,102 @@
|
|||
7987847, Werner, 7347119, Fajst, 7735965, Melikidze
|
||||
|
||||
Mit diesem Programm kann man das Kartenspiel "Wizard" spielen.
|
||||
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ß.
|
||||
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:
|
||||
How to play:
|
||||
1. The goal is to play the highest card.
|
||||
2. The trumpf color outweights all other colors.
|
||||
3. The player who wins the most amounts of tricks (Stiche) wins the game.
|
||||
|
||||
|
||||
Press ENTER key to continue...
|
||||
|
||||
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.
|
||||
|
||||
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).
|
||||
Eingaben außerhalb dieser Range werden Abgefangen.
|
||||
Die Abfrage sieht wiefolgt aus:
|
||||
How many players are playing?
|
||||
→ [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.
|
||||
BOTS füllen die Menge der Spieler auf maximal 5. Es kann ebenso nur mit BOTS gespielt werden.
|
||||
Diese Abfrage sieht wiefolgt aus:
|
||||
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.
|
||||
|
||||
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)
|
||||
|
||||
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.
|
||||
Genau so bekommen die Spieler immer random Karten auf die Hand.
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
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:
|
||||
Player 'a' is playing in round NO. 1 and trick NO. 1
|
||||
|
||||
Points of player a: 0 Trumpf: Diamonds ♦
|
||||
|
||||
1
|
||||
╔═══╗
|
||||
║ ♠ ║
|
||||
║ 5 ║
|
||||
╚═══╝
|
||||
|
||||
|
||||
Choose a card by its number
|
||||
→ [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.
|
||||
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:
|
||||
a: 1 points a: 0 points s: 1 points Bot 1: 1 points Bot 2: 0 points
|
||||
╔═══╗ ╔═══╗ ╔═══╗ ╔═══╗ ╔═══╗
|
||||
║ ♠ ║ ║ ♣ ║ ║ ♣ ║ ║ ♥ ║ ║ ♣ ║
|
||||
║ 5 ║ ║10 ║ ║ 3 ║ ║ 2 ║ ║ 7 ║
|
||||
╚═══╝ ╚═══╝ ╚═══╝ ╚═══╝ ╚═══╝
|
||||
|
||||
|
||||
╔═════════════════════════════════════════════════╗
|
||||
║ Congratulations! ║
|
||||
║ Player 'Bot 2' won the trick! ║
|
||||
║ Press ENTER to continue... ║
|
||||
╚═════════════════════════════════════════════════╝
|
||||
Diese Anzeige bleibt, bis der User ENTER drückt.
|
||||
|
||||
|
||||
Wenn BOTS an der Reihe sind, dann sieht es z.B. so aus:
|
||||
|
||||
$$$$$$$\ $$\
|
||||
$$ __$$\ $$ |
|
||||
$$ | $$ | $$$$$$\ $$$$$$\
|
||||
$$$$$$$\ |$$ __$$\\_$$ _|
|
||||
$$ __$$\ $$ / $$ | $$ |
|
||||
$$ | $$ |$$ | $$ | $$ |$$\
|
||||
$$$$$$$ |\$$$$$$ | \$$$$ |
|
||||
\_______/ \______/ \____/
|
||||
|
||||
|
||||
Am Ende des gesamten Spiels erscheint dieser Screen:
|
||||
Congratulations!
|
||||
Player '<Player>' won the game!
|
||||
|
||||
Would you like to play again?
|
||||
→ [Y/n]
|
||||
|
||||
Der User hat die Möglichkeit, das Spiel erneut zu spielen, indem er y in die Konsole eingibt oder ENTER drückt.
|
||||
7987847, Werner, 7347119, Fajst, 7735965, Melikidze
|
||||
|
||||
Mit diesem Programm kann man das Kartenspiel "Wizard" spielen.
|
||||
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ß.
|
||||
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:
|
||||
How to play:
|
||||
1. The goal is to play the highest card.
|
||||
2. The trumpf color outweights all other colors.
|
||||
3. The player who wins the most amounts of tricks (Stiche) wins the game.
|
||||
|
||||
|
||||
Press ENTER key to continue...
|
||||
|
||||
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.
|
||||
|
||||
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).
|
||||
Eingaben außerhalb dieser Range werden Abgefangen.
|
||||
Die Abfrage sieht wiefolgt aus:
|
||||
How many players are playing?
|
||||
→ [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.
|
||||
BOTS füllen die Menge der Spieler auf maximal 5. Es kann ebenso nur mit BOTS gespielt werden.
|
||||
Diese Abfrage sieht wiefolgt aus:
|
||||
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.
|
||||
|
||||
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)
|
||||
|
||||
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.
|
||||
Genau so bekommen die Spieler immer random Karten auf die Hand.
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
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:
|
||||
Player 'a' is playing in round NO. 1 and trick NO. 1
|
||||
|
||||
Points of player a: 0 Trumpf: Diamonds ♦
|
||||
|
||||
1
|
||||
╔═══╗
|
||||
║ ♠ ║
|
||||
║ 5 ║
|
||||
╚═══╝
|
||||
|
||||
|
||||
Choose a card by its number
|
||||
→ [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.
|
||||
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:
|
||||
a: 1 points a: 0 points s: 1 points Bot 1: 1 points Bot 2: 0 points
|
||||
╔═══╗ ╔═══╗ ╔═══╗ ╔═══╗ ╔═══╗
|
||||
║ ♠ ║ ║ ♣ ║ ║ ♣ ║ ║ ♥ ║ ║ ♣ ║
|
||||
║ 5 ║ ║10 ║ ║ 3 ║ ║ 2 ║ ║ 7 ║
|
||||
╚═══╝ ╚═══╝ ╚═══╝ ╚═══╝ ╚═══╝
|
||||
|
||||
|
||||
╔═════════════════════════════════════════════════╗
|
||||
║ Congratulations! ║
|
||||
║ Player 'Bot 2' won the trick! ║
|
||||
║ Press ENTER to continue... ║
|
||||
╚═════════════════════════════════════════════════╝
|
||||
Diese Anzeige bleibt, bis der User ENTER drückt.
|
||||
|
||||
|
||||
Wenn BOTS an der Reihe sind, dann sieht es z.B. so aus:
|
||||
|
||||
$$$$$$$\ $$\
|
||||
$$ __$$\ $$ |
|
||||
$$ | $$ | $$$$$$\ $$$$$$\
|
||||
$$$$$$$\ |$$ __$$\\_$$ _|
|
||||
$$ __$$\ $$ / $$ | $$ |
|
||||
$$ | $$ |$$ | $$ | $$ |$$\
|
||||
$$$$$$$ |\$$$$$$ | \$$$$ |
|
||||
\_______/ \______/ \____/
|
||||
|
||||
|
||||
Am Ende des gesamten Spiels erscheint dieser Screen:
|
||||
Congratulations!
|
||||
Player '<Player>' won the game!
|
||||
|
||||
Would you like to play again?
|
||||
→ [Y/n]
|
||||
|
||||
Der User hat die Möglichkeit, das Spiel erneut zu spielen, indem er y in die Konsole eingibt oder ENTER drückt.
|
||||
|
|
514
cmd_interface.py
514
cmd_interface.py
|
@ -1,258 +1,258 @@
|
|||
'''EPR 07 Aufgabe 3'''
|
||||
__author__ = "7987847, Werner, 7347119, Fajst, 7735965, Melikidze"
|
||||
|
||||
from os import get_terminal_size, name, system
|
||||
from sys import stdout
|
||||
|
||||
class Terminal:
|
||||
'''
|
||||
Terminal class
|
||||
'''
|
||||
def get_size():
|
||||
'''
|
||||
Returns the size of the terminal
|
||||
output:
|
||||
- columns: int
|
||||
number of columns
|
||||
- lines: int
|
||||
number of lines
|
||||
'''
|
||||
return get_terminal_size().columns, get_terminal_size().lines
|
||||
|
||||
def get_lines():
|
||||
'''
|
||||
Returns the number of lines of the terminal
|
||||
output:
|
||||
- lines: int
|
||||
number of lines
|
||||
'''
|
||||
return get_terminal_size().lines
|
||||
|
||||
def get_columns():
|
||||
'''
|
||||
Returns the number of columns of the terminal
|
||||
output:
|
||||
- columns: int
|
||||
number of columns
|
||||
'''
|
||||
return get_terminal_size().columns
|
||||
|
||||
def clear():
|
||||
'''
|
||||
Clears the terminal
|
||||
'''
|
||||
system('cls' if name in ('nt', 'dos') else 'clear')
|
||||
|
||||
def curser_to_pos1():
|
||||
'''
|
||||
Moves the curser to the first position
|
||||
'''
|
||||
for _ in range(self.get_lines() + 2):
|
||||
stdout.write("\033[F")
|
||||
|
||||
|
||||
class Matrix:
|
||||
'''
|
||||
Matrix class
|
||||
'''
|
||||
def __init__(self):
|
||||
self.columns, self.lines = Terminal.get_size()
|
||||
self.clear()
|
||||
|
||||
def clear(self):
|
||||
'''
|
||||
Clears the matrix
|
||||
'''
|
||||
self.matrix = []
|
||||
|
||||
def refresh(self):
|
||||
'''
|
||||
Refreshes the matrix
|
||||
'''
|
||||
self.columns, self.lines = Terminal.get_size()
|
||||
self.clear()
|
||||
for i in range(self.lines):
|
||||
self.matrix.append([])
|
||||
for _ in range(self.columns):
|
||||
self.matrix[i].append(" ")
|
||||
|
||||
def set_frame(self, x, y, dx, dy, rounded=True, double=False, title=None,
|
||||
alligncenter=True):
|
||||
'''
|
||||
Sets a frame in the matrix
|
||||
input:
|
||||
- x: int
|
||||
x position of the frame
|
||||
- y: int
|
||||
y position of the frame
|
||||
- dx: int
|
||||
width of the frame
|
||||
- dy: int
|
||||
height of the frame
|
||||
- rounded: bool
|
||||
if the frame is rounded
|
||||
- double: bool
|
||||
if the frame is double
|
||||
- title: str
|
||||
title of the frame
|
||||
- alligncenter: bool
|
||||
if the title is alligned to the center
|
||||
'''
|
||||
if double:
|
||||
self.set( x, y, "╔")
|
||||
self.set(x + dx, y, "╗")
|
||||
self.set(x, y + dy, "╚")
|
||||
self.set(x + dx, y + dy, "╝")
|
||||
for i in range(1, dx):
|
||||
self.set(x + i, y, "═")
|
||||
self.set(x + i, y + dy, "═")
|
||||
for i in range(1, dy):
|
||||
self.set(x, y + i, "║")
|
||||
self.set(x + dx, y + i, "║")
|
||||
else:
|
||||
if rounded:
|
||||
self.set(x, y, "╭")
|
||||
self.set(x + dx, y, "╮")
|
||||
self.set(x, y + dy, "╰")
|
||||
self.set(x + dx, y + dy, "╯")
|
||||
else:
|
||||
self.set(x, y, "┌")
|
||||
self.set(x + dx, y, "┐")
|
||||
self.set(x, y + dy, "└")
|
||||
self.set(x + dx, y + dy, "┘")
|
||||
for i in range(1, dx):
|
||||
self.set(x + i, y, "─")
|
||||
self.set(x + i, y + dy, "─")
|
||||
for i in range(1, dy):
|
||||
self.set(x, y + i, "│")
|
||||
self.set(x + dx, y + i, "│")
|
||||
if title is not None:
|
||||
if alligncenter:
|
||||
self.set(x + int(dx / 2) - int(len(title) / 2) - 1, y,
|
||||
"┤" if not double else "╡")
|
||||
self.set(x + int(dx / 2) + int(len(title) / 2), y, "├" if
|
||||
not double else "╞")
|
||||
self.set_string(x + int(dx / 2) - int(len(title) / 2),
|
||||
y, title)
|
||||
else:
|
||||
self.set(x + 1, y, "┤" if not double else "╡")
|
||||
self.set( x + len(title) + 2, y, "├" if not double else
|
||||
"╞")
|
||||
self.set_string(x + 2, y, title)
|
||||
|
||||
def set_square(self, x, y, dx, dy, char):
|
||||
'''
|
||||
Sets a square in the matrix
|
||||
input:
|
||||
- x: int
|
||||
x position of the square
|
||||
- y: int
|
||||
y position of the square
|
||||
- dx: int
|
||||
width of the square
|
||||
- dy: int
|
||||
height of the square
|
||||
- char: str
|
||||
character of the square
|
||||
'''
|
||||
for i in range(dx):
|
||||
for j in range(dy):
|
||||
self.set(x + i, y + j, char)
|
||||
|
||||
def set(self, x, y, value):
|
||||
'''
|
||||
Sets a value in the matrix
|
||||
input:
|
||||
- x: int
|
||||
x position of the value
|
||||
- y: int
|
||||
y position of the value
|
||||
- value: str
|
||||
value
|
||||
'''
|
||||
try:
|
||||
self.matrix[y][x] = value
|
||||
except IndexError:
|
||||
pass
|
||||
|
||||
def get(self, x, y):
|
||||
'''
|
||||
Gets a value in the matrix
|
||||
input:
|
||||
- x: int
|
||||
x position of the value
|
||||
- y: int
|
||||
y position of the value
|
||||
output:
|
||||
- value: str
|
||||
value
|
||||
'''
|
||||
return self.matrix[y][x]
|
||||
|
||||
def print(self):
|
||||
'''
|
||||
Prints the matrix
|
||||
'''
|
||||
for i in range(self.lines):
|
||||
for j in range(self.columns):
|
||||
print(self.matrix[i][j], end = "")
|
||||
print(end = "" if i < self.lines - 1 else "\r")
|
||||
|
||||
def set_string(self, x, y, chars):
|
||||
'''
|
||||
Sets a string in the matrix
|
||||
input:
|
||||
- x: int
|
||||
x position of the string
|
||||
- y: int
|
||||
y position of the string
|
||||
- chars: str
|
||||
string
|
||||
'''
|
||||
for i in range(len(chars)):
|
||||
self.set(x + i, y, chars[i])
|
||||
|
||||
def set_string_center(self, y, chars):
|
||||
'''
|
||||
Sets a string in the matrix, alligned to the center
|
||||
input:
|
||||
- y: int
|
||||
y position of the string
|
||||
- chars: str
|
||||
string
|
||||
'''
|
||||
self.set_string(int(Terminal.get_columns() / 2 - len(chars) / 2),
|
||||
y, chars)
|
||||
|
||||
def get_matrix(self):
|
||||
'''
|
||||
Gets the matrix
|
||||
output:
|
||||
- matrix: list
|
||||
matrix
|
||||
'''
|
||||
return self.matrix
|
||||
|
||||
def add_matrix(self, x, y, matrix):
|
||||
'''
|
||||
Adds a matrix to the matrix
|
||||
input:
|
||||
- x: int
|
||||
x position of the matrix
|
||||
- y: int
|
||||
y position of the matrix
|
||||
- matrix: list
|
||||
matrix
|
||||
'''
|
||||
for i in range(len(matrix)):
|
||||
for j in range(len(matrix[i])):
|
||||
self.set(self, x + j, y + i, matrix[i][j])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
term = Terminal()
|
||||
term.set_frame(0, 0, term.get_columns(), term.get_lines(), title="Test",
|
||||
alligncenter=True)
|
||||
term.set_string_center(1, "Hello World!")
|
||||
term.print()
|
||||
'''EPR 07 Aufgabe 3'''
|
||||
__author__ = "7987847, Werner, 7347119, Fajst, 7735965, Melikidze"
|
||||
|
||||
from os import get_terminal_size, name, system
|
||||
from sys import stdout
|
||||
|
||||
class Terminal:
|
||||
'''
|
||||
Terminal class
|
||||
'''
|
||||
def get_size():
|
||||
'''
|
||||
Returns the size of the terminal
|
||||
output:
|
||||
- columns: int
|
||||
number of columns
|
||||
- lines: int
|
||||
number of lines
|
||||
'''
|
||||
return get_terminal_size().columns, get_terminal_size().lines
|
||||
|
||||
def get_lines():
|
||||
'''
|
||||
Returns the number of lines of the terminal
|
||||
output:
|
||||
- lines: int
|
||||
number of lines
|
||||
'''
|
||||
return get_terminal_size().lines
|
||||
|
||||
def get_columns():
|
||||
'''
|
||||
Returns the number of columns of the terminal
|
||||
output:
|
||||
- columns: int
|
||||
number of columns
|
||||
'''
|
||||
return get_terminal_size().columns
|
||||
|
||||
def clear():
|
||||
'''
|
||||
Clears the terminal
|
||||
'''
|
||||
system('cls' if name in ('nt', 'dos') else 'clear')
|
||||
|
||||
def curser_to_pos1():
|
||||
'''
|
||||
Moves the curser to the first position
|
||||
'''
|
||||
for _ in range(self.get_lines() + 2):
|
||||
stdout.write("\033[F")
|
||||
|
||||
|
||||
class Matrix:
|
||||
'''
|
||||
Matrix class
|
||||
'''
|
||||
def __init__(self):
|
||||
self.columns, self.lines = Terminal.get_size()
|
||||
self.clear()
|
||||
|
||||
def clear(self):
|
||||
'''
|
||||
Clears the matrix
|
||||
'''
|
||||
self.matrix = []
|
||||
|
||||
def refresh(self):
|
||||
'''
|
||||
Refreshes the matrix
|
||||
'''
|
||||
self.columns, self.lines = Terminal.get_size()
|
||||
self.clear()
|
||||
for i in range(self.lines):
|
||||
self.matrix.append([])
|
||||
for _ in range(self.columns):
|
||||
self.matrix[i].append(" ")
|
||||
|
||||
def set_frame(self, x, y, dx, dy, rounded=True, double=False, title=None,
|
||||
alligncenter=True):
|
||||
'''
|
||||
Sets a frame in the matrix
|
||||
input:
|
||||
- x: int
|
||||
x position of the frame
|
||||
- y: int
|
||||
y position of the frame
|
||||
- dx: int
|
||||
width of the frame
|
||||
- dy: int
|
||||
height of the frame
|
||||
- rounded: bool
|
||||
if the frame is rounded
|
||||
- double: bool
|
||||
if the frame is double
|
||||
- title: str
|
||||
title of the frame
|
||||
- alligncenter: bool
|
||||
if the title is alligned to the center
|
||||
'''
|
||||
if double:
|
||||
self.set( x, y, "╔")
|
||||
self.set(x + dx, y, "╗")
|
||||
self.set(x, y + dy, "╚")
|
||||
self.set(x + dx, y + dy, "╝")
|
||||
for i in range(1, dx):
|
||||
self.set(x + i, y, "═")
|
||||
self.set(x + i, y + dy, "═")
|
||||
for i in range(1, dy):
|
||||
self.set(x, y + i, "║")
|
||||
self.set(x + dx, y + i, "║")
|
||||
else:
|
||||
if rounded:
|
||||
self.set(x, y, "╭")
|
||||
self.set(x + dx, y, "╮")
|
||||
self.set(x, y + dy, "╰")
|
||||
self.set(x + dx, y + dy, "╯")
|
||||
else:
|
||||
self.set(x, y, "┌")
|
||||
self.set(x + dx, y, "┐")
|
||||
self.set(x, y + dy, "└")
|
||||
self.set(x + dx, y + dy, "┘")
|
||||
for i in range(1, dx):
|
||||
self.set(x + i, y, "─")
|
||||
self.set(x + i, y + dy, "─")
|
||||
for i in range(1, dy):
|
||||
self.set(x, y + i, "│")
|
||||
self.set(x + dx, y + i, "│")
|
||||
if title is not None:
|
||||
if alligncenter:
|
||||
self.set(x + int(dx / 2) - int(len(title) / 2) - 1, y,
|
||||
"┤" if not double else "╡")
|
||||
self.set(x + int(dx / 2) + int(len(title) / 2), y, "├" if
|
||||
not double else "╞")
|
||||
self.set_string(x + int(dx / 2) - int(len(title) / 2),
|
||||
y, title)
|
||||
else:
|
||||
self.set(x + 1, y, "┤" if not double else "╡")
|
||||
self.set( x + len(title) + 2, y, "├" if not double else
|
||||
"╞")
|
||||
self.set_string(x + 2, y, title)
|
||||
|
||||
def set_square(self, x, y, dx, dy, char):
|
||||
'''
|
||||
Sets a square in the matrix
|
||||
input:
|
||||
- x: int
|
||||
x position of the square
|
||||
- y: int
|
||||
y position of the square
|
||||
- dx: int
|
||||
width of the square
|
||||
- dy: int
|
||||
height of the square
|
||||
- char: str
|
||||
character of the square
|
||||
'''
|
||||
for i in range(dx):
|
||||
for j in range(dy):
|
||||
self.set(x + i, y + j, char)
|
||||
|
||||
def set(self, x, y, value):
|
||||
'''
|
||||
Sets a value in the matrix
|
||||
input:
|
||||
- x: int
|
||||
x position of the value
|
||||
- y: int
|
||||
y position of the value
|
||||
- value: str
|
||||
value
|
||||
'''
|
||||
try:
|
||||
self.matrix[y][x] = value
|
||||
except IndexError:
|
||||
pass
|
||||
|
||||
def get(self, x, y):
|
||||
'''
|
||||
Gets a value in the matrix
|
||||
input:
|
||||
- x: int
|
||||
x position of the value
|
||||
- y: int
|
||||
y position of the value
|
||||
output:
|
||||
- value: str
|
||||
value
|
||||
'''
|
||||
return self.matrix[y][x]
|
||||
|
||||
def print(self):
|
||||
'''
|
||||
Prints the matrix
|
||||
'''
|
||||
for i in range(self.lines):
|
||||
for j in range(self.columns):
|
||||
print(self.matrix[i][j], end = "")
|
||||
print(end = "" if i < self.lines - 1 else "\r")
|
||||
|
||||
def set_string(self, x, y, chars):
|
||||
'''
|
||||
Sets a string in the matrix
|
||||
input:
|
||||
- x: int
|
||||
x position of the string
|
||||
- y: int
|
||||
y position of the string
|
||||
- chars: str
|
||||
string
|
||||
'''
|
||||
for i in range(len(chars)):
|
||||
self.set(x + i, y, chars[i])
|
||||
|
||||
def set_string_center(self, y, chars):
|
||||
'''
|
||||
Sets a string in the matrix, alligned to the center
|
||||
input:
|
||||
- y: int
|
||||
y position of the string
|
||||
- chars: str
|
||||
string
|
||||
'''
|
||||
self.set_string(int(Terminal.get_columns() / 2 - len(chars) / 2),
|
||||
y, chars)
|
||||
|
||||
def get_matrix(self):
|
||||
'''
|
||||
Gets the matrix
|
||||
output:
|
||||
- matrix: list
|
||||
matrix
|
||||
'''
|
||||
return self.matrix
|
||||
|
||||
def add_matrix(self, x, y, matrix):
|
||||
'''
|
||||
Adds a matrix to the matrix
|
||||
input:
|
||||
- x: int
|
||||
x position of the matrix
|
||||
- y: int
|
||||
y position of the matrix
|
||||
- matrix: list
|
||||
matrix
|
||||
'''
|
||||
for i in range(len(matrix)):
|
||||
for j in range(len(matrix[i])):
|
||||
self.set(self, x + j, y + i, matrix[i][j])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
term = Terminal()
|
||||
term.set_frame(0, 0, term.get_columns(), term.get_lines(), title="Test",
|
||||
alligncenter=True)
|
||||
term.set_string_center(1, "Hello World!")
|
||||
term.print()
|
||||
|
220
game.py
220
game.py
|
@ -1,110 +1,110 @@
|
|||
'''EPR 07 Aufgabe 3'''
|
||||
__author__ = "7987847, Werner, 7347119, Fajst, 7735965, Melikidze"
|
||||
|
||||
from random import randint
|
||||
|
||||
RANKS = ['Ace', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'Jack', 'Queen',
|
||||
'King']
|
||||
SUITS = ['Spades', 'Hearts', 'Diamonds', 'Clubs']
|
||||
|
||||
def create_cards():
|
||||
'''
|
||||
Creates a deck of cards
|
||||
|
||||
output:
|
||||
- card_deck: list
|
||||
list of cards
|
||||
'''
|
||||
card_deck = []
|
||||
|
||||
for suit in SUITS:
|
||||
for rank in RANKS:
|
||||
card = {'rank': rank, 'suit': suit}
|
||||
card_deck.append(card)
|
||||
return card_deck
|
||||
|
||||
|
||||
def deal_cards(card_deck:list, players:int, cards_per_player:int):
|
||||
'''
|
||||
Deals cards to players
|
||||
|
||||
input:
|
||||
- card_deck: list
|
||||
list of cards
|
||||
- players: int
|
||||
number of players
|
||||
- cards_per_player: int
|
||||
number of cards per player
|
||||
output:
|
||||
- player_cards: tuple
|
||||
tuple of lists, each list contains the cards of a player
|
||||
'''
|
||||
temp_cards = []
|
||||
for player in range(players):
|
||||
temp_cards.append([])
|
||||
for _ in range(cards_per_player):
|
||||
temp_cards[player].append(card_deck.pop(randint(0,
|
||||
len(card_deck)-1)))
|
||||
while len(temp_cards) < 5:
|
||||
temp_cards.append([])
|
||||
|
||||
return (temp_cards[0], temp_cards[1], temp_cards[2], temp_cards[3],
|
||||
temp_cards[4])
|
||||
|
||||
|
||||
def compare_cards(cards_to_compare:list, trumpf_color:str):
|
||||
'''
|
||||
Compares the given cards and returns the winner
|
||||
|
||||
input:
|
||||
- cards_to_compare: list
|
||||
list of cards to compare
|
||||
output:
|
||||
- winner: int
|
||||
index of the winning card
|
||||
'''
|
||||
winner = 0
|
||||
trumpf = []
|
||||
for i in cards_to_compare:
|
||||
if i.get('suit') == trumpf_color:
|
||||
trumpf.append(cards_to_compare.index(i))
|
||||
if len(trumpf) == 1:
|
||||
return trumpf[0]
|
||||
elif len(trumpf) > 1:
|
||||
winner = 0
|
||||
for j in trumpf:
|
||||
if RANKS.index(cards_to_compare[j].get('rank')) > RANKS.index(
|
||||
cards_to_compare[winner].get('rank')):
|
||||
winner = j
|
||||
winner = j
|
||||
else:
|
||||
winner = 0
|
||||
for j in cards_to_compare:
|
||||
if RANKS.index(j.get('rank')) > RANKS.index(
|
||||
cards_to_compare[winner].get('rank')):
|
||||
winner = cards_to_compare.index(j)
|
||||
print(winner, j, cards_to_compare)
|
||||
|
||||
return winner
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
card_deck = create_cards()
|
||||
print(card_deck)
|
||||
|
||||
print(deal_cards(card_deck, 5, 5))
|
||||
|
||||
if __name__ == '__main__':
|
||||
# Testcases
|
||||
deck = create_cards()
|
||||
print(deck)
|
||||
print(deal_cards(create_cards(), deck, 5))
|
||||
print(deal_cards(create_cards(), deck, 0))
|
||||
try:
|
||||
print(deal_cards(create_cards(), deck, 100))
|
||||
except:
|
||||
print('Exception')
|
||||
|
||||
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': 'Diamond'}]), 'Hearts')
|
||||
'''EPR 07 Aufgabe 3'''
|
||||
__author__ = "7987847, Werner, 7347119, Fajst, 7735965, Melikidze"
|
||||
|
||||
from random import randint
|
||||
|
||||
RANKS = ['Ace', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'Jack', 'Queen',
|
||||
'King']
|
||||
SUITS = ['Spades', 'Hearts', 'Diamonds', 'Clubs']
|
||||
|
||||
def create_cards():
|
||||
'''
|
||||
Creates a deck of cards
|
||||
|
||||
output:
|
||||
- card_deck: list
|
||||
list of cards
|
||||
'''
|
||||
card_deck = []
|
||||
# add every combination of suit and rank to the deck
|
||||
for suit in SUITS:
|
||||
for rank in RANKS:
|
||||
card = {'rank': rank, 'suit': suit}
|
||||
card_deck.append(card)
|
||||
return card_deck
|
||||
|
||||
|
||||
def deal_cards(card_deck:list, players:int, cards_per_player:int):
|
||||
'''
|
||||
Deals cards to players
|
||||
|
||||
input:
|
||||
- card_deck: list
|
||||
list of cards
|
||||
- players: int
|
||||
number of players
|
||||
- cards_per_player: int
|
||||
number of cards per player
|
||||
output:
|
||||
- player_cards: tuple
|
||||
tuple of lists, each list contains the cards of a player
|
||||
'''
|
||||
temp_cards = []
|
||||
for player in range(players):
|
||||
temp_cards.append([])
|
||||
for _ in range(cards_per_player):
|
||||
temp_cards[player].append(card_deck.pop(randint(0,
|
||||
len(card_deck)-1)))
|
||||
while len(temp_cards) < 5:
|
||||
temp_cards.append([])
|
||||
|
||||
return (temp_cards[0], temp_cards[1], temp_cards[2], temp_cards[3],
|
||||
temp_cards[4])
|
||||
|
||||
|
||||
def compare_cards(cards_to_compare:list, trumpf_color:str):
|
||||
'''
|
||||
Compares the given cards and returns the winner
|
||||
|
||||
input:
|
||||
- cards_to_compare: list
|
||||
list of cards to compare
|
||||
output:
|
||||
- winner: int
|
||||
index of the winning card
|
||||
'''
|
||||
winner = 0
|
||||
trumpf = []
|
||||
for i in cards_to_compare:
|
||||
if i.get('suit') == trumpf_color:
|
||||
trumpf.append(cards_to_compare.index(i))
|
||||
if len(trumpf) == 1:
|
||||
return trumpf[0]
|
||||
elif len(trumpf) > 1:
|
||||
winner = 0
|
||||
for j in trumpf:
|
||||
if RANKS.index(cards_to_compare[j].get('rank')) > RANKS.index(
|
||||
cards_to_compare[winner].get('rank')):
|
||||
winner = j
|
||||
winner = j
|
||||
else:
|
||||
winner = 0
|
||||
for j in cards_to_compare:
|
||||
if RANKS.index(j.get('rank')) > RANKS.index(
|
||||
cards_to_compare[winner].get('rank')):
|
||||
winner = cards_to_compare.index(j)
|
||||
print(winner, j, cards_to_compare)
|
||||
|
||||
return winner
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
card_deck = create_cards()
|
||||
print(card_deck)
|
||||
|
||||
print(deal_cards(card_deck, 5, 5))
|
||||
|
||||
if __name__ == '__main__':
|
||||
# Testcases
|
||||
deck = create_cards()
|
||||
print(deck)
|
||||
print(deal_cards(create_cards(), deck, 5))
|
||||
print(deal_cards(create_cards(), deck, 0))
|
||||
try:
|
||||
print(deal_cards(create_cards(), deck, 100))
|
||||
except:
|
||||
print('Exception')
|
||||
|
||||
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': 'Diamond'}]), 'Hearts')
|
||||
|
|
296
game_bot.py
296
game_bot.py
|
@ -1,148 +1,148 @@
|
|||
'''EPR 07 Aufgabe 3'''
|
||||
__author__ = "7987847, Werner, 7347119, Fajst, 7735965, Melikidze"
|
||||
|
||||
class BOT:
|
||||
'''
|
||||
Bot class
|
||||
'''
|
||||
def __init__(self, name, bot_number, cards):
|
||||
self.name = name
|
||||
self.cards = cards
|
||||
self.points = 0
|
||||
self.trumpf = False
|
||||
self.trumpf_color = None
|
||||
self.bot_number = bot_number
|
||||
|
||||
def play_card(self):
|
||||
'''
|
||||
Plays a card
|
||||
output:
|
||||
- card: dict
|
||||
card to play
|
||||
'''
|
||||
return self.cards.pop(0)
|
||||
|
||||
def add_points(self, points):
|
||||
'''
|
||||
Adds points to the bot
|
||||
input:
|
||||
- points: int
|
||||
points to add
|
||||
'''
|
||||
self.points += points
|
||||
|
||||
# Getters
|
||||
|
||||
def get_trumpf_color(self):
|
||||
'''
|
||||
Returns the trumpf color
|
||||
output:
|
||||
- trumpf_color: str
|
||||
trumpf color
|
||||
'''
|
||||
return self.trumpf_color
|
||||
|
||||
def get_name(self):
|
||||
'''
|
||||
Returns the name of the bot
|
||||
output:
|
||||
- name: str
|
||||
name of the bot
|
||||
'''
|
||||
return self.name
|
||||
|
||||
def get_cards(self):
|
||||
'''
|
||||
Returns the cards of the bot
|
||||
output:
|
||||
- cards: list
|
||||
list of cards
|
||||
'''
|
||||
return self.cards
|
||||
|
||||
def get_points(self):
|
||||
'''
|
||||
Returns the points of the bot
|
||||
output:
|
||||
- points: int
|
||||
points of the bot
|
||||
'''
|
||||
return self.points
|
||||
|
||||
def get_trumpf(self):
|
||||
'''
|
||||
Returns if the bot has trumpf
|
||||
output:
|
||||
- trumpf: bool
|
||||
if the bot has trumpf
|
||||
'''
|
||||
return self.trumpf
|
||||
|
||||
def is_bot(self):
|
||||
'''
|
||||
Returns if the player is a bot
|
||||
output:
|
||||
- is_bot: bool
|
||||
if the player is a bot
|
||||
'''
|
||||
return True
|
||||
|
||||
def get_bot_number(self):
|
||||
'''
|
||||
Returns the bot number
|
||||
output:
|
||||
- bot_number: int
|
||||
bot number
|
||||
'''
|
||||
return self.bot_number
|
||||
|
||||
# Setter
|
||||
|
||||
def set_trumpf(self, trumpf):
|
||||
'''
|
||||
Sets if the bot has trumpf
|
||||
input:
|
||||
- trumpf: bool
|
||||
if the bot has trumpf
|
||||
'''
|
||||
self.trumpf = trumpf
|
||||
|
||||
def set_cards(self, cards):
|
||||
'''
|
||||
Sets the cards of the bot
|
||||
input:
|
||||
- cards: list
|
||||
list of cards
|
||||
'''
|
||||
self.cards = cards
|
||||
|
||||
def set_points(self, points):
|
||||
'''
|
||||
Sets the points of the bot
|
||||
input:
|
||||
- points: int
|
||||
points of the bot
|
||||
'''
|
||||
self.points = points
|
||||
|
||||
def set_trumpf_color(self, trumpf_color):
|
||||
'''
|
||||
Sets the trumpf color of the bot
|
||||
input:
|
||||
- trumpf_color: str
|
||||
trumpf color of the bot
|
||||
'''
|
||||
self.trumpf_color = trumpf_color
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
import game
|
||||
|
||||
# Create a bot
|
||||
bot = BOT("Bot", 1, game.create_cards())
|
||||
print(bot.get_cards())
|
||||
print(bot.play_card())
|
||||
print(bot.get_cards())
|
||||
'''EPR 07 Aufgabe 3'''
|
||||
__author__ = "7987847, Werner, 7347119, Fajst, 7735965, Melikidze"
|
||||
|
||||
class BOT:
|
||||
'''
|
||||
Bot class
|
||||
'''
|
||||
def __init__(self, name, bot_number, cards):
|
||||
self.name = name
|
||||
self.cards = cards
|
||||
self.points = 0
|
||||
self.trumpf = False
|
||||
self.trumpf_color = None
|
||||
self.bot_number = bot_number
|
||||
|
||||
def play_card(self):
|
||||
'''
|
||||
Plays a card
|
||||
output:
|
||||
- card: dict
|
||||
card to play
|
||||
'''
|
||||
return self.cards.pop(0)
|
||||
|
||||
def add_points(self, points):
|
||||
'''
|
||||
Adds points to the bot
|
||||
input:
|
||||
- points: int
|
||||
points to add
|
||||
'''
|
||||
self.points += points
|
||||
|
||||
# Getters
|
||||
|
||||
def get_trumpf_color(self):
|
||||
'''
|
||||
Returns the trumpf color
|
||||
output:
|
||||
- trumpf_color: str
|
||||
trumpf color
|
||||
'''
|
||||
return self.trumpf_color
|
||||
|
||||
def get_name(self):
|
||||
'''
|
||||
Returns the name of the bot
|
||||
output:
|
||||
- name: str
|
||||
name of the bot
|
||||
'''
|
||||
return self.name
|
||||
|
||||
def get_cards(self):
|
||||
'''
|
||||
Returns the cards of the bot
|
||||
output:
|
||||
- cards: list
|
||||
list of cards
|
||||
'''
|
||||
return self.cards
|
||||
|
||||
def get_points(self):
|
||||
'''
|
||||
Returns the points of the bot
|
||||
output:
|
||||
- points: int
|
||||
points of the bot
|
||||
'''
|
||||
return self.points
|
||||
|
||||
def get_trumpf(self):
|
||||
'''
|
||||
Returns if the bot has trumpf
|
||||
output:
|
||||
- trumpf: bool
|
||||
if the bot has trumpf
|
||||
'''
|
||||
return self.trumpf
|
||||
|
||||
def is_bot(self):
|
||||
'''
|
||||
Returns if the player is a bot
|
||||
output:
|
||||
- is_bot: bool
|
||||
if the player is a bot
|
||||
'''
|
||||
return True
|
||||
|
||||
def get_bot_number(self):
|
||||
'''
|
||||
Returns the bot number
|
||||
output:
|
||||
- bot_number: int
|
||||
bot number
|
||||
'''
|
||||
return self.bot_number
|
||||
|
||||
# Setter
|
||||
|
||||
def set_trumpf(self, trumpf):
|
||||
'''
|
||||
Sets if the bot has trumpf
|
||||
input:
|
||||
- trumpf: bool
|
||||
if the bot has trumpf
|
||||
'''
|
||||
self.trumpf = trumpf
|
||||
|
||||
def set_cards(self, cards):
|
||||
'''
|
||||
Sets the cards of the bot
|
||||
input:
|
||||
- cards: list
|
||||
list of cards
|
||||
'''
|
||||
self.cards = cards
|
||||
|
||||
def set_points(self, points):
|
||||
'''
|
||||
Sets the points of the bot
|
||||
input:
|
||||
- points: int
|
||||
points of the bot
|
||||
'''
|
||||
self.points = points
|
||||
|
||||
def set_trumpf_color(self, trumpf_color):
|
||||
'''
|
||||
Sets the trumpf color of the bot
|
||||
input:
|
||||
- trumpf_color: str
|
||||
trumpf color of the bot
|
||||
'''
|
||||
self.trumpf_color = trumpf_color
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
import game
|
||||
|
||||
# Create a bot
|
||||
bot = BOT("Bot", 1, game.create_cards())
|
||||
print(bot.get_cards())
|
||||
print(bot.play_card())
|
||||
print(bot.get_cards())
|
||||
|
|
188
game_player.py
188
game_player.py
|
@ -1,94 +1,94 @@
|
|||
'''EPR 07 Aufgabe 3'''
|
||||
__author__ = "7987847, Werner, 7347119, Fajst, 7735965, Melikidze"
|
||||
|
||||
class PLAYER:
|
||||
'''
|
||||
Player class
|
||||
'''
|
||||
def __init__(self, name, cards):
|
||||
self.name = name
|
||||
self.cards = cards
|
||||
self.points = 0
|
||||
self.trumpf = False
|
||||
self.trumpf_color = None
|
||||
|
||||
def get_name(self):
|
||||
'''
|
||||
Returns the name of the player
|
||||
output:
|
||||
- name: str
|
||||
name of the player
|
||||
'''
|
||||
return self.name
|
||||
|
||||
def is_bot(self):
|
||||
'''
|
||||
Returns if the player is a bot
|
||||
output:
|
||||
- is_bot: bool
|
||||
if the player is a bot
|
||||
'''
|
||||
return False
|
||||
|
||||
def pop_card(self, card:int):
|
||||
'''
|
||||
Removes a card from the players cards
|
||||
input:
|
||||
- card: int
|
||||
index of the card
|
||||
'''
|
||||
return self.cards.pop(card)
|
||||
|
||||
def get_cards(self):
|
||||
'''
|
||||
Returns the cards of the player
|
||||
output:
|
||||
- cards: list
|
||||
list of cards of the player
|
||||
'''
|
||||
return self.cards
|
||||
|
||||
def add_points(self, points):
|
||||
'''
|
||||
Adds points to the player
|
||||
input:
|
||||
- points: int
|
||||
points to add
|
||||
'''
|
||||
self.points += points
|
||||
|
||||
def get_points(self):
|
||||
'''
|
||||
Returns the points of the player
|
||||
output:
|
||||
- points: int
|
||||
points of the player
|
||||
'''
|
||||
return self.points
|
||||
|
||||
def add_card(self, card):
|
||||
'''
|
||||
Adds a card to the players cards
|
||||
input:
|
||||
- card: dict
|
||||
card to add
|
||||
'''
|
||||
self.cards.append(card)
|
||||
|
||||
def set_cards(self, cards):
|
||||
'''
|
||||
Sets the cards of the player
|
||||
input:
|
||||
- cards: list
|
||||
list of cards
|
||||
'''
|
||||
self.cards = cards
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
import game
|
||||
|
||||
player = PLAYER("Bot", 1, game.create_cards())
|
||||
print(player.get_cards())
|
||||
print(player.play_card())
|
||||
print(player.get_cards())
|
||||
'''EPR 07 Aufgabe 3'''
|
||||
__author__ = "7987847, Werner, 7347119, Fajst, 7735965, Melikidze"
|
||||
|
||||
class PLAYER:
|
||||
'''
|
||||
Player class
|
||||
'''
|
||||
def __init__(self, name, cards):
|
||||
self.name = name
|
||||
self.cards = cards
|
||||
self.points = 0
|
||||
self.trumpf = False
|
||||
self.trumpf_color = None
|
||||
|
||||
def get_name(self):
|
||||
'''
|
||||
Returns the name of the player
|
||||
output:
|
||||
- name: str
|
||||
name of the player
|
||||
'''
|
||||
return self.name
|
||||
|
||||
def is_bot(self):
|
||||
'''
|
||||
Returns if the player is a bot
|
||||
output:
|
||||
- is_bot: bool
|
||||
if the player is a bot
|
||||
'''
|
||||
return False
|
||||
|
||||
def pop_card(self, card:int):
|
||||
'''
|
||||
Removes a card from the players cards
|
||||
input:
|
||||
- card: int
|
||||
index of the card
|
||||
'''
|
||||
return self.cards.pop(card)
|
||||
|
||||
def get_cards(self):
|
||||
'''
|
||||
Returns the cards of the player
|
||||
output:
|
||||
- cards: list
|
||||
list of cards of the player
|
||||
'''
|
||||
return self.cards
|
||||
|
||||
def add_points(self, points):
|
||||
'''
|
||||
Adds points to the player
|
||||
input:
|
||||
- points: int
|
||||
points to add
|
||||
'''
|
||||
self.points += points
|
||||
|
||||
def get_points(self):
|
||||
'''
|
||||
Returns the points of the player
|
||||
output:
|
||||
- points: int
|
||||
points of the player
|
||||
'''
|
||||
return self.points
|
||||
|
||||
def add_card(self, card):
|
||||
'''
|
||||
Adds a card to the players cards
|
||||
input:
|
||||
- card: dict
|
||||
card to add
|
||||
'''
|
||||
self.cards.append(card)
|
||||
|
||||
def set_cards(self, cards):
|
||||
'''
|
||||
Sets the cards of the player
|
||||
input:
|
||||
- cards: list
|
||||
list of cards
|
||||
'''
|
||||
self.cards = cards
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
import game
|
||||
|
||||
player = PLAYER("Bot", 1, game.create_cards())
|
||||
print(player.get_cards())
|
||||
print(player.play_card())
|
||||
print(player.get_cards())
|
||||
|
|
365
main.py
365
main.py
|
@ -1,160 +1,205 @@
|
|||
'''EPR 07 Aufgabe 3'''
|
||||
__author__ = "7987847, Werner, 7347119, Fajst, 7735965, Melikidze"
|
||||
|
||||
from time import sleep
|
||||
from random import randint
|
||||
|
||||
from cmd_interface import Matrix, Terminal
|
||||
import screen_handler
|
||||
import game
|
||||
from game_bot import BOT
|
||||
from game_player import PLAYER
|
||||
|
||||
screen = Matrix()
|
||||
|
||||
NO = ["n", 'N', 'no', 'No', 'NO', 'nO','']
|
||||
YES = ["y", 'Y', 'yes', 'Yes', 'YES', 'yES','yEs','YeS','yES', '']
|
||||
|
||||
PREVIOUS_CONFIG = None
|
||||
|
||||
def main(first_time:bool=True, previous_config = None):
|
||||
'''
|
||||
The main function of the game
|
||||
input:
|
||||
- first_time: bool
|
||||
if the game is started for the first time
|
||||
- previous_config: list
|
||||
previous config of the game
|
||||
|
||||
output:
|
||||
- previous_config: list
|
||||
previous config of the game
|
||||
'''
|
||||
if first_time:
|
||||
screen.refresh()
|
||||
screen.set_frame(int(Terminal.get_columns() / 2 - 25),
|
||||
int(Terminal.get_lines() / 2 - 10), 50, 20, rounded=True,
|
||||
title="Welcome to the game")
|
||||
screen.set_string_center(int(Terminal.get_lines() /2 - 7),
|
||||
"Follow these instructions")
|
||||
screen.set_string_center(int(Terminal.get_lines() /2 - 6),
|
||||
"for an enhanced gaming experience:")
|
||||
screen.set_string_center(int(Terminal.get_lines() /2 - 4),
|
||||
"1. Make sure your terminal is")
|
||||
screen.set_string_center(int(Terminal.get_lines() /2 - 3),
|
||||
" fullscreen or at least 80x24")
|
||||
screen.set_string_center(int(Terminal.get_lines() /2),
|
||||
"2. Make sure to not resize your")
|
||||
screen.set_string_center(int(Terminal.get_lines() /2 + 1),
|
||||
" terminal during gameplay")
|
||||
screen.set_string_center(int(Terminal.get_lines() /2 + 4),
|
||||
"Your terminal currently has the size:")
|
||||
screen.set_string_center(int(Terminal.get_lines() /2 + 5),
|
||||
f"{Terminal.get_columns()}x{Terminal.get_lines()}")
|
||||
screen.set_string_center(int(Terminal.get_lines() /2 + 7),
|
||||
"If your terminal is not fullscreen or")
|
||||
screen.set_string_center(int(Terminal.get_lines() /2 + 8),
|
||||
"at least 80x28, the game will pause")
|
||||
screen.set_string_center(int(Terminal.get_lines() /2 + 9),
|
||||
"and display an error message until resolved")
|
||||
if screen_handler.console_input(
|
||||
"Would you like to check out the rules of the game?", "[Y/n]",
|
||||
screen) in YES:
|
||||
screen_handler.game_rules(screen)
|
||||
screen.refresh()
|
||||
if previous_config is not None and screen_handler.console_input(
|
||||
"Would you like to reuse the configuration from the last game?",
|
||||
"[Y/n]", screen) in YES:
|
||||
pass
|
||||
else:
|
||||
previous_config = screen_handler.config_sequence(screen)
|
||||
|
||||
screen.refresh()
|
||||
screen.print()
|
||||
|
||||
players = []
|
||||
for i in range(0, int(previous_config[1])):
|
||||
players.append(PLAYER(screen_handler.console_input(
|
||||
f'Name for Player {i + 1}: In der kürze liegt die Würze \
|
||||
(In short lies the spice :) )', '', screen=screen), []))
|
||||
for i in range(0, int(previous_config[2])):
|
||||
players.append(BOT(f'Bot {i + 1}', i + 1, []))
|
||||
|
||||
screen.refresh()
|
||||
|
||||
screen_handler.starting_screen(screen, players)
|
||||
|
||||
sleep(1)
|
||||
|
||||
screen.refresh()
|
||||
|
||||
max_turns = int(52 / len(players))
|
||||
# debug to shorten game
|
||||
# max_turns = 3
|
||||
|
||||
for turn in range(1, max_turns):
|
||||
SUITS = ['Spades', 'Hearts', 'Diamonds', 'Clubs']
|
||||
SUITS_SYM = ["♠", "♥", "♦", "♣"]
|
||||
trumpf_color = SUITS[randint(0, 3)]
|
||||
|
||||
screen_handler.trumpf_screen(screen, trumpf_color)
|
||||
sleep(2)
|
||||
|
||||
|
||||
card_deck = game.create_cards()
|
||||
dealt_cards = game.deal_cards(card_deck, int(previous_config[1]) +
|
||||
int(previous_config[2]), turn)
|
||||
|
||||
for player in players:
|
||||
player.set_cards(dealt_cards[players.index(player)])
|
||||
|
||||
cards = []
|
||||
for stiche in range(0, turn):
|
||||
cards = []
|
||||
for player in players:
|
||||
if player.is_bot():
|
||||
cards.append(screen_handler.bot_interface(screen, player,
|
||||
turn, stiche + 1))
|
||||
sleep(0.5)
|
||||
else:
|
||||
cards.append(screen_handler.player_interface(
|
||||
screen, player, turn, stiche + 1, trumpf_color,
|
||||
SUITS_SYM[SUITS.index(trumpf_color)]))
|
||||
print(cards)
|
||||
winner = game.compare_cards(cards, trumpf_color)
|
||||
players[winner].add_points(1)
|
||||
|
||||
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:
|
||||
PREVIOUS_CONFIG = main()
|
||||
while screen_handler.console_input("Would you like to play again?",
|
||||
"[Y/n]", screen) in YES:
|
||||
screen.refresh()
|
||||
PREVIOUS_CONFIG = main(first_time=False,
|
||||
previous_config=PREVIOUS_CONFIG)
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
|
||||
Terminal.clear()
|
||||
print("Thank you for playing!")
|
||||
'''EPR 07 Aufgabe 3'''
|
||||
__author__ = "7987847, Werner, 7347119, Fajst, 7735965, Melikidze"
|
||||
|
||||
from time import sleep
|
||||
from random import randint
|
||||
|
||||
from cmd_interface import Matrix, Terminal
|
||||
import screen_handler
|
||||
import game
|
||||
from game_bot import BOT
|
||||
from game_player import PLAYER
|
||||
|
||||
# initialize screen
|
||||
screen = Matrix()
|
||||
|
||||
NO = ["n", 'N', 'no', 'No', 'NO', 'nO','']
|
||||
YES = ["y", 'Y', 'yes', 'Yes', 'YES', 'yES','yEs','YeS','yES', '']
|
||||
|
||||
PREVIOUS_CONFIG = None
|
||||
|
||||
def main(first_time:bool=True, previous_config = None):
|
||||
'''
|
||||
The main function of the game
|
||||
input:
|
||||
- first_time: bool
|
||||
if the game is started for the first time
|
||||
- previous_config: list
|
||||
previous config of the game
|
||||
|
||||
output:
|
||||
- previous_config: list
|
||||
previous config of the game
|
||||
'''
|
||||
# welcome screen - only shown on first start
|
||||
if first_time:
|
||||
screen.refresh()
|
||||
screen.set_frame(int(Terminal.get_columns() / 2 - 25),
|
||||
int(Terminal.get_lines() / 2 - 10), 50, 20, rounded=True,
|
||||
title="Welcome to the game")
|
||||
screen.set_string_center(int(Terminal.get_lines() /2 - 7),
|
||||
"Follow these instructions")
|
||||
screen.set_string_center(int(Terminal.get_lines() /2 - 6),
|
||||
"for an enhanced gaming experience:")
|
||||
screen.set_string_center(int(Terminal.get_lines() /2 - 4),
|
||||
"1. Make sure your terminal is")
|
||||
screen.set_string_center(int(Terminal.get_lines() /2 - 3),
|
||||
" fullscreen or at least 80x24")
|
||||
screen.set_string_center(int(Terminal.get_lines() /2),
|
||||
"2. Make sure to not resize your")
|
||||
screen.set_string_center(int(Terminal.get_lines() /2 + 1),
|
||||
" terminal during gameplay")
|
||||
screen.set_string_center(int(Terminal.get_lines() /2 + 4),
|
||||
"Your terminal currently has the size:")
|
||||
screen.set_string_center(int(Terminal.get_lines() /2 + 5),
|
||||
f"{Terminal.get_columns()}x{Terminal.get_lines()}")
|
||||
screen.set_string_center(int(Terminal.get_lines() /2 + 7),
|
||||
"If your terminal is not fullscreen or")
|
||||
screen.set_string_center(int(Terminal.get_lines() /2 + 8),
|
||||
"at least 80x28, the game will pause")
|
||||
screen.set_string_center(int(Terminal.get_lines() /2 + 9),
|
||||
"and display an error message until resolved")
|
||||
# ask if user wants to see the rules
|
||||
if screen_handler.console_input(
|
||||
"Would you like to check out the rules of the game?", "[Y/n]",
|
||||
screen) in YES:
|
||||
screen_handler.game_rules(screen)
|
||||
screen.refresh()
|
||||
# ask if user wants to reuse the previous config
|
||||
# only shown if the game is not started for the first time
|
||||
if previous_config is not None and screen_handler.console_input(
|
||||
"Would you like to reuse the configuration from the last game?",
|
||||
"[Y/n]", screen) in YES:
|
||||
pass
|
||||
else:
|
||||
# else show config screen
|
||||
previous_config = screen_handler.config_sequence(screen)
|
||||
# previous_config = ['', <Player count>, '<Bot Count>']
|
||||
|
||||
screen.refresh()
|
||||
screen.print()
|
||||
|
||||
# game initialization
|
||||
# create players and bots
|
||||
players = []
|
||||
|
||||
# create players
|
||||
# Ask for player names, set cards to empty list
|
||||
# PLAYER(name, cards)
|
||||
for i in range(0, int(previous_config[1])):
|
||||
players.append(PLAYER(screen_handler.console_input(
|
||||
f'Name for Player {i + 1}: In der kürze liegt die Würze \
|
||||
(In short lies the spice :) )', '', screen=screen), []))
|
||||
# create bots
|
||||
# set cards to empty list
|
||||
# id is number of the bot starting from 1
|
||||
# name is Bot <id>
|
||||
# BOT(name, id, cards)
|
||||
for i in range(0, int(previous_config[2])):
|
||||
players.append(BOT(f'Bot {i + 1}', i + 1, []))
|
||||
|
||||
screen.refresh()
|
||||
|
||||
# starting screen with player names
|
||||
screen_handler.starting_screen(screen, players)
|
||||
|
||||
sleep(1)
|
||||
|
||||
screen.refresh()
|
||||
|
||||
# determine the amount of turns
|
||||
# 52 cards per card deck
|
||||
max_turns = int(52 / len(players))
|
||||
# debug to shorten game
|
||||
# max_turns = 3
|
||||
|
||||
# main game loop
|
||||
for turn in range(1, max_turns):
|
||||
SUITS = ['Spades', 'Hearts', 'Diamonds', 'Clubs']
|
||||
SUITS_SYM = ["♠", "♥", "♦", "♣"]
|
||||
# determine trumpf color for this turn
|
||||
# is determined randomly
|
||||
trumpf_color = SUITS[randint(0, 3)]
|
||||
|
||||
# show trumpf screen
|
||||
screen_handler.trumpf_screen(screen, trumpf_color)
|
||||
sleep(2)
|
||||
|
||||
# create and deal cards
|
||||
card_deck = game.create_cards()
|
||||
# deal_cards(card_deck, amount, turn)
|
||||
# dealt_cards is a tuple of lists
|
||||
dealt_cards = game.deal_cards(card_deck, int(previous_config[1]) +
|
||||
int(previous_config[2]), turn)
|
||||
|
||||
# set cards for each player
|
||||
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):
|
||||
cards = []
|
||||
# each player plays a card
|
||||
for player in players:
|
||||
# if player is a bot, use bot interface
|
||||
if player.is_bot():
|
||||
cards.append(screen_handler.bot_interface(screen, player,
|
||||
turn, stiche + 1))
|
||||
sleep(0.5)
|
||||
# else use player interface
|
||||
else:
|
||||
cards.append(screen_handler.player_interface(
|
||||
screen, player, turn, stiche + 1, trumpf_color,
|
||||
SUITS_SYM[SUITS.index(trumpf_color)]))
|
||||
# both the bot and the player interface return the played card
|
||||
|
||||
# determine winner of the trick
|
||||
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!")
|
||||
|
|
200
regExpr_ex1.py
200
regExpr_ex1.py
|
@ -1,100 +1,100 @@
|
|||
'''EPR 07 Aufgabe 1'''
|
||||
__author__ = "7987847, Werner, 7347119, Fajst, 7735965, Melikidze"
|
||||
|
||||
import re
|
||||
|
||||
|
||||
# a) All character strings between < and the next >.
|
||||
# The two < and > can also be output. Example: <a>, <span …>.
|
||||
# b) All (annual) numbers between 1900 and 2099.
|
||||
|
||||
|
||||
def extract_annual(text):
|
||||
'''
|
||||
Extract all annual numbers between 1900 and 2099.
|
||||
Return a list of strings.
|
||||
valid years are 1900-2099
|
||||
'''
|
||||
# Extract all annual numbers between 1900 and 2099.
|
||||
# Return a list of strings.
|
||||
# valid years are 1900-2099
|
||||
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)
|
||||
|
||||
|
||||
def extract_tags(text):
|
||||
'''
|
||||
Extract all tags.
|
||||
Return a list of strings.
|
||||
'''
|
||||
# Extract all tags.
|
||||
# Return a list of strings.
|
||||
return re.findall(r'<[^>]+>', text)
|
||||
|
||||
|
||||
def extract_strings(text):
|
||||
'''
|
||||
Extract all strings outside that are between > and <.
|
||||
Return a list of strings.
|
||||
'''
|
||||
# Extract all strings outside that are between > and <.
|
||||
# Return a list of strings.
|
||||
return re.findall(r'>([^<]+)<', text)
|
||||
|
||||
|
||||
def main():
|
||||
'''
|
||||
Main function.
|
||||
'''
|
||||
# open file
|
||||
with open('PythonEntwicklungG.txt', 'r') as file:
|
||||
# read a list of lines into data
|
||||
data = file.readlines()
|
||||
file.close()
|
||||
|
||||
data_extracted = []
|
||||
for line in data:
|
||||
tag_list = extract_tags(line)
|
||||
if tag_list:
|
||||
data_extracted.append(tag_list)
|
||||
strings_list = extract_strings(line)
|
||||
if strings_list:
|
||||
data_extracted.append(strings_list)
|
||||
annual_list = extract_annual(line)
|
||||
if annual_list:
|
||||
data_extracted.append(annual_list)
|
||||
|
||||
for _ in data_extracted:
|
||||
if type(_) == list:
|
||||
for __ in _:
|
||||
# check the type of the element
|
||||
try:
|
||||
if type(int(__)) == int:
|
||||
# print with formatted tab spacing and color in Red
|
||||
print(
|
||||
f'{__:<110} <--- is an annual number',
|
||||
end='\t\n')
|
||||
|
||||
elif type(__) == str:
|
||||
# check if the string is a tag
|
||||
if __.startswith('<') and __.endswith('>'):
|
||||
print(
|
||||
f'{__:<110} <--- is a Tag string',
|
||||
end='\t\n')
|
||||
else:
|
||||
print(f'{__:<110} <--- is a string',
|
||||
end='\t\n')
|
||||
|
||||
except ValueError:
|
||||
if __.startswith('<') and __.endswith('>'):
|
||||
print(f'{__:<110} <--- is a Tag string',
|
||||
end='\t\n')
|
||||
else:
|
||||
print(f'{__:<110} <--- is a string', end='\t\n')
|
||||
|
||||
else:
|
||||
print(_)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
'''EPR 07 Aufgabe 1'''
|
||||
__author__ = "7987847, Werner, 7347119, Fajst, 7735965, Melikidze"
|
||||
|
||||
import re
|
||||
|
||||
|
||||
# a) All character strings between < and the next >.
|
||||
# The two < and > can also be output. Example: <a>, <span …>.
|
||||
# b) All (annual) numbers between 1900 and 2099.
|
||||
|
||||
|
||||
def extract_annual(text):
|
||||
'''
|
||||
Extract all annual numbers between 1900 and 2099.
|
||||
Return a list of strings.
|
||||
valid years are 1900-2099
|
||||
'''
|
||||
# Extract all annual numbers between 1900 and 2099.
|
||||
# Return a list of strings.
|
||||
# valid years are 1900-2099
|
||||
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)
|
||||
|
||||
|
||||
def extract_tags(text):
|
||||
'''
|
||||
Extract all tags.
|
||||
Return a list of strings.
|
||||
'''
|
||||
# Extract all tags.
|
||||
# Return a list of strings.
|
||||
return re.findall(r'<[^>]+>', text)
|
||||
|
||||
|
||||
def extract_strings(text):
|
||||
'''
|
||||
Extract all strings outside that are between > and <.
|
||||
Return a list of strings.
|
||||
'''
|
||||
# Extract all strings outside that are between > and <.
|
||||
# Return a list of strings.
|
||||
return re.findall(r'>([^<]+)<', text)
|
||||
|
||||
|
||||
def main():
|
||||
'''
|
||||
Main function.
|
||||
'''
|
||||
# open file
|
||||
with open('PythonEntwicklungG.txt', 'r') as file:
|
||||
# read a list of lines into data
|
||||
data = file.readlines()
|
||||
file.close()
|
||||
|
||||
data_extracted = []
|
||||
for line in data:
|
||||
tag_list = extract_tags(line)
|
||||
if tag_list:
|
||||
data_extracted.append(tag_list)
|
||||
strings_list = extract_strings(line)
|
||||
if strings_list:
|
||||
data_extracted.append(strings_list)
|
||||
annual_list = extract_annual(line)
|
||||
if annual_list:
|
||||
data_extracted.append(annual_list)
|
||||
|
||||
for _ in data_extracted:
|
||||
if type(_) == list:
|
||||
for __ in _:
|
||||
# check the type of the element
|
||||
try:
|
||||
if type(int(__)) == int:
|
||||
# print with formatted tab spacing and color in Red
|
||||
print(
|
||||
f'{__:<110} <--- is an annual number',
|
||||
end='\t\n')
|
||||
|
||||
elif type(__) == str:
|
||||
# check if the string is a tag
|
||||
if __.startswith('<') and __.endswith('>'):
|
||||
print(
|
||||
f'{__:<110} <--- is a Tag string',
|
||||
end='\t\n')
|
||||
else:
|
||||
print(f'{__:<110} <--- is a string',
|
||||
end='\t\n')
|
||||
|
||||
except ValueError:
|
||||
if __.startswith('<') and __.endswith('>'):
|
||||
print(f'{__:<110} <--- is a Tag string',
|
||||
end='\t\n')
|
||||
else:
|
||||
print(f'{__:<110} <--- is a string', end='\t\n')
|
||||
|
||||
else:
|
||||
print(_)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
@ -1,418 +1,418 @@
|
|||
'''EPR 07 Aufgabe 3'''
|
||||
__author__ = "7987847, Werner, 7347119, Fajst, 7735965, Melikidze"
|
||||
|
||||
from time import sleep
|
||||
from cmd_interface import Matrix, Terminal
|
||||
from game_player import PLAYER
|
||||
from game_bot import BOT
|
||||
|
||||
|
||||
def console_input(text:str, input_str:str, screen:Matrix, fullscreen=False):
|
||||
'''
|
||||
Prints a text and waits for user input
|
||||
input:
|
||||
- text: str
|
||||
text to print
|
||||
- input_str: str
|
||||
input string
|
||||
- screen: Matrix
|
||||
screen to print on
|
||||
- fullscreen: bool
|
||||
if the screen is fullscreen
|
||||
output:
|
||||
- input: str
|
||||
user input
|
||||
'''
|
||||
screen.set_string(2, Terminal.get_lines() - 2, text)
|
||||
screen.set(0, Terminal.get_lines() - 2, "│")
|
||||
screen.set_string(0, Terminal.get_lines() - 3,
|
||||
"╭─────────────────────────── ── ── ─ ─ ─")
|
||||
if fullscreen:
|
||||
screen.set_string(0, Terminal.get_lines() - 3,
|
||||
"├─────────────────────────── ── ── ─ ─ ─")
|
||||
screen.set_string(0, Terminal.get_lines() - 1,
|
||||
" ─ ─ ─ ── ── ")
|
||||
screen.print()
|
||||
return input("╰→ " + input_str + " ")
|
||||
|
||||
|
||||
def game_rules(screen:Matrix):
|
||||
'''
|
||||
Prints the game rules
|
||||
input:
|
||||
- screen: Matrix
|
||||
screen to print on
|
||||
'''
|
||||
screen.refresh()
|
||||
screen.set_frame(0, 0, Terminal.get_columns() - 1,
|
||||
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 - 5),
|
||||
"1. The goal is to play the highest card.")
|
||||
screen.set_string(2, int(Terminal.get_lines() /2 - 4),
|
||||
"2. The trumpf color outweights all other colors.")
|
||||
screen.set_string(2, int(Terminal.get_lines() /2 - 3),
|
||||
"3. The player who wins the most amounts of tricks\
|
||||
(Stiche) wins the game.")
|
||||
screen.set_string(2, int(Terminal.get_lines() /2 + 3),
|
||||
"Press ENTER key to continue...")
|
||||
screen.print()
|
||||
input()
|
||||
|
||||
|
||||
def config_sequence(screen:Matrix):
|
||||
'''
|
||||
Prints the game configuration sequence
|
||||
input:
|
||||
- screen: Matrix
|
||||
screen to print on
|
||||
output:
|
||||
- config: list
|
||||
list of the game configuration
|
||||
'''
|
||||
screen.refresh()
|
||||
screen.set_frame(int(Terminal.get_columns() / 2 - 25),
|
||||
int(Terminal.get_lines() / 2 - 10), 50, 20, rounded=True,
|
||||
title="Game Configuration")
|
||||
screen.set_string_center(int(Terminal.get_lines() /2 - 6),
|
||||
"Please answer the questions below:")
|
||||
config = ['', '1', '1']
|
||||
question_possible_asnwers = ['0 - 5', '']
|
||||
previous_question = ""
|
||||
question_no = 0
|
||||
for i in ['How many players are playing?',
|
||||
'How many bots should be playing?']:
|
||||
wrong_input = True
|
||||
while wrong_input:
|
||||
screen.set_string(int(Terminal.get_columns() / 2 - 24),
|
||||
int(Terminal.get_lines() /2 - 4 + question_no),
|
||||
" ")
|
||||
screen.set_string(int(Terminal.get_columns() / 2 - 24),
|
||||
int(Terminal.get_lines() /2 - 2 + question_no),
|
||||
" ")
|
||||
screen.set_string_center(int(Terminal.get_lines() /2 - 4 +\
|
||||
question_no), previous_question + " " + config[question_no])
|
||||
screen.set_string_center(int(Terminal.get_lines() /2 - 2 +\
|
||||
question_no), i)
|
||||
screen.set_frame(int(Terminal.get_columns() / 2 - 24),
|
||||
int(Terminal.get_lines() / 2 - 3 + question_no),
|
||||
48, 2,double=True)
|
||||
input = console_input(i, "[" +\
|
||||
question_possible_asnwers[question_no] + "]", screen)
|
||||
if input.isdigit():
|
||||
if int(question_possible_asnwers[question_no].split(" - ")[0])\
|
||||
<= int(input) <=\
|
||||
int(question_possible_asnwers[question_no].split(" - "\
|
||||
)[1]):
|
||||
wrong_input = False
|
||||
config[question_no + 1] = input
|
||||
previous_question = i
|
||||
question_no += 1
|
||||
question_possible_asnwers[1] = f"{'0' if config[1] == '5' else '2' if config[1] == '0' else '1'} -\
|
||||
{5 - int(config[1])}"
|
||||
return config
|
||||
|
||||
|
||||
def starting_screen(screen:Matrix, players:list):
|
||||
'''
|
||||
Prints the starting screen
|
||||
input:
|
||||
- screen: Matrix
|
||||
screen to print on
|
||||
- players: list
|
||||
list of the players
|
||||
'''
|
||||
screen.refresh()
|
||||
screen.set_frame(int(Terminal.get_columns() / 2 - 25),
|
||||
int(Terminal.get_lines() / 2 - 10), 50, 20, rounded=True,
|
||||
title="Preparing...")
|
||||
screen.set_string_center(int(Terminal.get_lines() /2 - 6),
|
||||
"The game is starting...")
|
||||
screen.set_string_center(int(Terminal.get_lines() /2 - 4),
|
||||
"Here are the players:")
|
||||
|
||||
for i in range(len(players)):
|
||||
screen.set_string_center(int(Terminal.get_lines() /2 - 3 + i),
|
||||
players[i].get_name())
|
||||
|
||||
screen.print()
|
||||
|
||||
|
||||
def add_bot_font(screen:Matrix, bot:int):
|
||||
'''
|
||||
Adds the bot font to the screen
|
||||
input:
|
||||
- screen: Matrix
|
||||
screen to print on
|
||||
- bot: int
|
||||
bot number
|
||||
'''
|
||||
line_1 = "$$$$$$$\ $$\ "
|
||||
line_2 = "$$ __$$\ $$ | "
|
||||
line_3 = "$$ | $$ | $$$$$$\ $$$$$$\ "
|
||||
line_4 = "$$$$$$$\ |$$ __$$\\_$$ _| "
|
||||
line_5 = "$$ __$$\ $$ / $$ | $$ | "
|
||||
line_6 = "$$ | $$ |$$ | $$ | $$ |$$\ "
|
||||
line_7 = "$$$$$$$ |\$$$$$$ | \$$$$ | "
|
||||
line_8 = "\_______/ \______/ \____/ "
|
||||
|
||||
if bot == 1:
|
||||
screen.set_string_center(4, line_1 + " $$\ ")
|
||||
screen.set_string_center(5, line_2 + " $$$$ | ")
|
||||
screen.set_string_center(6, line_3 + " \_$$ | ")
|
||||
screen.set_string_center(7, line_4 + " $$ | ")
|
||||
screen.set_string_center(8, line_5 + " $$ | ")
|
||||
screen.set_string_center(9, line_6 + " $$ | ")
|
||||
screen.set_string_center(10, line_7 + " $$$$$$\ ")
|
||||
screen.set_string_center(11, line_8 + " \______|")
|
||||
|
||||
elif bot == 2:
|
||||
screen.set_string_center(4, line_1 + " $$$$$$\ ")
|
||||
screen.set_string_center(5, line_2 + "$$ __$$\ ")
|
||||
screen.set_string_center(6, line_3 + "\__/ $$ |")
|
||||
screen.set_string_center(7, line_4 + " $$$$$$ |")
|
||||
screen.set_string_center(8, line_5 + "$$ ____/ ")
|
||||
screen.set_string_center(9, line_6 + "$$ | ")
|
||||
screen.set_string_center(10, line_7 + "$$$$$$$$\ ")
|
||||
screen.set_string_center(11, line_8 + "\________|")
|
||||
|
||||
elif bot == 3:
|
||||
screen.set_string_center(4, line_1 + " $$$$$$\ ")
|
||||
screen.set_string_center(5, line_2 + "$$ ___$$\ ")
|
||||
screen.set_string_center(6, line_3 + "\_/ $$ |")
|
||||
screen.set_string_center(7, line_4 + " $$$$$ / ")
|
||||
screen.set_string_center(8, line_5 + " \___$$\ ")
|
||||
screen.set_string_center(9, line_6 + "$$\ $$ |")
|
||||
screen.set_string_center(10, line_7 + "\$$$$$$ |")
|
||||
screen.set_string_center(11, line_8 + " \______/ ")
|
||||
|
||||
elif bot == 4:
|
||||
screen.set_string_center(4, line_1 + "$$\ $$\ ")
|
||||
screen.set_string_center(5, line_2 + "$$ | $$ |")
|
||||
screen.set_string_center(6, line_3 + "$$ | $$ |")
|
||||
screen.set_string_center(7, line_4 + " $$$$$$$$ |")
|
||||
screen.set_string_center(8, line_5 + "\_____$$ |")
|
||||
screen.set_string_center(9, line_6 + " $$ |")
|
||||
screen.set_string_center(10, line_7 + " $$ |")
|
||||
screen.set_string_center(11, line_8 + " \__|")
|
||||
|
||||
elif bot == 5:
|
||||
screen.set_string_center(4, line_1 + "$$$$$$$\ ")
|
||||
screen.set_string_center(5, line_2 + "$$ ____| ")
|
||||
screen.set_string_center(6, line_3 + "$$ | ")
|
||||
screen.set_string_center(7, line_4 + "$$$$$$$\ ")
|
||||
screen.set_string_center(8, line_5 + "\_____$$\ ")
|
||||
screen.set_string_center(9, line_6 + "$$\ $$ |")
|
||||
screen.set_string_center(10, line_7 + "\$$$$$$ |")
|
||||
screen.set_string_center(11, line_8 + " \______/ ")
|
||||
|
||||
|
||||
screen.print()
|
||||
|
||||
|
||||
def draw_player_cards(screen:Matrix, cards:list, players = None):
|
||||
'''
|
||||
Draws the cards of the players
|
||||
input:
|
||||
- screen: Matrix
|
||||
screen to print on
|
||||
- cards: list
|
||||
list of the cards
|
||||
- players: list
|
||||
list of the players
|
||||
'''
|
||||
card1 = "╔═══╗"
|
||||
card2 = "║ X ║"
|
||||
card3 = "║ X ║"
|
||||
card4 = "╚═══╝"
|
||||
|
||||
SUITS = ["♠", "♥", "♦", "♣"]
|
||||
RANKS = ["A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"]
|
||||
|
||||
y = 5
|
||||
x = 0
|
||||
|
||||
for i in range(len(cards)):
|
||||
card = cards[i]
|
||||
if Terminal.get_columns() < x + 10:
|
||||
y += 7
|
||||
x = 0
|
||||
if card.get("suit") == "Spades":
|
||||
card2 = "║ ♠ ║"
|
||||
elif card.get("suit") == "Hearts":
|
||||
card2 = "║ ♥ ║"
|
||||
elif card.get("suit") == "Diamonds":
|
||||
card2 = "║ ♦ ║"
|
||||
elif card.get("suit") == "Clubs":
|
||||
card2 = "║ ♣ ║"
|
||||
|
||||
if card.get("rank") == "Ace":
|
||||
card3 = "║ A ║"
|
||||
elif card.get("rank") == "Jack":
|
||||
card3 = "║ J ║"
|
||||
elif card.get("rank") == "Queen":
|
||||
card3 = "║ Q ║"
|
||||
elif card.get("rank") == "King":
|
||||
card3 = "║ K ║"
|
||||
elif card.get("rank") == "10":
|
||||
card3 = "║10 ║"
|
||||
else:
|
||||
card3 = f"║ {card.get('rank')} ║"
|
||||
if players is not None:
|
||||
screen.set_string(3 + x, y - 1, " " + players[i].get_name() + ": \
|
||||
" + str(players[i].get_points()) + " points")
|
||||
else:
|
||||
screen.set_string(3 + x, y - 1, " " + str(i + 1))
|
||||
screen.set_string(3 + x, y, card1)
|
||||
screen.set_string(3 + x, y + 1, card2)
|
||||
screen.set_string(3 + x, y + 2, card3)
|
||||
screen.set_string(3 + x, y + 3, card4)
|
||||
|
||||
if players is not None:
|
||||
x += 16
|
||||
x += 6
|
||||
|
||||
|
||||
|
||||
def player_interface(screen:Matrix, player:PLAYER, round_no:int, stich:int,
|
||||
trumpf:str, trumpf_sym:str):
|
||||
'''
|
||||
Draws the interface for the player
|
||||
input:
|
||||
- screen: Matrix
|
||||
screen to print on
|
||||
- player: PLAYER
|
||||
player object
|
||||
- round_no: int
|
||||
number of the round
|
||||
- stich: int
|
||||
number of the stich
|
||||
- trumpf: str
|
||||
trumpf of the round
|
||||
- trumpf_sym: str
|
||||
symbol of the trumpf
|
||||
'''
|
||||
screen.refresh()
|
||||
screen.set_frame(0, 0, Terminal.get_columns() - 1,
|
||||
Terminal.get_lines() - 1, rounded=True, title=f"Player \
|
||||
'{player.get_name()}' is playing in round NO. \
|
||||
{round_no} and trick NO. {stich}")
|
||||
screen.set_string(Terminal.get_columns() - len(trumpf + " ") - 2,
|
||||
2, "Trumpf: " + trumpf + " " + trumpf_sym)
|
||||
screen.set_string(2, 2, f"Points of player {player.get_name()}: \
|
||||
{player.get_points()}")
|
||||
draw_player_cards(screen, player.get_cards())
|
||||
screen.print()
|
||||
wrong_input = True
|
||||
while wrong_input:
|
||||
chosen_card = console_input("Choose a card by its number", "[1 - " +\
|
||||
str(len(player.get_cards())) + "]", screen, fullscreen=True)
|
||||
if chosen_card.isdigit():
|
||||
if int(chosen_card) > 0 and int(chosen_card) <=\
|
||||
len(player.get_cards()):
|
||||
wrong_input = False
|
||||
return player.pop_card(int(chosen_card) - 1)
|
||||
|
||||
def bot_interface(screen:Matrix, bot:BOT, round_no:int, stich:int):
|
||||
'''
|
||||
Draws the interface for the bot
|
||||
input:
|
||||
- screen: Matrix
|
||||
screen to print on
|
||||
- bot: BOT
|
||||
bot object
|
||||
- round_no: int
|
||||
number of the round
|
||||
- stich: int
|
||||
number of the stich
|
||||
'''
|
||||
screen.refresh()
|
||||
screen.set_frame(0, 0, Terminal.get_columns() - 1,\
|
||||
Terminal.get_lines() - 1, rounded=True, title=f"Bot {bot.get_name()} \
|
||||
is playing in round NO. {round_no}, trick NO. {stich}")
|
||||
add_bot_font(screen, bot.get_bot_number())
|
||||
screen.print()
|
||||
return bot.play_card()
|
||||
|
||||
def winner_screen(screen, winner, players:list):
|
||||
'''
|
||||
Draws the screen for the winner
|
||||
input:
|
||||
- screen: Matrix
|
||||
screen to print on
|
||||
- winner: PLAYER
|
||||
player object
|
||||
- players: list
|
||||
list of all players
|
||||
'''
|
||||
screen.refresh()
|
||||
screen.set_frame(int(Terminal.get_columns() / 2 - 25),
|
||||
int(Terminal.get_columns() / 2 - 25), 50, 20, rounded=True,
|
||||
title=f"Player '{winner.get_name()}' won the game!")
|
||||
screen.set_string_center(int(Terminal.get_columns() / 2), "Congratulations!")
|
||||
screen.print()
|
||||
|
||||
def trumpf_screen(screen:Matrix, trumpf:str):
|
||||
'''
|
||||
Draws the screen for the trumpf
|
||||
input:
|
||||
- screen: Matrix
|
||||
screen to print on
|
||||
- trumpf: str
|
||||
trumpf of the round
|
||||
'''
|
||||
screen.refresh()
|
||||
screen.set_frame(int(Terminal.get_columns() / 2 - 25),
|
||||
int(Terminal.get_lines() / 2 - 10), 50, 20,
|
||||
rounded=True, title="Trumpf")
|
||||
screen.set_string_center( int(Terminal.get_lines() / 2 - 1),
|
||||
"The trumpf is:")
|
||||
screen.set_string_center( int(Terminal.get_lines() / 2), trumpf)
|
||||
screen.print()
|
||||
|
||||
def stich_win_screen(screen:Matrix, winner, players:list, cards:list,
|
||||
trumpf:str, trumpf_sym:str):
|
||||
'''
|
||||
Draws the screen for the stich winner
|
||||
input:
|
||||
- screen: Matrix
|
||||
screen to print on
|
||||
- winner: PLAYER
|
||||
player object
|
||||
- players: list
|
||||
list of all players
|
||||
- cards: list
|
||||
list of all cards
|
||||
- trumpf: str
|
||||
trumpf of the round
|
||||
- trumpf_sym: str
|
||||
symbol of the trumpf
|
||||
'''
|
||||
screen.refresh()
|
||||
screen.set_frame(0, 0, Terminal.get_columns() - 1,
|
||||
Terminal.get_lines() - 1, rounded=True, title=f"Player \
|
||||
'{winner.get_name()}' won the trick!")
|
||||
screen.set_frame(int(Terminal.get_columns() / 2 - 25), 19, 50, 4,
|
||||
double=True)
|
||||
screen.set_string_center(20, "Congratulations!")
|
||||
screen.set_string_center(21, f"Player '{winner.get_name()}'\
|
||||
won the trick!")
|
||||
screen.set_string_center(22, "Press ENTER to continue...")
|
||||
screen.set_string(Terminal.get_columns() - len(trumpf + " ") - 2,
|
||||
2, "Trumpf: " + trumpf + " " + trumpf_sym)
|
||||
draw_player_cards(screen, cards, players)
|
||||
screen.print()
|
||||
input()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
# Create a new screen
|
||||
screen = Matrix(Terminal.get_columns(), Terminal.get_lines())
|
||||
screen.set_frame(0, 0, Terminal.get_columns() - 1,
|
||||
Terminal.get_lines() - 1, rounded=True, title="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.print()
|
||||
input()
|
||||
'''EPR 07 Aufgabe 3'''
|
||||
__author__ = "7987847, Werner, 7347119, Fajst, 7735965, Melikidze"
|
||||
|
||||
from time import sleep
|
||||
from cmd_interface import Matrix, Terminal
|
||||
from game_player import PLAYER
|
||||
from game_bot import BOT
|
||||
|
||||
|
||||
def console_input(text:str, input_str:str, screen:Matrix, fullscreen=False):
|
||||
'''
|
||||
Prints a text and waits for user input
|
||||
input:
|
||||
- text: str
|
||||
text to print
|
||||
- input_str: str
|
||||
input string
|
||||
- screen: Matrix
|
||||
screen to print on
|
||||
- fullscreen: bool
|
||||
if the screen is fullscreen
|
||||
output:
|
||||
- input: str
|
||||
user input
|
||||
'''
|
||||
screen.set_string(2, Terminal.get_lines() - 2, text)
|
||||
screen.set(0, Terminal.get_lines() - 2, "│")
|
||||
screen.set_string(0, Terminal.get_lines() - 3,
|
||||
"╭─────────────────────────── ── ── ─ ─ ─")
|
||||
if fullscreen:
|
||||
screen.set_string(0, Terminal.get_lines() - 3,
|
||||
"├─────────────────────────── ── ── ─ ─ ─")
|
||||
screen.set_string(0, Terminal.get_lines() - 1,
|
||||
" ─ ─ ─ ── ── ")
|
||||
screen.print()
|
||||
return input("╰→ " + input_str + " ")
|
||||
|
||||
|
||||
def game_rules(screen:Matrix):
|
||||
'''
|
||||
Prints the game rules
|
||||
input:
|
||||
- screen: Matrix
|
||||
screen to print on
|
||||
'''
|
||||
screen.refresh()
|
||||
screen.set_frame(0, 0, Terminal.get_columns() - 1,
|
||||
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 - 5),
|
||||
"1. The goal is to play the highest card.")
|
||||
screen.set_string(2, int(Terminal.get_lines() /2 - 4),
|
||||
"2. The trumpf color outweights all other colors.")
|
||||
screen.set_string(2, int(Terminal.get_lines() /2 - 3),
|
||||
"3. The player who wins the most amounts of tricks\
|
||||
(Stiche) wins the game.")
|
||||
screen.set_string(2, int(Terminal.get_lines() /2 + 3),
|
||||
"Press ENTER key to continue...")
|
||||
screen.print()
|
||||
input()
|
||||
|
||||
|
||||
def config_sequence(screen:Matrix):
|
||||
'''
|
||||
Prints the game configuration sequence
|
||||
input:
|
||||
- screen: Matrix
|
||||
screen to print on
|
||||
output:
|
||||
- config: list
|
||||
list of the game configuration
|
||||
'''
|
||||
screen.refresh()
|
||||
screen.set_frame(int(Terminal.get_columns() / 2 - 25),
|
||||
int(Terminal.get_lines() / 2 - 10), 50, 20, rounded=True,
|
||||
title="Game Configuration")
|
||||
screen.set_string_center(int(Terminal.get_lines() /2 - 6),
|
||||
"Please answer the questions below:")
|
||||
config = ['', '1', '1']
|
||||
question_possible_asnwers = ['0 - 5', '']
|
||||
previous_question = ""
|
||||
question_no = 0
|
||||
for i in ['How many players are playing?',
|
||||
'How many bots should be playing?']:
|
||||
wrong_input = True
|
||||
while wrong_input:
|
||||
screen.set_string(int(Terminal.get_columns() / 2 - 24),
|
||||
int(Terminal.get_lines() /2 - 4 + question_no),
|
||||
" ")
|
||||
screen.set_string(int(Terminal.get_columns() / 2 - 24),
|
||||
int(Terminal.get_lines() /2 - 2 + question_no),
|
||||
" ")
|
||||
screen.set_string_center(int(Terminal.get_lines() /2 - 4 +\
|
||||
question_no), previous_question + " " + config[question_no])
|
||||
screen.set_string_center(int(Terminal.get_lines() /2 - 2 +\
|
||||
question_no), i)
|
||||
screen.set_frame(int(Terminal.get_columns() / 2 - 24),
|
||||
int(Terminal.get_lines() / 2 - 3 + question_no),
|
||||
48, 2,double=True)
|
||||
input = console_input(i, "[" +\
|
||||
question_possible_asnwers[question_no] + "]", screen)
|
||||
if input.isdigit():
|
||||
if int(question_possible_asnwers[question_no].split(" - ")[0])\
|
||||
<= int(input) <=\
|
||||
int(question_possible_asnwers[question_no].split(" - "\
|
||||
)[1]):
|
||||
wrong_input = False
|
||||
config[question_no + 1] = input
|
||||
previous_question = i
|
||||
question_no += 1
|
||||
question_possible_asnwers[1] = f"{'0' if config[1] == '5' else '2' if config[1] == '0' else '1'} -\
|
||||
{5 - int(config[1])}"
|
||||
return config
|
||||
|
||||
|
||||
def starting_screen(screen:Matrix, players:list):
|
||||
'''
|
||||
Prints the starting screen
|
||||
input:
|
||||
- screen: Matrix
|
||||
screen to print on
|
||||
- players: list
|
||||
list of the players
|
||||
'''
|
||||
screen.refresh()
|
||||
screen.set_frame(int(Terminal.get_columns() / 2 - 25),
|
||||
int(Terminal.get_lines() / 2 - 10), 50, 20, rounded=True,
|
||||
title="Preparing...")
|
||||
screen.set_string_center(int(Terminal.get_lines() /2 - 6),
|
||||
"The game is starting...")
|
||||
screen.set_string_center(int(Terminal.get_lines() /2 - 4),
|
||||
"Here are the players:")
|
||||
|
||||
for i in range(len(players)):
|
||||
screen.set_string_center(int(Terminal.get_lines() /2 - 3 + i),
|
||||
players[i].get_name())
|
||||
|
||||
screen.print()
|
||||
|
||||
|
||||
def add_bot_font(screen:Matrix, bot:int):
|
||||
'''
|
||||
Adds the bot font to the screen
|
||||
input:
|
||||
- screen: Matrix
|
||||
screen to print on
|
||||
- bot: int
|
||||
bot number
|
||||
'''
|
||||
line_1 = "$$$$$$$\ $$\ "
|
||||
line_2 = "$$ __$$\ $$ | "
|
||||
line_3 = "$$ | $$ | $$$$$$\ $$$$$$\ "
|
||||
line_4 = "$$$$$$$\ |$$ __$$\\_$$ _| "
|
||||
line_5 = "$$ __$$\ $$ / $$ | $$ | "
|
||||
line_6 = "$$ | $$ |$$ | $$ | $$ |$$\ "
|
||||
line_7 = "$$$$$$$ |\$$$$$$ | \$$$$ | "
|
||||
line_8 = "\_______/ \______/ \____/ "
|
||||
|
||||
if bot == 1:
|
||||
screen.set_string_center(4, line_1 + " $$\ ")
|
||||
screen.set_string_center(5, line_2 + " $$$$ | ")
|
||||
screen.set_string_center(6, line_3 + " \_$$ | ")
|
||||
screen.set_string_center(7, line_4 + " $$ | ")
|
||||
screen.set_string_center(8, line_5 + " $$ | ")
|
||||
screen.set_string_center(9, line_6 + " $$ | ")
|
||||
screen.set_string_center(10, line_7 + " $$$$$$\ ")
|
||||
screen.set_string_center(11, line_8 + " \______|")
|
||||
|
||||
elif bot == 2:
|
||||
screen.set_string_center(4, line_1 + " $$$$$$\ ")
|
||||
screen.set_string_center(5, line_2 + "$$ __$$\ ")
|
||||
screen.set_string_center(6, line_3 + "\__/ $$ |")
|
||||
screen.set_string_center(7, line_4 + " $$$$$$ |")
|
||||
screen.set_string_center(8, line_5 + "$$ ____/ ")
|
||||
screen.set_string_center(9, line_6 + "$$ | ")
|
||||
screen.set_string_center(10, line_7 + "$$$$$$$$\ ")
|
||||
screen.set_string_center(11, line_8 + "\________|")
|
||||
|
||||
elif bot == 3:
|
||||
screen.set_string_center(4, line_1 + " $$$$$$\ ")
|
||||
screen.set_string_center(5, line_2 + "$$ ___$$\ ")
|
||||
screen.set_string_center(6, line_3 + "\_/ $$ |")
|
||||
screen.set_string_center(7, line_4 + " $$$$$ / ")
|
||||
screen.set_string_center(8, line_5 + " \___$$\ ")
|
||||
screen.set_string_center(9, line_6 + "$$\ $$ |")
|
||||
screen.set_string_center(10, line_7 + "\$$$$$$ |")
|
||||
screen.set_string_center(11, line_8 + " \______/ ")
|
||||
|
||||
elif bot == 4:
|
||||
screen.set_string_center(4, line_1 + "$$\ $$\ ")
|
||||
screen.set_string_center(5, line_2 + "$$ | $$ |")
|
||||
screen.set_string_center(6, line_3 + "$$ | $$ |")
|
||||
screen.set_string_center(7, line_4 + " $$$$$$$$ |")
|
||||
screen.set_string_center(8, line_5 + "\_____$$ |")
|
||||
screen.set_string_center(9, line_6 + " $$ |")
|
||||
screen.set_string_center(10, line_7 + " $$ |")
|
||||
screen.set_string_center(11, line_8 + " \__|")
|
||||
|
||||
elif bot == 5:
|
||||
screen.set_string_center(4, line_1 + "$$$$$$$\ ")
|
||||
screen.set_string_center(5, line_2 + "$$ ____| ")
|
||||
screen.set_string_center(6, line_3 + "$$ | ")
|
||||
screen.set_string_center(7, line_4 + "$$$$$$$\ ")
|
||||
screen.set_string_center(8, line_5 + "\_____$$\ ")
|
||||
screen.set_string_center(9, line_6 + "$$\ $$ |")
|
||||
screen.set_string_center(10, line_7 + "\$$$$$$ |")
|
||||
screen.set_string_center(11, line_8 + " \______/ ")
|
||||
|
||||
|
||||
screen.print()
|
||||
|
||||
|
||||
def draw_player_cards(screen:Matrix, cards:list, players = None):
|
||||
'''
|
||||
Draws the cards of the players
|
||||
input:
|
||||
- screen: Matrix
|
||||
screen to print on
|
||||
- cards: list
|
||||
list of the cards
|
||||
- players: list
|
||||
list of the players
|
||||
'''
|
||||
card1 = "╔═══╗"
|
||||
card2 = "║ X ║"
|
||||
card3 = "║ X ║"
|
||||
card4 = "╚═══╝"
|
||||
|
||||
SUITS = ["♠", "♥", "♦", "♣"]
|
||||
RANKS = ["A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"]
|
||||
|
||||
y = 5
|
||||
x = 0
|
||||
|
||||
for i in range(len(cards)):
|
||||
card = cards[i]
|
||||
if Terminal.get_columns() < x + 10:
|
||||
y += 7
|
||||
x = 0
|
||||
if card.get("suit") == "Spades":
|
||||
card2 = "║ ♠ ║"
|
||||
elif card.get("suit") == "Hearts":
|
||||
card2 = "║ ♥ ║"
|
||||
elif card.get("suit") == "Diamonds":
|
||||
card2 = "║ ♦ ║"
|
||||
elif card.get("suit") == "Clubs":
|
||||
card2 = "║ ♣ ║"
|
||||
|
||||
if card.get("rank") == "Ace":
|
||||
card3 = "║ A ║"
|
||||
elif card.get("rank") == "Jack":
|
||||
card3 = "║ J ║"
|
||||
elif card.get("rank") == "Queen":
|
||||
card3 = "║ Q ║"
|
||||
elif card.get("rank") == "King":
|
||||
card3 = "║ K ║"
|
||||
elif card.get("rank") == "10":
|
||||
card3 = "║10 ║"
|
||||
else:
|
||||
card3 = f"║ {card.get('rank')} ║"
|
||||
if players is not None:
|
||||
screen.set_string(3 + x, y - 1, " " + players[i].get_name() + ": \
|
||||
" + str(players[i].get_points()) + " points")
|
||||
else:
|
||||
screen.set_string(3 + x, y - 1, " " + str(i + 1))
|
||||
screen.set_string(3 + x, y, card1)
|
||||
screen.set_string(3 + x, y + 1, card2)
|
||||
screen.set_string(3 + x, y + 2, card3)
|
||||
screen.set_string(3 + x, y + 3, card4)
|
||||
|
||||
if players is not None:
|
||||
x += 16
|
||||
x += 6
|
||||
|
||||
|
||||
|
||||
def player_interface(screen:Matrix, player:PLAYER, round_no:int, stich:int,
|
||||
trumpf:str, trumpf_sym:str):
|
||||
'''
|
||||
Draws the interface for the player
|
||||
input:
|
||||
- screen: Matrix
|
||||
screen to print on
|
||||
- player: PLAYER
|
||||
player object
|
||||
- round_no: int
|
||||
number of the round
|
||||
- stich: int
|
||||
number of the stich
|
||||
- trumpf: str
|
||||
trumpf of the round
|
||||
- trumpf_sym: str
|
||||
symbol of the trumpf
|
||||
'''
|
||||
screen.refresh()
|
||||
screen.set_frame(0, 0, Terminal.get_columns() - 1,
|
||||
Terminal.get_lines() - 1, rounded=True, title=f"Player \
|
||||
'{player.get_name()}' is playing in round NO. \
|
||||
{round_no} and trick NO. {stich}")
|
||||
screen.set_string(Terminal.get_columns() - len(trumpf + " ") - 2,
|
||||
2, "Trumpf: " + trumpf + " " + trumpf_sym)
|
||||
screen.set_string(2, 2, f"Points of player {player.get_name()}: \
|
||||
{player.get_points()}")
|
||||
draw_player_cards(screen, player.get_cards())
|
||||
screen.print()
|
||||
wrong_input = True
|
||||
while wrong_input:
|
||||
chosen_card = console_input("Choose a card by its number", "[1 - " +\
|
||||
str(len(player.get_cards())) + "]", screen, fullscreen=True)
|
||||
if chosen_card.isdigit():
|
||||
if int(chosen_card) > 0 and int(chosen_card) <=\
|
||||
len(player.get_cards()):
|
||||
wrong_input = False
|
||||
return player.pop_card(int(chosen_card) - 1)
|
||||
|
||||
def bot_interface(screen:Matrix, bot:BOT, round_no:int, stich:int):
|
||||
'''
|
||||
Draws the interface for the bot
|
||||
input:
|
||||
- screen: Matrix
|
||||
screen to print on
|
||||
- bot: BOT
|
||||
bot object
|
||||
- round_no: int
|
||||
number of the round
|
||||
- stich: int
|
||||
number of the stich
|
||||
'''
|
||||
screen.refresh()
|
||||
screen.set_frame(0, 0, Terminal.get_columns() - 1,\
|
||||
Terminal.get_lines() - 1, rounded=True, title=f"Bot {bot.get_name()} \
|
||||
is playing in round NO. {round_no}, trick NO. {stich}")
|
||||
add_bot_font(screen, bot.get_bot_number())
|
||||
screen.print()
|
||||
return bot.play_card()
|
||||
|
||||
def winner_screen(screen, winner, players:list):
|
||||
'''
|
||||
Draws the screen for the winner
|
||||
input:
|
||||
- screen: Matrix
|
||||
screen to print on
|
||||
- winner: PLAYER
|
||||
player object
|
||||
- players: list
|
||||
list of all players
|
||||
'''
|
||||
screen.refresh()
|
||||
screen.set_frame(int(Terminal.get_columns() / 2 - 25),
|
||||
int(Terminal.get_columns() / 2 - 25), 50, 20, rounded=True,
|
||||
title=f"Player '{winner.get_name()}' won the game!")
|
||||
screen.set_string_center(int(Terminal.get_columns() / 2), "Congratulations!")
|
||||
screen.print()
|
||||
|
||||
def trumpf_screen(screen:Matrix, trumpf:str):
|
||||
'''
|
||||
Draws the screen for the trumpf
|
||||
input:
|
||||
- screen: Matrix
|
||||
screen to print on
|
||||
- trumpf: str
|
||||
trumpf of the round
|
||||
'''
|
||||
screen.refresh()
|
||||
screen.set_frame(int(Terminal.get_columns() / 2 - 25),
|
||||
int(Terminal.get_lines() / 2 - 10), 50, 20,
|
||||
rounded=True, title="Trumpf")
|
||||
screen.set_string_center( int(Terminal.get_lines() / 2 - 1),
|
||||
"The trumpf is:")
|
||||
screen.set_string_center( int(Terminal.get_lines() / 2), trumpf)
|
||||
screen.print()
|
||||
|
||||
def stich_win_screen(screen:Matrix, winner, players:list, cards:list,
|
||||
trumpf:str, trumpf_sym:str):
|
||||
'''
|
||||
Draws the screen for the stich winner
|
||||
input:
|
||||
- screen: Matrix
|
||||
screen to print on
|
||||
- winner: PLAYER
|
||||
player object
|
||||
- players: list
|
||||
list of all players
|
||||
- cards: list
|
||||
list of all cards
|
||||
- trumpf: str
|
||||
trumpf of the round
|
||||
- trumpf_sym: str
|
||||
symbol of the trumpf
|
||||
'''
|
||||
screen.refresh()
|
||||
screen.set_frame(0, 0, Terminal.get_columns() - 1,
|
||||
Terminal.get_lines() - 1, rounded=True, title=f"Player \
|
||||
'{winner.get_name()}' won the trick!")
|
||||
screen.set_frame(int(Terminal.get_columns() / 2 - 25), 19, 50, 4,
|
||||
double=True)
|
||||
screen.set_string_center(20, "Congratulations!")
|
||||
screen.set_string_center(21, f"Player '{winner.get_name()}'\
|
||||
won the trick!")
|
||||
screen.set_string_center(22, "Press ENTER to continue...")
|
||||
screen.set_string(Terminal.get_columns() - len(trumpf + " ") - 2,
|
||||
2, "Trumpf: " + trumpf + " " + trumpf_sym)
|
||||
draw_player_cards(screen, cards, players)
|
||||
screen.print()
|
||||
input()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
# Create a new screen
|
||||
screen = Matrix(Terminal.get_columns(), Terminal.get_lines())
|
||||
screen.set_frame(0, 0, Terminal.get_columns() - 1,
|
||||
Terminal.get_lines() - 1, rounded=True, title="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.print()
|
||||
input()
|
||||
|
|
|
@ -1,29 +1,29 @@
|
|||
__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,
|
||||
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),
|
||||
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:
|
||||
|
||||
T -> (TOT)
|
||||
T -> V
|
||||
O -> +
|
||||
T -> (TOT)
|
||||
T -> (TOT)
|
||||
T -> V
|
||||
O -> -
|
||||
T -> V
|
||||
O -> /
|
||||
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:
|
||||
|
||||
T -> (TOT)
|
||||
T -> V
|
||||
O -> +
|
||||
T -> (TOT)
|
||||
T -> V
|
||||
|
||||
__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,
|
||||
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),
|
||||
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:
|
||||
|
||||
T -> (TOT)
|
||||
T -> V
|
||||
O -> +
|
||||
T -> (TOT)
|
||||
T -> (TOT)
|
||||
T -> V
|
||||
O -> -
|
||||
T -> V
|
||||
O -> /
|
||||
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:
|
||||
|
||||
T -> (TOT)
|
||||
T -> V
|
||||
O -> +
|
||||
T -> (TOT)
|
||||
T -> V
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue