def __init__(self, player): self.races = {} self.races["Elders"] = Race("Elders", None, "E", colorama.Fore.LIGHTWHITE_EX) self.races["Humans"] = Race("Human", None, "H", colorama.Fore.WHITE) self.races["Rindhalu"] = Race("Rindhalu", None, "R", colorama.Fore.GREEN) self.races["Jeraptha"] = Race("Jeraptha", self.races["Rindhalu"], "J", colorama.Fore.BLUE) self.races["Ruhar"] = Race("Ruhar", self.races["Jeraptha"], "R", colorama.Fore.LIGHTCYAN_EX) self.races["Maxolhx"] = Race("Maxolhx", None, "M", colorama.Fore.LIGHTMAGENTA_EX) self.races["Thuranin"] = Race("Thuranin", self.races["Maxolhx"], "T", colorama.Fore.MAGENTA) self.races["Kristang"] = Race("Kristang", self.races["Thuranin"], "K", colorama.Fore.YELLOW) self.races["Bosphuraq"] = Race("Bosphuraq", self.races["Maxolhx"], "B", colorama.Fore.RED) self.races["Wurgalan"] = Race("Wurgalan", self.races["Bosphuraq"], "W", colorama.Fore.LIGHTYELLOW_EX) self.news = {} self.news["global"] = [] self._star_names = StarNamesStack() self.stars = [] for n in range(len(self._star_names.names)): star = Star(random.randrange(config.world_width), random.randrange(config.world_height), self._star_names.pop(), self.get_random_owner_race()) self.stars.append(star) self.news[star.name] = [] self._scatter_stars() self._scatter_stars() sol = Sol(self, player.world_x, player.world_y) self.stars.append(sol) player.star = sol for b in sol.bodies: if b.name == 'Planet Earth (Medium Terran)': player.system_x = b.body_x player.system_y = b.body_y player.body = b break self.fleets = [] self.spawn_fleets() self.spawn_investigator_fleet()
def get_race(self, key): with dbapi2.connect(self.app.config['dsn']) as connection: cursor = connection.cursor() query = "SELECT TITLE, RACE_TYPE, FOUNDERID, PARTICIPANT_COUNT, TIME, CYCROUTEID FROM RACE WHERE (ID = %s)" cursor.execute(query, (key,)) title, race_type, founder, participant_count, time, place = cursor.fetchone() return Race(title, race_type, founder, participant_count, time, place)
def __init__(self, name): super().__init__(name) self.name = name self.race = Race() self.scores = { 'Strength': 0, 'Dexterity': 0, 'Constitution': 0, 'Intelligence': 0, 'Wisdom': 0, 'Charisma': 0, } self.scores['Strength'] = self.getRoll() self.scores['Dexterity'] = self.getRoll() self.scores['Constitution'] = self.getRoll() self.scores['Intelligence'] = self.getRoll() self.scores['Wisdom'] = self.getRoll() self.scores['Charisma'] = self.getRoll() self.getClass() self.modifiers = { 'Strength': 0, 'Dexterity': 0, 'Constitution': 0, 'Intelligence': 0, 'Wisdom': 0, 'Charisma': 0, } self.getMods()
def __init__(self): with open("conf/filepaths.yaml") as filepath_config: self.conf = yaml.safe_load(filepath_config) self.sheet_stuff = utils.load_json(self.conf["CHARACTER_STATS_PATH"]) self.all_items = utils.load_json(self.conf["ITEM_PATH"]) self.clss = PlayerClass( self.sheet_stuff["saving_throws"], utils.load_json(self.conf["ITEM_PATH"]), *utils.select_random_from_json(self.conf["PLAYER_CLASS_PATH"]), ) self.stats = sheet_maths.generate_stats() self.race = Race( *utils.select_random_from_json(self.conf["RACES_PATH"])) self.finalise_stats() self.mods = sheet_maths.generate_mods(self.stats) self.saves = sheet_maths.generate_saves(self.mods, self.clss.saves, self.clss.proficiency_bonus) self.weapons = self.finalise_weapons() self.bg = Background( *utils.select_random_from_json(self.conf["BACKGROUND_PATH"])) self.final_languages = self.select_languages() self.final_profs = self.select_profs() self.final_skills = self.select_skills() self.ac = self.finalise_ac() if "Perception" in self.final_skills: self.pp = self.mods["WISmod"] + self.clss.proficiency_bonus + 10 else: self.pp = self.mods["WISmod"] + 10
def test_DoesNotAcceptSplitIfItIsEarlierThanStartTime(self): some_participant = 7 sut = Race(laps=5, bibs=[some_participant]) sut.start('12:00:00') earlier_than_start = "11:00:00" with self.assertRaises(SplitTimeIsEarlierThanStartTime): sut.split(some_participant, earlier_than_start)
def main(): """The main entry point for the turtle game""" race_meet = RaceMeet() print("Race name: {}".format(race_meet.name)) print("Race length: {} metres".format(race_meet.length)) print("Number of competitors: {}\n".format( race_meet.number_of_competitors)) competitors = generate_competitor_list(race_meet.number_of_competitors) race = Race() competitor_times = {} for i in range(0, len(competitors)): try: total_time_for_competitor = (race.get_total_time_for_turtle( competitors[i].speed, competitors[i].stamina, race_meet.length)) except TurtleHasNoEnergyError: print(("Competitor {}: {} didn't have the energy to complete the " "race...").format(i + 1, competitors[i].name)) continue competitor_times[competitors[i].name] = total_time_for_competitor print(("Competitor {}: " "{} ran the race in {} seconds").format( i + 1, competitors[i].name, total_time_for_competitor))
def load_track(self, dt, *args, **kwargs): if not self.images_loaded: self.track.load_images() self.label.text = self.text + '5%' self.total = len(self.track.partition_list) self.images_loaded = True elif not self.overlay_loaded: self.track.load_overlay() self.label.text = self.text + '25%' self.overlay_loaded = True else: partitions_left = self.track.load_partitions() percent = 25 + int( ((self.total - partitions_left) * 1.0 / self.total) * 75) self.label.text = self.text + str(percent) + '%' if partitions_left == 0: # load the music last self.track.load_music() # hack to prevent circular imports from race import Race race = Race(self.track, [ state.profile.car, ComputerCar.get_default(), ComputerCar.get_default() ]) director.replace(race)
def __init__(self, name): self.name = name self.class_name = self.chooseClass() self.race = Race() self.rolls = [] self.scores = { 'Strength': 0, 'Dexterity': 0, 'Constitution': 0, 'Intelligence': 0, 'Wisdom': 0, 'Charisma': 0, } self.rollStats() self.assignScores() self.modifiers = { 'Strength': 0, 'Dexterity': 0, 'Constitution': 0, 'Intelligence': 0, 'Wisdom': 0, 'Charisma': 0, } self.getMods() self.printStats()
def begin_new_race(self): self.cancelling_racers = [] self.before_races = False self.race = Race(self, RaceRoom.get_new_raceinfo()) yield from self.race.initialize() self.recorded_race = False for racer in self.match.racers: racer_as_member = self._cm.necrobot.find_member_with_id(racer.discord_id) if racer_as_member: yield from self.race.enter_racer(racer_as_member) else: yield from self.write('Error: Couldn\'t find the racer {0}. Please contact CoNDOR Staff (`.staff`).'.format(racer.escaped_twitch_name)) yield from self.update_leaderboard() race_number = int(self._cm.condordb.number_of_finished_races(self.match) + 1) race_str = '{}th'.format(race_number) if race_number == int(1): race_str = 'first' elif race_number == int(2): race_str = 'second' elif race_number == int(3): race_str = 'third' yield from self.write('Please input the seed ({1}) and type `.ready` when you are ready for the {0} race. '\ 'When both racers `.ready`, the race will begin.'.format(race_str, self.race.race_info.seed))
def main(): window = tk.Tk() window.title("flamme rouge") faster = parseArgs().faster track = colDuBallon() if faster else pickTrack(window) layout = RaceLayout(window, 2) players, riders = createRiders(layout.getUserFrame(), faster) onCardsDisplay = riders[0:2] clock = 0.3 if faster: clock /= faster roadDisplay = RoadDisplay(layout.getTrackFrame(), track) roadDisplay.displayRiders(riders) animation = Animation(roadDisplay, clock) race = Race(track, riders, players) window.update() while not race.isOver(): for rider, frame in zip(onCardsDisplay, layout.getDecksFrames()): displayRiderCards(frame, rider) logger = Logger() race.newTurn(logger) animation.animate(logger.getMoves(), logger.getGroups(), logger.getExhausted()) roadDisplay.displayRiders(race.riders) roadDisplay.ranking(race.ranking()) window.update() window.bind("<Escape>", lambda e: window.destroy()) window.mainloop()
def buildCharacterSheet(self, character): backgroundList = self.getBGs() #get player name print("Please enter the name of the player") playerName = input() #get character name print("Please enter the name of the character") characterName = input() #setting variables like this for now in case we want to put it in a try/except for #error handling later character.player_name = playerName character.char_name = characterName #race class will handle all race attributes race = Race() charClass = CharClass() startingEquipment = StartingEquipment() equipment = Equipment() charBackground = CharBackground(backgroundList) #race will be filled in depending on menu selection if self.quick == True: race.chooseRace(character, menuOption='quick') charClass.chooseClass(character, menuOption='quick') bg = charBackground.chooseBackground(character, menuOption='quick') character.background = bg else: race.chooseRace(character, menuOption='detailed') charClass.chooseClass(character, menuOption='detailed') bg = charBackground.chooseBackground(character, menuOption='detailed') character.background = bg startingEquipment.chooseStartingEquipment(character) equipment.getEquipmentStats(character) self.startingEquipString(character) StatRoller.rollForStats(character) StatCalculator.update(character) self.getPersonalInformation(character) charDict = CharacterDictBuilder.builder(character) outFile = characterName + '_char_sheet.pdf' write_fillable_pdf('.\\CharacterSheetTemplate.pdf', outFile, charDict) Sending.email(outFile) print("Good day to you Sir/Madam!")
def test_DoesNotAcceptSplitIfBibIsNotRegistered(self): some_participant = 7 sut = Race(laps=5, bibs=[some_participant]) sut.start('12:00:00') not_a_participant = 13 some_split_time = "12:15:00" with self.assertRaises(BibIsNotRegistered): sut.split(not_a_participant, some_split_time)
def test_DoesNotAcceptDnfIfBibIsNotRegistered(self): some_participant = 7 sut = Race(laps=3, bibs=[some_participant]) sut.start('12:00:00') not_a_participant = 13 with self.assertRaises(BibIsNotRegistered): sut.dnf(not_a_participant)
def get_races(self): with dbapi2.connect(self.app.config['dsn']) as connection: cursor = connection.cursor() query = "SELECT * FROM RACE ORDER BY ID" cursor.execute(query) races = [(key, Race(title, race_type, founder, participant_count, time, place)) for key, title, race_type, founder, participant_count, time, place in cursor] return races
def test_TheOneWhoRidesMoreLapsStandsHigher_1(self): participant1 = 7 participant2 = 9 sut = Race(laps=3, bibs=[participant1, participant2]) sut.start('12:00:00') sut.split(participant1, '12:15:15') standings = [result.bib for result in sut.results] self.assertSequenceEqual([participant1, participant2], standings)
def main(): red_speed = input("Please select speed for the red car: ") blue_speed = input("Please select speed for the blue car: ") c1 = Car('red', red_speed) c2 = Car('blue', blue_speed) race = Race([c1, c2]) print(f"And the winner is... {race.winner().color} car")
def search_race(self, key): with dbapi2.connect(self.app.config['dsn']) as connection: cursor = connection.cursor() query = "SELECT * FROM RACE WHERE (TITLE ILIKE %s OR RACE_TYPE ILIKE %s)" key = '%'+key+'%' cursor.execute(query, (key, key)) races = [(key, Race(title, race_type, founder, participant_count, time, place)) for key, title, race_type, founder, participant_count, time, place in cursor] return races
def test_ReturnsRidersPosition(self): participant1 = 7 participant2 = 9 sut = Race(laps=3, bibs=[participant1, participant2]) sut.start('12:00:00') sut.split(participant2, '12:14:00') sut.split(participant1, '12:15:00') standings = [(result.position, result.bib) for result in sut.results] self.assertSequenceEqual([(1, participant2), (2, participant1)], standings)
def test_OrderOfSplitsMatters(self): some_participant = 7 other_participant = 9 sut = Race(laps=3, bibs=[some_participant, other_participant]) sut.start('12:00:00') shuffled_splits = ['12:15:20', '12:10:10'] sut.split(some_participant, shuffled_splits[0]) with self.assertRaises(SplitsAreOutOfOrder): sut.split(other_participant, shuffled_splits[1])
def __init__(self, r, headings, filename): super().__init__(r, len(headings)) self.onFocusGainedText = "" self.headings = headings self.setColumnWidth(0, 70) self.setColumnWidth(1, 200) self.setColumnWidth(2, 200) self.setColumnWidth(3, 200) self.setColumnWidth(4, 70) self.setColumnWidth(5, 70) self.setColumnWidth(6, 70) self.setHorizontalHeaderLabels(headings) self.check_change = True self.cellChanged.connect(self.c_current) QEsFile = r"2020_Feb_QE.txt" handicapsFile = r"2020.csv" self.filename = filename handicaps = [] self.PYdict = {} self.dinghyLst = [] self.cols = dict() for h in headings: self.cols[h] = [] for line in open(handicapsFile, "r").readlines(): tokens = line.split(",") if tokens[0] != "" and len(tokens) > 3: self.dinghyLst.append(tokens[0]) handicaps.append(tokens[0] + "," + tokens[1] + "," + tokens[2]) self.PYdict[tokens[0]] = int(tokens[1]) QEs = [] for line in open(QEsFile, "r").readlines(): QEs.append(QE(line, self.PYdict)) self.race = Race([], QEs) self.race.handicaps = handicaps self.completerLsts = {"QE": [], "Class": [], "Code": []} for qe in QEs: self.completerLsts["QE"].append(qe.QE) for c in self.PYdict.keys(): self.completerLsts["Class"].append(c) self.completerLsts["Code"] = ["DNF", "OCS", "DNC"] self.completers = dict() for k in self.completerLsts.keys(): self.completers[k] = QCompleter(self.completerLsts[k]) self.completers[k].setCaseSensitivity(QtCore.Qt.CaseInsensitive) people = set() for Q in QEs: people.add(Q.helm) people.add(Q.crew) self.peopleLst = list(people) self.show()
def test(): date1 = date(1999, 5, 5) date2 = date(2000, 5, 5) date3 = date(2002, 5, 1) date4 = date(2022, 5, 1) date5 = date(2022, 5, 2) dog1 = Dog("firulais", date1, "galgo") dog2 = Dog("cholo", date2, "pitbull") dogs = [dog1, dog2] owner1 = Owner("Diego", "123456789-1", [dog1, dog2]) dog3 = Dog("cleo", date3, "golden retriever") owner1.add_dog(dog3) dogs = owner1.dogs race1 = Race(date4, dogs) race2 = Race(date5, dogs) races = [race1, race2] event1 = Event(date4, date5, "Santiago", races) race1.run_race() positions_table = race1.make_positions_table() print(positions_table)
def setUp(self): self.driver1 = Driver('Ivo', Car('Opel', 'Astra', 240)) self.driver2 = Driver('Rado', Car('Peugeot', '107', 180)) self.driver3 = Driver('Slavqna', Car('Opel', 'Meriva', 300)) self.driver4 = Driver('Pavlin', Car('AUDI', 'R8', 380)) self.driver5 = Driver('Roni', Car('Golf', '5', 200)) self.driver6 = Driver('Ceco', Car('AUDI', 'Q5', 310)) self.race = Race([ self.driver1, self.driver2, self.driver3, self.driver4, self.driver5, self.driver6 ], 0.2)
def test_DoesNotAcceptMalformedTimeStrings(self): some_participant = 7 sut = Race(laps=5, bibs=[some_participant]) sut.start('12:00:00') malformed_time_strings = [ '25:00:00', '12:61:00', '12:00:61', '-01:00:00', '12:00', 'ab:bc:de', '12:00:00,', '12 :00: 00' ] for malformed_time_string in malformed_time_strings: with self.assertRaises(MalformedTimeString): sut.split(some_participant, malformed_time_string)
def test_DoesNotAcceptDnfIfBibHasAlreadyFinished(self): some_participant = 7 sut = Race(laps=3, bibs=[some_participant]) sut.start('12:00:00') sut.split(some_participant, '12:10:10') sut.split(some_participant, '12:15:20') sut.split(some_participant, '12:20:00') with self.assertRaises(BibHasAlreadyFinished): sut.dnf(some_participant)
def test_TheOneWhoDNFsStandsLower(self): participant1 = 7 participant2 = 9 sut = Race(laps=3, bibs=[participant1, participant2]) sut.start('12:00:00') sut.split(participant2, '12:10:00') sut.split(participant1, '12:12:00') sut.split(participant2, '12:15:00') sut.dnf(participant2) standings = [result.bib for result in sut.results] self.assertSequenceEqual([participant1, participant2], standings)
async def open(self, ctx, start_time_str): """ usage: !kiite open TIMESTRING TIMESTRING: A string indicates a start time of the race. The string must be following the format "hh:mm" or "yyyy/mm/dd hh:mm". """ start_time = self.__parse_timestamp(start_time_str) race = Race(ctx.message.id, ctx.channel.id, start_time) self.races[race.hash()] = race await ctx.channel.send(race.template())
def __init__(self, name_in): self.name = name_in self.stats = { "str": 0, "dex": 0, "con": 0, "wis": 0, "int": 0, "cha": 0 } self.species = Race() print("Creating character: ", self.name)
def test_LappedRiderRidesLess(self): leader = 7 lapped = 9 sut = Race(laps=3, bibs=[leader, lapped]) sut.start('12:00:00') sut.split(leader, '12:05:00') sut.split(leader, '12:10:00') sut.split(lapped, '12:10:00') sut.split(leader, '12:15:00') sut.split(lapped, '12:20:00') lapped_state = sut.results[1].state self.assertEqual(ParticipantState.FINISHED, lapped_state)
def test_DoesNotAcceptSplitIfBibHasAlreadyFinished(self): some_participant = 7 sut = Race(laps=3, bibs=[some_participant]) sut.start('12:00:00') sut.split(some_participant, '12:10:10') sut.split(some_participant, '12:15:20') sut.split(some_participant, '12:20:00') with self.assertRaises(BibHasAlreadyFinished): excessive_split = '12:25:00' sut.split(some_participant, excessive_split)
def test_ReturnsNumberOfRidersOnTheCourse(self): sut = Race(laps=1, bibs=[1, 2, 3]) self.assertEqual(0, sut.riders_on_course) sut.start('12:00:00') self.assertEqual(3, sut.riders_on_course) sut.split(1, '12:01:00') sut.split(2, '12:01:03') self.assertEqual(1, sut.riders_on_course) sut.dnf(3) self.assertEqual(0, sut.riders_on_course)