def __init__(self, view): self.view = view self.live = Live() self.music = None self.card_ids = None self.cards = list() eventbus.eventbus.register(self)
def test_music_not_found(self): live = Live() self.assertRaises( NoLiveFoundException, lambda: live.set_music(music_name="印象", difficulty=Difficulty.TRICK)) self.assertRaises( NoLiveFoundException, lambda: live.set_music(music_name="not found", difficulty=Difficulty.REGULAR))
def set_cards(self, event): cards = event.cards self.cards = cards try: custom_pots = eventbus.eventbus.post_and_get_first(GetCustomPotsEvent()) if len(cards) == 15: unit = GrandUnit.from_list(self.cards, custom_pots) self.live = GrandLive() self.live.set_unit(unit) else: unit = Unit.from_list(self.cards, custom_pots) self.live = Live() self.live.set_unit(unit) except InvalidUnit: return False return True
def highlight_event_cards(self, checked): highlight_set = Live.static_get_chara_bonus_set(get_name=True) for r_idx in range(self.view.widget.rowCount()): if self.view.widget.item(r_idx, 5).text() not in highlight_set: continue for c_idx in range(4, 5): item = self.view.widget.item(r_idx, c_idx) if checked: item.setBackground(QColor(50, 100, 100, 80)) else: item.setBackground(QColor(0, 0, 0, 0))
def test_mplus(self): c1 = Card.from_query("sae4", custom_pots=(10, 10, 10, 10, 10)) c2 = Card.from_query("chieri2", custom_pots=(10, 10, 10, 10, 10)) c3 = Card.from_query("chieri2u", custom_pots=(10, 10, 10, 10, 10)) c4 = Card.from_query("rika4", custom_pots=(10, 10, 10, 10, 10)) c5 = Card.from_query("yoko1", custom_pots=(10, 10, 10, 10, 10)) cg = Card.from_query("kaede2", custom_pots=(10, 10, 10, 10, 10)) unit = Unit.from_list([c1, c2, c3, c4, c5, cg]) live = Live() live.set_music(music_name="EVERMORE", difficulty=Difficulty.MPLUS) live.set_unit(unit) self.assertEqual(live.get_appeals(), 134140) self.assertEqual(live.get_life(), 394)
def test_master(self): c1 = Card.from_query("karen4", custom_pots=(0, 6, 10, 0, 10)) c2 = Card.from_query("sachiko2", custom_pots=(0, 0, 8, 0, 0)) c3 = Card.from_query("koume2", custom_pots=(0, 0, 10, 0, 10)) c4 = Card.from_query("miho4", custom_pots=(0, 4, 10, 0, 10)) c5 = Card.from_query("fumika1", custom_pots=(0, 6, 10, 0, 0)) cg = Card.from_query("sae4", custom_pots=(0, 10, 0, 5, 10)) unit = Unit.from_list([c1, c2, c3, c4, c5, cg]) live = Live() live.set_music(music_name="印象", difficulty=Difficulty.MASTER) live.set_unit(unit) self.assertEqual(live.get_appeals(), 38965) self.assertEqual(live.get_life(), 272)
def test_bless1(self): c0 = Card.from_query("kaede5", custom_pots=(10, 10, 5, 0, 10)) c1 = Card.from_query("natalia1", custom_pots=(10, 0, 0, 0, 10)) c2 = Card.from_query("yoshino3", custom_pots=(0, 10, 10, 0, 10)) c3 = Card.from_query("sarina1", custom_pots=(0, 0, 0, 0, 0)) c4 = Card.from_query("shiki3", custom_pots=(10, 0, 10, 0, 10)) guest = Card.from_query("kaede2", custom_pots=(10, 10, 10, 0, 0)) unit = Unit.from_list([c0, c1, c2, c3, c4, guest]) live = Live() live.set_music(music_name="印象", difficulty=Difficulty.MPLUS) live.set_unit(unit) sim = Simulator(live) sim._setup_simulator(support=110319) self.assertEqual(sim.total_appeal, 279476)
def test_bless3(self): # For some reason, with reso, the other bonuses can only be 0 or -100 c0 = Card.from_query("kaede5", custom_pots=(10, 10, 5, 0, 10)) c1 = Card.from_query("karen4", custom_pots=(0, 6, 10, 0, 10)) c2 = Card.from_query("syuko4", custom_pots=(0, 0, 8, 0, 10)) c3 = Card.from_query("asuka4", custom_pots=(10, 10, 0, 0, 10)) c4 = Card.from_query("shiki3", custom_pots=(10, 0, 10, 0, 10)) guest = Card.from_query("yui2", custom_pots=(10, 10, 10, 0, 0)) unit = Unit.from_list([c0, c1, c2, c3, c4, guest]) live = Live() live.set_music(music_name="印象", difficulty=Difficulty.MPLUS) live.set_unit(unit) sim = Simulator(live) sim._setup_simulator(support=110319) self.assertEqual(sim.total_appeal, 189565)
class SupportModel: def __init__(self, view): self.view = view self.live = Live() self.music = None self.card_ids = None self.cards = list() eventbus.eventbus.register(self) @subscribe(SetSupportCardsEvent) def set_cards(self, event): cards = event.cards self.cards = cards try: custom_pots = eventbus.eventbus.post_and_get_first(GetCustomPotsEvent()) if len(cards) == 15: unit = GrandUnit.from_list(self.cards, custom_pots) self.live = GrandLive() self.live.set_unit(unit) else: unit = Unit.from_list(self.cards, custom_pots) self.live = Live() self.live.set_unit(unit) except InvalidUnit: return False return True @subscribe(SupportTeamSetMusicEvent) def set_music(self, event): score_id = event.score_id difficulty = event.difficulty self.live.set_music(score_id=score_id, difficulty=difficulty, skip_load_notes=True) self.music = (score_id, difficulty) @subscribe(RequestSupportTeamEvent) def generate_support(self, event): if self.live.unit is None: return if self.music is not None: self.live.set_music(score_id=self.music[0], difficulty=self.music[1]) groove_song_color = eventbus.eventbus.post_and_get_first(GetGrooveSongColor()) if groove_song_color is not None: self.live.color = groove_song_color self.live.set_extra_bonus(*eventbus.eventbus.post_and_get_first(GetCustomBonusEvent())) self.live.get_support() self.view.display_support(self.live.support.copy()) return self.live.get_appeals(), self.live.get_support(), self.live.get_life()
self.p.drawConvexPolygon(polygon) def draw_notes(self): for group_idx, group in enumerate(self.note_groups): for note in group: x = self.get_x(note.lane + note.span / 2, group_idx) - note.note_pic.width() // 2 y = self.get_y(note.sec, group_idx) - note.note_pic.height() // 2 self.p.drawImage(QPoint(x, y), note.note_pic) if __name__ == '__main__': app = QApplication(sys.argv) app.setApplicationName("Bruh") main_window = QMainWindow() main_window.show() unit = Unit.from_list([100936, 100708, 100914, 100584, 100456, 100964]) live = Live() live.set_music(score_id=637, difficulty=5) live.set_unit(unit) sim = Simulator(live) res: MaxSimulationResult = sim.simulate_theoretical_max() cpg = BaseChartPicGenerator.get_generator(637, Difficulty(5), main_window, mirrored=True) cpg.hook_cards(unit.all_cards()) cpg.hook_abuse(unit.all_cards(), res.abuse_df) app.exec_()
def test_bonus_chara(self): sae4 = Card.from_query("sae4", custom_pots=(0, 10, 10, 0, 10)) chieri4 = Card.from_query("chieri4", custom_pots=(0, 10, 10, 0, 10)) yoshino3 = Card.from_query("yoshino3", custom_pots=(0, 10, 10, 0, 10)) rika4 = Card.from_query("rika4", custom_pots=(0, 10, 10, 0, 10)) mio4 = Card.from_query("mio4", custom_pots=(0, 10, 10, 0, 10)) kaede2_guest = Card.from_query("kaede2", custom_pots=(10, 10, 10, 0, 0)) unit = Unit.from_list( [sae4, chieri4, yoshino3, rika4, mio4, kaede2_guest]) live = Live() live.set_music(music_name="印象", difficulty=Difficulty.MPLUS) live.set_unit(unit) sim = Simulator(live) sim.simulate() self.assertEqual(live.get_appeals(), 155135) live.reset_attributes() live.set_chara_bonus({262}, 500) live.special_option = APPEAL_PRESETS["Event Idols"] self.assertEqual(live.get_appeals(), 238635) live.reset_attributes() live.set_chara_bonus({262}, 5000) live.special_option = APPEAL_PRESETS["Event Idols"] self.assertEqual(live.get_appeals(), 973137)
def __init__(self, music_name=None, difficulty=None, unit=None): self.unit_lives = list() for i in range(3): dummy_live = Live() self.unit_lives.append(dummy_live) super().__init__(music_name, difficulty, unit)
from logic.live import Live from logic.unit import Unit from simulator import Simulator from static.song_difficulty import Difficulty logger.print_debug() sae4 = Card.from_query("sae4", custom_pots=(2, 10, 0, 0, 10)) chieri4 = Card.from_query("chieri4", custom_pots=(0, 10, 9, 0, 10)) yoshino3 = Card.from_query("yoshino3", custom_pots=(8, 10, 0, 0, 10)) rika4 = Card.from_query("rika4", custom_pots=(8, 10, 0, 0, 10)) mio4 = Card.from_query("mio4", custom_pots=(0, 5, 0, 0, 10)) kaede2_guest = Card.from_query("kaede2", custom_pots=(10, 10, 10, 0, 5)) unit = Unit.from_list([sae4, chieri4, yoshino3, rika4, mio4, kaede2_guest]) live = Live() live.set_music(music_name="印象", difficulty=Difficulty.MPLUS) live.set_unit(unit) sim = Simulator(live) assert sim.simulate(times=100, appeals=270000).perfect_score == 1736810 unitA = Unit.from_query("kaede2 chieri4 kyoko4 rika4 rika4u") unitB = Unit.from_query("sae4 kozue2 momoka3 frederica3 sachiko4") unitC = Unit.from_query("atsumi2 anzu3 anzu3u miku4 miku3") gu = GrandUnit(unitA, unitB, unitC) live = GrandLive() live.set_music(music_name="Starry-Go-Round", difficulty=Difficulty.PIANO) live.set_unit(gu) sim = Simulator(live) assert sim.simulate(times=10, appeals=490781).perfect_score == 3424303
def initialize_index_db(self, card_list=None): logger.info("Building quicksearch index, please wait...") carnival_idols = ",".join( map(str, Live.static_get_chara_bonus_set(get_name=False))) db.cachedb.execute("""ATTACH DATABASE "{}" AS masterdb""".format( get_masterdb_path())) query = """ SELECT cdc.id, LOWER(cnc.card_short_name) as short, oc.number as owned, LOWER(cc.full_name) as chara, LOWER(rt.text) as rarity, LOWER(ct.text) as color, CASE WHEN cdc.rarity % 2 == 0 THEN 1 ELSE 0 END idolized, CASE WHEN pk.id IS NOT NULL THEN sd.condition || pk.short ELSE '' END time_prob_key, IFNULL(LOWER(sk.keywords), "") as skill, IFNULL(LOWER(lk.keywords), "") as leader, CASE WHEN cdc.leader_skill_id IN (70,71,72,73,81,82,83,84,104,105,106,113,117,118) AND cdc.rarity > 6 THEN "fes" ELSE "" END fes, CASE WHEN cdc.leader_skill_id IN (70,71,72,73,81,82,83,84,104,105,106,113,117) AND cdc.rarity > 6 THEN "blanc" ELSE "" END blanc, CASE WHEN cdc.leader_skill_id IN (118) AND cdc.rarity > 6 THEN "noir" ELSE "" END noir, CASE WHEN cdc.chara_id IN ({}) THEN "carnival" ELSE "" END carnival, CASE WHEN 1.0 * cdc.vocal_min / (cdc.vocal_min + cdc.visual_min + cdc.dance_min) > 0.39 THEN "vocal" WHEN 1.0 * cdc.visual_min / (cdc.vocal_min + cdc.visual_min + cdc.dance_min) > 0.39 THEN "visual" WHEN 1.0 * cdc.dance_min / (cdc.vocal_min + cdc.visual_min + cdc.dance_min) > 0.39 THEN "dance" ELSE "balance" END main_attribute FROM card_data_cache as cdc INNER JOIN card_name_cache cnc on cdc.id = cnc.card_id INNER JOIN owned_card oc on oc.card_id = cnc.card_id INNER JOIN chara_cache cc on cdc.chara_id = cc.chara_id INNER JOIN rarity_text rt on cdc.rarity = rt.id INNER JOIN color_text ct on cdc.attribute = ct.id LEFT JOIN masterdb.skill_data sd on cdc.skill_id = sd.id LEFT JOIN probability_keywords pk on pk.id = sd.probability_type LEFT JOIN skill_keywords sk on sd.skill_type = sk.id LEFT JOIN leader_keywords lk on cdc.leader_skill_id = lk.id """.format(carnival_idols) if card_list is not None: query += "WHERE cdc.id IN ({})".format(','.join(['?'] * len(card_list))) data = db.cachedb.execute_and_fetchall(query, card_list, out_dict=True) else: data = db.cachedb.execute_and_fetchall(query, out_dict=True) db.cachedb.execute("DROP TABLE IF EXISTS card_index_keywords") db.cachedb.execute(""" CREATE TABLE IF NOT EXISTS card_index_keywords ( "card_id" INTEGER UNIQUE PRIMARY KEY, "fields" BLOB ) """) logger.debug("Initializing quicksearch db for {} cards".format( len(data))) for card in data: card_id = card['id'] fields = {_: card[_] for _ in KEYWORD_KEYS} db.cachedb.execute( """ INSERT OR REPLACE INTO card_index_keywords ("card_id", "fields") VALUES (?,?) """, [card_id, str(fields)]) db.cachedb.commit() logger.debug( "Quicksearch db transaction for {} cards completed".format( len(data))) db.cachedb.execute("DETACH DATABASE masterdb")
def simulate_internal(self, perfect_play, left_inclusive, right_inclusive, theoretical_simulation, score_id, diff_id, times, all_cards, custom_pots, appeals, support, extra_bonus, special_option, special_value, mirror, autoplay, autoplay_offset, doublelife, row=None): """ :type all_cards: List[CardsWithUnitUuid] """ results = list() if len(all_cards) == 0: logger.info("Nothing to simulate") return extra_return = None # Initialize song first because SQLite DB thread lock # Live objects are mutable so create one for each simulation # TODO: Minor optimize by calling set_music only once then clone, but set_music shouldn't take too long to run so this is on low priority live_objects = list() for card_with_uuid in all_cards: cards = card_with_uuid.cards if len(cards) == 15: live = GrandLive() else: live = Live() live.set_music(score_id=score_id, difficulty=diff_id) groove_song_color = eventbus.eventbus.post_and_get_first( GetGrooveSongColor()) if groove_song_color is not None: live.color = groove_song_color live_objects.append(live) # Load cards for live, card_with_uuid in zip(live_objects, all_cards): cards = card_with_uuid.cards try: if len(cards) == 15: unit = GrandUnit.from_list(cards, custom_pots) else: if cards[5] is None: cards = cards[:5] unit = Unit.from_list(cards, custom_pots) except InvalidUnit: logger.info("Invalid unit: {}".format(cards)) results.append(None) continue eventbus.eventbus.post(SimulationEvent( card_with_uuid.uuid, card_with_uuid.short_uuid, row is not None and theoretical_simulation, appeals, autoplay, autoplay_offset, doublelife, extra_bonus, extra_return, live, mirror, perfect_play, results, special_option, special_value, support, times, unit, left_inclusive, right_inclusive, theoretical_simulation), high_priority=True, asynchronous=True)