def initialize(): input = open("a_example.txt", "r") text = input.read() input.close() first_split = text.split("\n") for i in range(len(first_split)): first_split[i] = first_split[i].strip() first_split = list(filter(None, first_split)) for i, y in zip(first_split, range(len(first_split))): first_split[y] = first_split[y].split(" ") first_row = first_split[0] total_pizzas = int(first_split[0][0]) first_row.pop(0) teams = [] for i in range(int(first_row[0])): teams.append(Team(2)) for i in range(int(first_row[1])): teams.append(Team(3)) for i in range(int(first_row[2])): teams.append(Team(4)) first_split.pop(0) pizzas = [] for _pizza, index in zip(first_split, range(len(first_split))): ingredients_length = _pizza.pop(0) ingredients = _pizza pizza = Pizza(index, ingredients_length, ingredients) pizzas.append(pizza) return teams, pizzas, total_pizzas
class AI: def __init__(self): self._team = Team() def play_round(self): self._team.perform_actions()
def test_if_clear_announcements_works_correctly(self): player1 = Player(name='Marto') player1.set_hand(['10h', 'Jh', 'Qh']) player2 = Player(name='Rado') player2.set_hand(['7s', '8s', '9s']) team = Team(player1=player1, player2=player2) team.clear_announcements() self.assertEqual(team.player1.get_announcements(), []) self.assertEqual(team.player2.get_announcements(), [])
def test_if_constructor_sets_attributes_correctly(self): player1 = Player(name='Marto') player2 = Player(name='Rado') team1 = Team(player1=player1, player2=player2) player3 = Player(name='Gosho') player4 = Player(name='Pesho') team2 = Team(player1=player1, player2=player2) r = Round(round_id=1, team1=team1, team2=team2) self.assertEqual(r.round_id, 'round 1') self.assertEqual(r.team1, team1) self.assertEqual(r.team2, team2)
def test_if_constructor_sets_attributes_correctly(self): player1 = Player(name='Marto') player2 = Player(name='Rado') team1 = Team(team_name='Mechetata', player1=player1, player2=player2) player3 = Player(name='Gosho') player4 = Player(name='Pesho') team2 = Team(team_name='Kotetata', player1=player3, player2=player4) g = Game(game_id=1, team1=team1, team2=team2) self.assertEqual(g.game_id, 'game 1') self.assertEqual(g.team1, team1) self.assertEqual(g.team2, team2)
def main(): player1 = Player(name='Marto') player2 = Player(name='Rado') team1 = Team(team_name='Mechetata', player1=player1, player2=player2) player3 = Player(name='Gosho') player4 = Player(name='Pesho') team2 = Team(team_name='Kotetata', player1=player3, player2=player4) w = WriteToTxt(team1, team2) g1 = Game(game_id=1, team1=team1, team2=team2, write_to_txt=w) g1.play_game() g1.to_json() g2 = Game(game_id=2, team1=team1, team2=team2, write_to_txt=w) g2.play_game() g2.to_json()
def test_if_constructor_sets_attributes_correctly(self): player1 = Player(name='Marto') player2 = Player(name='Rado') team = Team(player1=player1, player2=player2) self.assertEqual(team.team_name, 'Team') self.assertIs(player1, team.player1) self.assertIs(player2, team.player2)
def test_if_compare_best_announcements_works_when_all_announcements_check_out(self): player1 = Player(name='Marto') player2 = Player(name='Rado') player1.set_hand(['Jh', 'Qh', 'Kh']) player2.set_hand(['10d', 'Jd', 'Qd', 'Kd']) team1 = Team(team_name='Mechetata', player1=player1, player2=player2) player3 = Player(name='Gosho') player4 = Player(name='Pesho') player3.set_hand(['Js', 'Qs', 'Ks']) player4.set_hand(['10c', 'Jc', 'Qc', 'Kc']) team2 = Team(team_name='Kotetata', player1=player3, player2=player4) r = Round(round_id=1, team1=team1, team2=team2) r.compare_best_announcements() self.assertEqual(team1.player1.get_announcements(), ['belot']) self.assertEqual(team2.player2.get_announcements(), ['belot'])
def main(): teams = read_teams_names() players = read_player_names(teams[0], teams[1]) player1 = Player(players[0]) player2 = Player(players[1]) team1 = Team(teams[0], player1, player2) player3 = Player(players[2]) player4 = Player(players[3]) team2 = Team(teams[1], player3, player4) write_to_txt = WriteToTxt(team1, team2) write_to_json = WriteToJSON() game_id = 1 while not is_match_won(team1.games_won, team2.games_won): g = Game(game_id=game_id, team1=team1, team2=team2) g.play_game(write_to_txt, write_to_json) game_id += 1
def test_if_clear_announcements_for_round_works_as_expected(self): player1 = Player(name='Marto') player2 = Player(name='Rado') player1.set_hand(['Jh', 'Qh', 'Kh']) player2.set_hand(['10d', 'Jd', 'Qd', 'Kd']) team1 = Team(team_name='Mechetata', player1=player1, player2=player2) player3 = Player(name='Gosho') player4 = Player(name='Pesho') player3.set_hand(['Js', 'Qs', 'Ks']) player4.set_hand(['9c', '10c', 'Jc', 'Qc', 'Kc']) team2 = Team(team_name='Kotetata', player1=player3, player2=player4) r = Round(round_id=1, team1=team1, team2=team2) r.compare_best_announcements() r.clear_scoring_for_round() self.assertEqual(team2.player1.belots, []) self.assertEqual(team2.player1.trieces, []) self.assertEqual(team2.player2.belots, []) self.assertEqual(team2.player2.quintes, [])
def main(): player1 = Player(name='Marto') player2 = Player(name='Rado') player1.set_hand(['Jh', 'Qh', 'Kh']) player2.set_hand(['10d', 'Jd', 'Qd', 'Kd']) team1 = Team(team_name='Mechetata', player1=player1, player2=player2) player3 = Player(name='Gosho') player4 = Player(name='Pesho') player3.set_hand(['Js', 'Qs', 'Ks']) player4.set_hand(['10c', 'Jc', 'Qc', 'Kc']) team2 = Team(team_name='Kotetata', player1=player3, player2=player4) r = Round(round_id=1, team1=team1, team2=team2) print(team1.best_announcement()) print(team2.best_announcement()) print(r.compare_best_announcements()) print(team1.player1.get_announcements(), team1.player2.get_announcements()) print(prettyjson(r.to_dict()))
def __init__(self): self._team = Team()
from entities.team import Team from get_combinations import get_combinations teams, pizzas, total_pizzas = initialize() combinations = get_combinations(total_pizzas, teams) pizzas_sl = create_similarity_levels(pizzas) print(pizzas_sl) delivery_notes = Delivery_Notes() # right now takes only first combination first_combination = combinations[0] # for noOfMembers in first_combination: delivery_notes.add_team(Team(noOfMembers)) for pizza_id in pizzas_sl.keys(): pizza = [pizza for pizza in pizzas if pizza.Id == pizza_id][0] delivery_notes.add_pizza(pizza) delivery_notes.calc_total_score() print(delivery_notes.total_score) file = open("res.txt", "w") file.write(f"{delivery_notes.total_deliveries}\n") for team in delivery_notes.teams: file.write(f"{team.members} ") for pizza in team.pizzas: file.write(f"{pizza.Id} ") file.write("\n")