<commit_before>from clue.game.character import Colonel, Scarlet, Professor, Green, White, Peacock
from clue.game.location import Study, Hall, Lounge, Library, BilliardRoom, DiningRoom, Conservatory, Ballroom, Kitchen, HallwayStudyToHall, HallwayHallToLounge, HallwayStudyToLibrary, HallwayHallToBilliardRoom, HallwayLoungeToDiningRoom, HallwayLibraryToBilliardRoom, HallwayBilliardRoomToDiningRoom, HallwayLibraryToConservatory, HallwayBilliardRoomToBallroom, HallwayDiningRoomToKitchen, HallwayConservatoryToBallroom, HallwayBallroomToKitchen
from clue.game.card import Weapon, Suspect, Room
from clue.game.casefile import CaseFile
from clue.game.suggestion import Suggestion
from clue.game.error import GameError
from twisted.python import log
from random import randint, shuffle, choice

TURN_STATE_WAITING_TO_MOVE = "waiting_to_move"
TURN_STATE_WAITING_TO_SUGGEST = "waiting_to_suggest"
TURN_STATE_IS_SUGGESTING = "suggesting"
TURN_STATE_WAITING_TO_ACCUSE = "waiting_to_accuse"
TURN_STATE_IS_ACCUSING = "accusing"

class Game:

	def __init__(self):
		self.players = {}
		self.in_progress = False
		self.num_turns = 0
		self.active_turn = None
		self.active_turn_state = None
		self.case_file = None
		self.active_suggestion = None
		self.active_suggestion_turn = None
		self.winner = None
		self.game_over = False
		self.creator = None

		self.grid = [
			[Study(), HallwayStudyToHall(), Hall(), HallwayHallToLounge(), Lounge()],
			[HallwayStudyToLibrary(), None, HallwayHallToBilliardRoom(), None, HallwayLoungeToDiningRoom()],
			[Library(), HallwayLibraryToBilliardRoom(), BilliardRoom(), HallwayBilliardRoomToDiningRoom(), DiningRoom()],
			[HallwayLibraryToConservatory(), None, HallwayBilliardRoomToBallroom(), None, HallwayDiningRoomToKitchen()],
			[Conservatory(), HallwayConservatoryToBallroom(), Ballroom(), HallwayBallroomToKitchen(), Kitchen()]
		]

	def is_in_progress(self):
		return self.in_progress

	def num_players(self):
		return len(self.players)

	def add_player(self, player):
		if player.id in self.players:
			raise Exception("Player is already part of this game.")

		# What character should this player be?
		characters = [Colonel, Scarlet, Professor, Green, White, Peacock]
		for option in characters:
			unique = True
			for playerId in self.players:
				if self.players[playerId].character.color == option.color:
					unique = False
					break

			if unique:
				player.character = option(player)
				break

		if player.character is None:
			raise Exception("Player has no character.")

		self.players[player.id] = player
		self.broadcast_game_state()
		
		# Start the game if we have enough players.
		if self.num_players() >= 3: self.start()

	def remove_player(self, player):
		try:
			del self.players[player.id]
			self.broadcast_game_state()
		except KeyError: pass

	def start(self):
		if self.in_progress:
			raise Exception("Game has already started.")

		# Build the case file
		# Select one random suspect, one random weapon, and one random room
		deck = self.build_deck()

		suspects = [card for card in deck if card.card_type == "suspect"]
		rooms = [card for card in deck if card.card_type == "room"]
		weapons = [card for card in deck if card.card_type == "weapon"]
		
		self.case_file = CaseFile(choice(suspects), choice(weapons), choice(rooms))

		# Remove these cards from the deck
		deck.remove(self.case_file.suspect)
		deck.remove(self.case_file.weapon)
		deck.remove(self.case_file.location)

		# Shuffle and deal the remaining cards to each player
		shuffle(deck)
		while len(deck) > 0:<commit_msg>changed min player to 6<commit_after>from clue.game.character import Colonel, Scarlet, Professor, Green, White, Peacock
from clue.game.location import Study, Hall, Lounge, Library, BilliardRoom, DiningRoom, Conservatory, Ballroom, Kitchen, HallwayStudyToHall, HallwayHallToLounge, HallwayStudyToLibrary, HallwayHallToBilliardRoom, HallwayLoungeToDiningRoom, HallwayLibraryToBilliardRoom, HallwayBilliardRoomToDiningRoom, HallwayLibraryToConservatory, HallwayBilliardRoomToBallroom, HallwayDiningRoomToKitchen, HallwayConservatoryToBallroom, HallwayBallroomToKitchen
from clue.game.card import Weapon, Suspect, Room
from clue.game.casefile import CaseFile
from clue.game.suggestion import Suggestion
from clue.game.error import GameError
from twisted.python import log
from random import randint, shuffle, choice

TURN_STATE_WAITING_TO_MOVE = "waiting_to_move"
TURN_STATE_WAITING_TO_SUGGEST = "waiting_to_suggest"
TURN_STATE_IS_SUGGESTING = "suggesting"
TURN_STATE_WAITING_TO_ACCUSE = "waiting_to_accuse"
TURN_STATE_IS_ACCUSING = "accusing"

class Game:

	def __init__(self):
		self.players = {}
		self.in_progress = False
		self.num_turns = 0
		self.active_turn = None
		self.active_turn_state = None
		self.case_file = None
		self.active_suggestion = None
		self.active_suggestion_turn = None
		self.winner = None
		self.game_over = False
		self.creator = None

		self.grid = [
			[Study(), HallwayStudyToHall(), Hall(), HallwayHallToLounge(), Lounge()],
			[HallwayStudyToLibrary(), None, HallwayHallToBilliardRoom(), None, HallwayLoungeToDiningRoom()],
			[Library(), HallwayLibraryToBilliardRoom(), BilliardRoom(), HallwayBilliardRoomToDiningRoom(), DiningRoom()],
			[HallwayLibraryToConservatory(), None, HallwayBilliardRoomToBallroom(), None, HallwayDiningRoomToKitchen()],
			[Conservatory(), HallwayConservatoryToBallroom(), Ballroom(), HallwayBallroomToKitchen(), Kitchen()]
		]

	def is_in_progress(self):
		return self.in_progress

	def num_players(self):
		return len(self.players)

	def add_player(self, player):
		if player.id in self.players:
			raise Exception("Player is already part of this game.")

		# What character should this player be?
		characters = [Colonel, Scarlet, Professor, Green, White, Peacock]
		for option in characters:
			unique = True
			for playerId in self.players:
				if self.players[playerId].character.color == option.color:
					unique = False
					break

			if unique:
				player.character = option(player)
				break

		if player.character is None:
			raise Exception("Player has no character.")

		self.players[player.id] = player
		self.broadcast_game_state()
		
		# Start the game if we have enough players.
		if self.num_players() >= 6: self.start()

	def remove_player(self, player):
		try:
			del self.players[player.id]
			self.broadcast_game_state()
		except KeyError: pass

	def start(self):
		if self.in_progress:
			raise Exception("Game has already started.")

		# Build the case file
		# Select one random suspect, one random weapon, and one random room
		deck = self.build_deck()

		suspects = [card for card in deck if card.card_type == "suspect"]
		rooms = [card for card in deck if card.card_type == "room"]
		weapons = [card for card in deck if card.card_type == "weapon"]
		
		self.case_file = CaseFile(choice(suspects), choice(weapons), choice(rooms))

		# Remove these cards from the deck
		deck.remove(self.case_file.suspect)
		deck.remove(self.case_file.weapon)
		deck.remove(self.case_file.location)

		# Shuffle and deal the remaining cards to each player
		shuffle(deck)
		while len(deck) > 0:
{'fraction_non_alphanumeric': 0.09407469811850604, 'fraction_numerical': 0.0009828699803426004, 'mean_word_length': 5.242769500438212, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7453332', 'n_tokens_mistral': 2558, 'n_tokens_neox': 2276, 'n_words': 587}