Merge pull request 'feature: konec hry – cílové skóre a vyhlášení vítěze' (#10) from feature/konec-hry into version/v0.1.0
Reviewed-on: david/kostky#10
This commit was merged in pull request #10.
This commit is contained in:
@@ -3,6 +3,7 @@ from random import randint
|
||||
from os import system, name
|
||||
import re
|
||||
import csv
|
||||
from collections import Counter
|
||||
|
||||
score = 0
|
||||
hodnoty = {}
|
||||
@@ -11,6 +12,7 @@ pointer = ""
|
||||
first = ""
|
||||
h_bool = True
|
||||
aggr = {}
|
||||
final_score = 10000
|
||||
|
||||
with open("hodnoty.csv", "r") as csv_file:
|
||||
csv_reader = csv.reader(csv_file)
|
||||
@@ -126,6 +128,10 @@ def evaluate(inp: Any, count: int, throw: str) -> tuple:
|
||||
h_bool = True
|
||||
next_player()
|
||||
data = ("count", 6, "")
|
||||
if pointer == first:
|
||||
winner = check_win()
|
||||
if winner:
|
||||
data = ("win", winner, aggr[winner])
|
||||
return data
|
||||
else:
|
||||
data = ("msg", "ER03", "Zadejte prosím platnou hodnotu:", count, throw)
|
||||
@@ -146,6 +152,7 @@ def add_players(iter=False):
|
||||
global players
|
||||
global pointer
|
||||
global first
|
||||
global final_score
|
||||
|
||||
if not iter:
|
||||
var = "prvního hráče"
|
||||
@@ -157,6 +164,11 @@ def add_players(iter=False):
|
||||
if inp == "x":
|
||||
if not iter:
|
||||
add_players()
|
||||
inp = input("Zadejte finální skóre (nechte prázdné pro výchozích 10 000): ")
|
||||
if inp != "":
|
||||
inp = int(inp)
|
||||
final_score = inp
|
||||
|
||||
elif inp == "":
|
||||
print("Jméno nemůže být prázdné.")
|
||||
add_players(iter)
|
||||
@@ -172,6 +184,30 @@ def add_players(iter=False):
|
||||
first = inp
|
||||
add_players(True)
|
||||
|
||||
def check_win() -> str:
|
||||
over_limit = {}
|
||||
for p in aggr:
|
||||
if aggr[p] >= final_score:
|
||||
over_limit[p] = aggr[p]
|
||||
|
||||
winner = ""
|
||||
|
||||
if over_limit:
|
||||
over_limit_sorted = dict(sorted(over_limit.items(), key=lambda x: x[1], reverse=True))
|
||||
over_limit_sorted_list = []
|
||||
for ols in over_limit_sorted:
|
||||
over_limit_sorted_list.append((ols, over_limit_sorted[ols]))
|
||||
|
||||
|
||||
count = Counter(list(over_limit_sorted.values()))
|
||||
|
||||
for c in count:
|
||||
if count[c] == 1:
|
||||
winner = over_limit_sorted_list[0][0]
|
||||
break
|
||||
|
||||
return winner
|
||||
|
||||
def game(data: tuple):
|
||||
if data[0] == "count":
|
||||
count = data[1]
|
||||
@@ -179,7 +215,8 @@ def game(data: tuple):
|
||||
if(th == ""):
|
||||
th = throw(count)
|
||||
clear()
|
||||
print(f"Na tahu je {pointer} ({aggr[pointer]})")
|
||||
print(f"Vítězné skóre: {final_score}.")
|
||||
print(f"Na tahu je {pointer} ({aggr[pointer]}).")
|
||||
print(show_throw(th))
|
||||
if not check_value(th) and data[2] == "" and count != 0:
|
||||
global score
|
||||
@@ -211,8 +248,17 @@ def game(data: tuple):
|
||||
else:
|
||||
msg = data[1]
|
||||
print(msg)
|
||||
|
||||
elif data[0] == "win":
|
||||
winner = data[1]
|
||||
score = data[2]
|
||||
|
||||
clear()
|
||||
print(f"Vítězem se stává {winner} s {score} body!")
|
||||
print("Díky za hru a zase příště.")
|
||||
|
||||
def main():
|
||||
clear()
|
||||
print("Vítejte ve hře v kostky!")
|
||||
add_players()
|
||||
input("Prosím, stiskněte enter pro první hod:")
|
||||
|
||||
Reference in New Issue
Block a user