def __init__(self,screen,config): State.__init__(self,screen) self.config = config self.object = None self.rect = pygame.Rect(100,0,700,600) width,height = map(int,self.config['screen_size'].split('x')) tile_size = int(config['tile_size']) self.screen.fill((255,255,255),self.rect) self.grid = Grid(width,height,tile_size,(700,600),screen)
def __init__(self,screen,config,objects): State.__init__(self,screen) self.config = config self.objects = objects self.object_positions = [] self.selected = None self.rect = pygame.Rect(0,0,100,600) self.title_font = pygame.font.SysFont('Arial', 15) self.save_location = [] self.draw_items()
def __init__(self, key, manager): State.__init__(self,key,manager) self.psurf = pygame.surface.Surface((1024,768)) self.psurf.fill((0,0,0)) self.psurf.set_alpha(200) self.paused = False self.prepared = False self.bullet_group = pygame.sprite.Group() self.creeps = pygame.sprite.LayeredUpdates() self.cursor = self.manager.cursor self.towers = pygame.sprite.OrderedUpdates() self.bgt = pygame.sprite.OrderedUpdates() self.needed_tiles = pygame.sprite.Group() self.needed_tiles1 = pygame.sprite.Group() self.banned_tiles = pygame.sprite.OrderedUpdates() self.banned_tiles1 = pygame.sprite.OrderedUpdates() self.player = self.manager.player self.weatherbg = pygame.surface.Surface((1024,640)) self.weatherbg.fill((0,0,0)) self.weatherbg.set_alpha(0) self.magic = pygame.sprite.Group() self.d = pygame.sprite.Group() self.buoyant = pygame.sprite.Group() self.default_text = '' self.before_mag = self.before_g = 0 self.tpassed = 0 self.tbot = None self.previous = 0 self.ingame_menu = Master([0,596],1024,172,self.screen,self.cursor, \ "./data/font/carolingia.ttf") self.ingame_menu_bg = load_image("./data/image/menu/ingame_menu.png") self.ship_menu = SHIMENU.get_at((0,0,157,61), True) self.ship_hp = SHIMENU.get_at((159,6,47,43), True) self.bonus_menu = load_image("./data/image/menu/bns_menu.png") self.particle_emitter = pygame.sprite.Group() self.spells = pygame.sprite.Group() self.wave = 0 self.total = 0 self.bars = pygame.surface.Surface((1024,768)) self.bars.fill((0,0,0)) self.bars.set_colorkey((0,0,0)) self.wave_t = 0 self.countdown = False self.moded = False self.totalc = 0 self.unlock = ['Nothing',''] self.map = None self.lname = None self.cid = None
def __init__(self, key, manager): State.__init__(self,key,manager) self.cursor = self.manager.cursor self.player = self.manager.player self.menu = Master([0,0],1024,768,self.screen,self.cursor,"./data/font/carolingia.ttf") self.menu_background = load_image("./data/image/menu/map.PNG") self.levels = [[Level("lv01.mkm"), [195, 542]],[Level("lv02.mkm"), [215,469]], \ [Level("lv03.mkm"), [177,402]], [Level("lv04.mkm"), [165, 331]], \ [Level("lv05.mkm"), [209, 281]], [Level("lv06.mkm"), [268, 210]], \ [Level("lv07.mkm"),[255,125]], [Level("lv08.mkm"),[372,199]], \ [Level("lv09.mkm"),[481,234]], [Level("lv10.mkm"),[547,266]], \ [Level("lv11.mkm"),[687,261]], [Level("lv12.mkm"),[720,149]], \ [Level("lv13.mkm"),[875,125]], [Level("lv14.mkm"),[871,201]], \ [Level("lv15.mkm"),[840,252]], [Level("lv16.mkm"),[818,291]], \ [Level("lv17.mkm"),[761,382]], [Level("lv18.mkm"),[631,429]], \ [Level("lv19.mkm"),[616,477]], [Level("lv20.mkm"),[579,519]], \ [Level("indian1.mkm"),[149,154]], [Level("indian2.mkm"),[152,106]], \ [Level("warrior1.mkm"),[356,235]]] self.prepared = False
def __init__(self,key,manager): State.__init__(self,key,manager) self.cursor = self.manager.cursor self.menu = Master([0,0],1024,768,self.screen,self.cursor,"./data/font/carolingia.ttf") self.menu_background = load_image("./data/image/menu/menu.PNG") self.temp = Label(self.menu,[273,638],(0,0,0),None,19,"v. 0.9") self.boxes = [] icons = Sheet("./data/image/menu/status_icons.png") try: version = float(urllib.urlopen("http://mkm.limun.org/vs/version.txt").read()) if version==0.9: self.boxes.append(MessageBox([300,300],[400,100],self.screen,self.cursor,"You have the most recent version installed.",[self.menu])) temp_image = icons.get_at((0,0,19,19),False) elif version<0.9: self.boxes.append(MessageBox([300,300],[400,100],self.screen,self.cursor,"Damn, you must be Chuck Norris! How did you...?",[self.menu])) temp_image = icons.get_at((0,0,19,19),False) else: self.boxes.append(MessageBox([300,300],[400,100],self.screen,self.cursor,"A new version is available on the official site!",[self.menu])) temp_image = icons.get_at((38,0,19,19),False) except: self.boxes.append(MessageBox([300,300],[400,100],self.screen,self.cursor,"Can't connect! Please check connection and restart.",[self.menu])) temp_image = icons.get_at((19,0,19,19),False) def x(something): print something,"x!" self.temp = ImageButton(self.menu,[318,638],temp_image,self.boxes[0].wake) self.temp = Button(self.menu,[395,155],(0,0,0),None,62,"New Game",self.manager.set_state,"game") self.temp = Button(self.menu,[395,222],(0,0,0),None,62,"Continue",x,"aa") self.temp = Button(self.menu,[395,294],(0,0,0),None,62,"Profile",x,"aa") self.temp = Button(self.menu,[395,366],(0,0,0),None,62,"Options",self.menu.switch,"options") self.temp = Button(self.menu,[395,438],(0,0,0),None,62,"Credits",self.menu.switch,"credits") self.temp = Button(self.menu,[395,510],(0,0,0),None,62,"Quit",exit,None) self.temp = Button(self.menu,[273,630],(0,0,0),None,20,"Back",self.menu.switch,"default",["credits"]) self.temp = Button(self.menu,[273,630],(0,0,0),None,20,"Back",self.menu.switch,"default",["options"]) self.temp = Button(self.menu,[323,630],(0,0,0),None,20,"Apply",x,"aa",["options"]) self.temp = Textbox(self.menu, [300,155],(0,0,0),None,28,"Created by: Marko Pranjic\nPowered by: PyGame\nBackground music: Celestial Aeon Project\nSound effects: freesounds.org\nSpecial thanks to my friends\nand forumers who supported me!",3,["credits"]) self.temp = Checkbox(self.menu,[395,154],(0,0,0),None,19,"Fullscreen",(0,1),["options"]) self.temp = Label(self.menu,[395,179],(0,0,0),None,19,"Background sound:",["options"]) self.temp = Scroll(self.menu, [560,179],(0,0,0),None,19,["options"])
def init_extra_points_state_graph(verbosity=0): # Construct tap inflow = Quantity("inflow", derivative="+") tap = Tap(inflow=inflow) # Construct container volume = Quantity("volume") height = Quantity("height") pressure = Quantity("pressure") container = Container(volume=volume, height=height, pressure=pressure) # Construct drain outflow = Quantity("outflow") drain = Drain(outflow=outflow) # Set up rules inter_state = [ PositiveInfluence(source="tap.inflow", target="container.volume"), NegativeInfluence(source="drain.outflow", target="container.volume"), PositiveProportion(source="container.volume", target="container.height"), PositiveProportion(source="container.height", target="container.pressure"), PositiveProportion(source="container.pressure", target="drain.outflow"), ] intra_state = [ PositiveConsequence(target="tap.inflow"), NegativeConsequence(target="tap.inflow"), PositiveConsequence(target="container.volume"), NegativeConsequence(target="container.volume"), PositiveConsequence(target="container.height"), NegativeConsequence(target="container.height"), PositiveConsequence(target="container.pressure"), NegativeConsequence(target="container.pressure"), PositiveConsequence(target="drain.outflow"), NegativeConsequence(target="drain.outflow"), VCmax(source="container.volume", target="container.height"), VCzero(source="container.volume", target="container.height"), VCmax(source="container.height", target="container.pressure"), VCzero(source="container.height", target="container.pressure"), VCmax(source="container.pressure", target="drain.outflow"), VCzero(source="container.pressure", target="drain.outflow") ] # Create initial state init_state = State(tap=tap, container=container, drain=drain) # Create state graph state_graph = StateGraph(initial_state=init_state, inter_state=inter_state, intra_state=intra_state, verbosity=verbosity) return state_graph
def setUp(self): super(StorageTest, self).setUp() self.useFixture(State(self.fakes)) self.fakes.fs.add(os.path.dirname(paths.HOME)) self.fakes.processes.add(fake_mv, name='mv') os.makedirs(paths.HOME) os.chown(paths.HOME, 123, 123) with open(os.path.join(paths.HOME, "jenkins_config"), 'w') as f: f.write("fake config") self.storage_dir = paths.HOME + '-storage' os.makedirs(self.storage_dir)
def get_end_state(self): # Calculates the end state or current state the node is in after applying the players actions end_state_content = list() begin_state_content = self.begin_state.state_content for i, state in enumerate(begin_state_content): end_state_content.append(self.actions[i] if not self.actions[i] == None else begin_state_content[i]) end_state = State(tuple(end_state_content)) return end_state
def apply(self, state): self.T += 1 st = State.parse(state) actions = [] my_ships = [] enemy_ships = [] for some_ship in st.ships: if some_ship.id not in self.birthday: self.birthday[some_ship.id] = self.T if some_ship.player == st.me: my_ships.append(some_ship) else: enemy_ships.append(some_ship) if self.printships: print( f'T:{self.T} Player {st.me}: {" ".join(str([s.fuel, s.laser, s.regen, s.lives]) for s in my_ships)}' ) for my_ship in my_ships: my_ship = my_ship birthday = self.birthday[my_ship.id] age = self.T - birthday if self.duplicate and my_ship.lives > 1 and self.T > 10: actions.append(my_ship.do_duplicate()) my_pos = [my_ship.x, my_ship.y] my_vel = [my_ship.vx, my_ship.vy] cur_closest = trace_orbit(my_pos[0], my_pos[1], my_vel[0], my_vel[1]) thrust = (0, 0) if cur_closest <= 17: thrust = (-sign(my_pos[0]), -sign(my_pos[0])) if abs( my_pos[0]) > abs(my_pos[1]) else (sign(my_pos[1]), -sign(my_pos[1])) # find closest friend - if too close randomize movement (include velocity in distance computation) closest_ship, dist = None, 1000 for other in my_ships: if other.id == my_ship.id: continue od = abs(other.x - my_ship.x) + abs(other.y - my_ship.y) + abs( other.vx - my_ship.vx) + abs(other.vy - my_ship.vy) if od < dist: dist = od closest_ship = other if closest_ship and dist < 4: thrust = (random.randint(-1, 1), random.randint(-1, 1)) actions.append([0, my_ship.id, thrust]) if enemy_ships: enemy_ship = random.choice(enemy_ships) if my_ship.laser and self.do_laser: ex, ey = enemy_ship.next_round_expected_location() actions.append(my_ship.do_laser(ex, ey)) return actions
def __init__(self,key,manager): State.__init__(self,key,manager) self.bullet_group = pygame.sprite.Group() self.creeps = pygame.sprite.OrderedUpdates() self.cursor = self.manager.cursor self.tiles_dict, self.path_tiles = tiles_dictionary() self.towers = pygame.sprite.OrderedUpdates() self.needed_tiles = pygame.sprite.Group() self.banned_tiles = pygame.sprite.OrderedUpdates() self.banned_tiles2 = pygame.sprite.OrderedUpdates() self.ingame_menu = Master([0,19*32],1024,160,self.screen,self.cursor,"./data/font/viking.ttf") self.ingame_menu_bg = load_image("./data/image/menu/ingame_menu.png") self.levels = {} temp = Level("lv01.mkm") self.levels[temp["name"]]=temp self.player = self.manager.player self.gold_label = Label(self.ingame_menu,[285,10],(255,255,255),None,15,str(self.player["gold"])) self.magicka_label = Label(self.ingame_menu,[372,10],(255,255,255),None,15,str(self.player["magicka"])) self.particle_emitter = pygame.sprite.Group() self.spells = pygame.sprite.Group() def spawn(): if not self.player.buying: self.player.buying = True temp = (ArrowTower(len(self.towers),[0,0],80,self.screen, \ self.bullet_group,self.creeps,[self.needed_tiles, \ self.towers],[self.banned_tiles,self.banned_tiles2], \ self.player, self.particle_emitter)) self.towers.add(temp) def spawn2(): if not self.player.buying: self.player.buying = True temp = FireArrows([0, 0], self.player, self.particle_emitter, \ self.screen, self.towers) self.spells.add(temp) buttons = Sheet("./data/image/menu/buttons.png") ImageButton(self.ingame_menu,[33,47],buttons.get_at((33,0,32,32),False),spawn) ImageButton(self.ingame_menu,[806,47],buttons.get_at((66,0,32,32),True),spawn2)
def start_game(self): """ Initialise game matrix and add 2 tiles of value 2 in the game grid. """ self.matrix = [[0] * 4 for _ in range(4)] self.changeflag = False self.ai = AI() self.score = 0 self.tilesum = 0 self.agentgameover = False self.add_new_tile() self.add_new_tile() self.gui.update_GUI(self.matrix, self.score) self.history.push(State(self.matrix, self.score, self.tilesum), None)
def create_statechart(self, param): state_chart = Statechart(param) start = StartState(state_chart) A = State(state_chart, TestEntryClassAction("A"), TestDoClassAction("A"), TestExitClassAction("A")) B = State(state_chart, TestEntryClassAction("B"), TestDoClassAction("B"), TestExitClassAction("B")) C = State(state_chart, TestEntryClassAction("C"), TestDoClassAction("C"), TestExitClassAction("C")) end = EndState(state_chart) TestTransition(start, 'start', A, 'A', None, None) TestTransition(A, 'A', B, 'B', Event(1), None) TestTransition(B, 'B', B, 'B', Event(2), None) TestTransition(B, 'B', end, 'end', Event(3), None) TestTransition(B, 'B', C, 'C', Event(4), None) TestTransition(C, 'C', C, 'C', Event(5), None) TestTransition(C, 'C', B, 'B', Event(6), None) TestTransition(C, 'C', A, 'A', Event(7), None) TestTransition(C, 'C', A, 'A', Event(8), None) return state_chart
def restart(self, event): """ Remake the GUI of the grid and reset all variables and score. """ for x in self.gui.main_grid.winfo_children(): x.destroy() self.gui.make_GUI() self.matrix = [[0] * 4 for _ in range(4)] self.changeflag = False self.score = 0 self.add_new_tile(2) self.add_new_tile(2) self.gui.update_GUI(self.matrix, self.score) self.history.delete() self.history.push(State(self.matrix, self.score, self.tilesum), None)
def __init__(self, key, manager): State.__init__(self,key,manager) self.cursor = self.manager.cursor self.player = self.manager.player self.menu = Master([0,0],1024,768,self.screen,self.cursor,"./data/font/carolingia.ttf") self.menu_background = load_image("./data/image/menu/shop.png") self.shopl = load_image("./data/image/menu/shoplayer.png") self.blargh = False self.effects = pygame.sprite.Group() p1 = [[64, 640], [96, 640], [128, 640], [160, 640], [192, 640], \ [96, 672], [128, 672], [160, 672], [192, 672], [256, 640], \ [298, 640], [320, 640], [256, 672], [290, 672], [320, 672], \ [352, 672]] p2 = [[672, 160], [704, 160], [736, 160], [758, 160], [640, 192], \ [672, 192], [704, 192], [736, 192]] pat = [p1, p2] for i in range(12): self.effects.add(Butterfly(random.choice(pat))) self.effects.add(ABoat()) self.rects = [] for i in range(6): self.rects.append(pygame.Rect(58+74*i+288, 23+64, 59, 58)) self.cid = None self.mix()
def populate_action_dictionary(turn_state_space, state_space): #Populates actions to all possible turn states action_dictionary = dict() for turn_state in turn_state_space: current_player = turn_state.player_turn current_state = turn_state.state current_claim = current_state[current_player] action_candidates = lower_claims(current_claim) viable_actions = list() for action in action_candidates: new_state_contents = list(current_state.state_content) new_state_contents[current_player] = action new_state = State(tuple(new_state_contents)) if new_state in state_space: viable_actions.append(action) action_dictionary[turn_state] = tuple(viable_actions) return action_dictionary
def apply(self, state): self.field1.append('blablabla') self.field2['abc'] = 'def' print('=====ROTATE====') st = State.parse(state) print(st) ship = st.player_ships(st.me)[0] mid = (st.field_size + st.planet_size) / 2 x, y = -ship.y, ship.x n = max(abs(x), abs(y)) x, y = mid * x / n, mid * y / n dx = move_towards(ship.x, ship.vx, x) dy = move_towards(ship.y, ship.vy, y) print('===============') if (dx or dy) and ship.fuel: return [ship.do_thrust(dx, dy)] else: return []
def init_minimum_viable_state_graph(verbosity=0): # Construct tap inflow = Quantity("inflow", derivative="+") tap = Tap(inflow=inflow) # Construct container volume = Quantity("volume") container = Container(volume=volume) # Construct drain outflow = Quantity("outflow") drain = Drain(outflow=outflow) # Set up relationships inter_state = [ PositiveInfluence(source="tap.inflow", target="container.volume"), NegativeInfluence(source="drain.outflow", target="container.volume"), PositiveProportion(source="container.volume", target="drain.outflow") ] intra_state = [ PositiveConsequence(target="tap.inflow"), NegativeConsequence(target="tap.inflow"), PositiveConsequence(target="container.volume"), NegativeConsequence(target="container.volume"), PositiveConsequence(target="drain.outflow"), NegativeConsequence(target="drain.outflow"), VCmax(source="container.volume", target="drain.outflow"), VCzero(source="container.volume", target="drain.outflow") ] # Create initial state init_state = State(tap=tap, container=container, drain=drain) # Create state graph state_graph = StateGraph(initial_state=init_state, inter_state=inter_state, intra_state=intra_state, verbosity=verbosity) return state_graph
chainList = [] level = int(input('Enter starting level (0-19): ')) gravity = gravityTable[level] pieceList = [] rowList = [] clearList = [] fetchData(1) fetchData(2) print("Initializing possible seeds...") with tqdm(total=N * 8 * 4, leave=True) as pbar: for i in range(N): for j in range(8): for k in range(4): newChain = StateChain(State(seed, j, k, pieceList[-1])) newChain.addFrames(rowList[-1], clearList[-1], gravity) chainList.append(newChain) pbar.update(8 * 4) seed = State.prng(seed, 1) pieceNum = 3 while len(chainList) > 1: print(f'{len(chainList)} possible third piece seeds.') if len(chainList) < 10: for chain in chainList: print(f'{chain.thirdState}, {chain.tailState}') fetchData(pieceNum) newChainList = []
def __init__(self, driver, player, pgs): State.__init__(self, driver) self._player = player self._pgs = pgs self._menu = None
def transition_state(state, action, player): state_content = list(state.state_content) state_content[player] = action transitioned_state = State(tuple(state_content)) return transitioned_state
def __init__(self,screen,config,objects): State.__init__(self,screen) self.config = config self.objects = objects self.window = LEWindow(screen,config) self.toolbar = LEToolbar(screen,config,objects)
def __init__(self, key, manager): State.__init__(self,key,manager) self.cursor = self.manager.cursor self.pon = 0 self.menu = Master([0,0],1024,768,self.screen,self.cursor,"./data/font/carolingia.ttf") self.menu_background = load_image("./data/image/menu/menu.PNG") self.sbg = load_image("./data/image/menu/storyBG.PNG") self.boxes = [] self.page = 0 icons = Sheet("./data/image/menu/status_icons.png") credit_text = "Programming, design and graphics\nby Marko Pranjic a.k.a mkmgames.\n \ \nMusic is from Celestial Aeon Project;\nYou can find it and download \ it from\nhttp://www.mattipaalanen.com/\n \nFor more info or contact, \ please visit\nhttp//vikingsstory.sourceforge.net" Button(self.menu,[395,155],(0,0,0),None,62,"New Game",self.menu.switch,"diff") Button(self.menu,[395,222],(0,0,0),None,62,"Continue",self.manager.set_state,"map") Button(self.menu,[395,294],(0,0,0),None,62,"Achievements",self.menu.switch,"achievements") Button(self.menu,[294,110],(0,0,0),None,52,"Easy",self.difficulty,4, \ ["diff", "inf1"], hovfun=self.hovinfo, hovarg=A3) Button(self.menu,[294,177],(0,0,0),None,52,"Normal",self.difficulty,2, \ ["diff", "inf1"], hovfun=self.hovinfo, hovarg=A2) Button(self.menu,[294,244],(0,0,0),None,52,"Ragnarok",self.difficulty,0, \ ["diff", "inf1"], hovfun=self.hovinfo, hovarg=A1) Button(self.menu,[395,366],(0,0,0),None,62,"Options",self.menu.switch,"options") Button(self.menu,[395,438],(0,0,0),None,62,"Credits",self.menu.switch,"credits") Button(self.menu,[395,510],(0,0,0),None,62,"Quit",exit,None) Button(self.menu,[273,630],(0,0,0),None,32,"Back",self.menu.switch,"default",["credits"]) Button(self.menu,[273,630],(0,0,0),None,32,"Back",self.menu.switch,"default",["diff", "inf1"]) Button(self.menu,[273,630],(0,0,0),None,32,"Back",self.menu.switch,"default",["options","okbox"]) Button(self.menu,[273,630],(0,0,0),None,32,"Back",self.menu.switch,"default",["achievements", "inf"]) Button(self.menu,[343,630],(0,0,0),None,32,"Apply",self.change_settings,None,["options","okbox"]) self.pic = Image(self.menu,[523,112],TALE[0],["intro","intro1"]) ImageButton(self.menu,[230,613],SIC.get_at((0,19,38,53),False),self.flip, -1, ["intro1"]) ImageButton(self.menu,[790,613],SIC.get_at((38,19,38,53),False),self.flip, 1, ["intro","intro1"]) Textbox(self.menu,[300,155],(0,0,0),None,28,credit_text,3,["credits"]) self.story = Textbox(self.menu,[224,120],(0,0,0),None,28,TXT[0],3,["intro","intro1"]) self.dt = Textbox(self.menu,[392,484],(0,0,0),None,24,"",3, \ ["inf"]) self.achievements = { "TUT":ImageButton(self.menu,[392,211], ACH.get_at((0,177,59,58),True), self.potatoes, \ None, ["achievements", "inf"], hovfun=self.desc, hovarg="TUT"), "WIZ":ImageButton(self.menu,[492,211], ACH.get_at((0,177,59,58),True), self.potatoes, \ None, ["achievements", "inf"], hovfun=self.desc, hovarg="WIZ"), "SAI":ImageButton(self.menu,[592,211], ACH.get_at((0,177,59,58),True), self.potatoes, \ None, ["achievements", "inf"], hovfun=self.desc, hovarg="SAI"), "LUC":ImageButton(self.menu,[392,290], ACH.get_at((0,177,59,58),True), self.potatoes, \ None, ["achievements", "inf"], hovfun=self.desc, hovarg="LUC"), "SHI":ImageButton(self.menu,[492,290], ACH.get_at((0,177,59,58),True), self.potatoes, \ None, ["achievements", "inf"], hovfun=self.desc, hovarg="SHI"), "BUI":ImageButton(self.menu,[592,290], ACH.get_at((0,177,59,58),True), self.potatoes, \ None, ["achievements", "inf"], hovfun=self.desc, hovarg="BUI"), "PER":ImageButton(self.menu,[392,370], ACH.get_at((0,177,59,58),True), self.potatoes, \ None, ["achievements", "inf"], hovfun=self.desc, hovarg="PER"), "INV":ImageButton(self.menu,[492,370], ACH.get_at((0,177,59,58),True), self.potatoes, \ None, ["achievements", "inf"], hovfun=self.desc, hovarg="INV"), "UNL":ImageButton(self.menu,[592,370], ACH.get_at((0,177,59,58),True), self.potatoes, \ None, ["achievements", "inf"], hovfun=self.desc, hovarg="UNL") } self.fs = Checkbox(self.menu,[395,154],(0,0,0),None,32,"Fullscreen",(0,1),["options","okbox"], \ self.manager.config["fullscreen"]) self.fps = Checkbox(self.menu,[395,194],(0,0,0),None,32,"Show FPS",(0,1),["options","okbox"], \ self.manager.config["fps"]) Label(self.menu,[395,234],(0,0,0),None,31,"Music:",["options","okbox"]) self.bs = Scroll(self.menu, [500,234],(0,0,0),None,32,["options","okbox"], \ self.manager.config["bsound"]*100) Label(self.menu,[395,274],(0,0,0),None,31,"Sound:",["options","okbox"]) self.sfx = Scroll(self.menu, [500,274],(0,0,0),None,32,["options","okbox"], \ self.manager.config["sfx"]*100) OKBox(self.menu,(0,0,0),None,22, "You will need to restart\nthe game so changes could\nbe applied.",3,self.menu.switch,"options") self.df = Textbox(self.menu,[525,110],(0,0,0),None,32,"",3, \ ["inf1"]) self.cid = None self.cid1 = None self.check_ach()
def die_strategy(state): print('=====HANG======') st = State.parse(state) ship = st.player_ships(st.me)[0] print('===============') return [ship.do_explode()]
def create_statechart(self, param): state_chart = Statechart(param) start = StartState(state_chart) X = ConcurrentState(state_chart, TestEntryClassAction("X"), TestDoClassAction("X"), TestExitClassAction("X")) TestTransition(start, 'start', X, 'X', None, None) A = HierarchicalState(X, TestEntryClassAction("A"), TestDoClassAction("A"), TestExitClassAction("A")) start_a = StartState(A) history_a = HistoryState(A) D = State(A, TestEntryClassAction("D"), TestDoClassAction("D"), TestExitClassAction("D")) E = State(A, TestEntryClassAction("E"), TestDoClassAction("E"), TestExitClassAction("E")) TestTransition(start_a, 'start_a', history_a, 'history_a', None, None) TestTransition(history_a, 'history_a', D, 'D', None, None) TestTransition(D, 'D', E, 'E', Event(1), None) TestTransition(E, 'E', D, 'D', Event(2), None) B = HierarchicalState(X, TestEntryClassAction("B"), TestDoClassAction("B"), TestExitClassAction("B")) start_b = StartState(B) history_b = HistoryState(B) F = State(B, TestEntryClassAction("F"), TestDoClassAction("F"), TestExitClassAction("F")) G = State(B, TestEntryClassAction("G"), TestDoClassAction("G"), TestExitClassAction("G")) H = State(B, TestEntryClassAction("H"), TestDoClassAction("H"), TestExitClassAction("H")) TestTransition(start_b, 'start_b', history_b, 'history_b', None, None) TestTransition(history_b, 'history_b', F, 'F', None, None) TestTransition(F, 'F', H, 'H', Event(1), None) TestTransition(H, 'H', G, 'G', Event(6), None) TestTransition(G, 'G', F, 'F', Event(2), None) TestTransition(F, 'F', G, 'G', Event(8), None) C = HierarchicalState(state_chart, TestEntryClassAction("C"), TestDoClassAction("C"), TestExitClassAction("C")) start_c = StartState(C) history_c = HistoryState(C) I = State(C, TestEntryClassAction("I"), TestDoClassAction("I"), TestExitClassAction("I")) J = State(C, TestEntryClassAction("J"), TestDoClassAction("J"), TestExitClassAction("J")) K = State(C, TestEntryClassAction("K"), TestDoClassAction("K"), TestExitClassAction("K")) TestTransition(start_c, 'start_c', history_c, 'history_c', None, None) TestTransition(history_c, 'history_c', I, 'I', None, None) TestTransition(J, 'J', X, 'X', Event(13), None) TestTransition(I, 'I', J, 'J', Event(10), None) TestTransition(J, 'J', I, 'I', Event(9), None) TestTransition(J, 'J', K, 'K', Event(12), None) TestTransition(K, 'K', J, 'J', Event(11), None) TestTransition(E, 'E', K, 'K', Event(3), None) TestTransition(B, 'B', C, 'C', Event(5), None) TestTransition(G, 'G', C, 'C', Event(14), None) TestTransition(C, 'C', X, 'X', Event(15), None) return state_chart
def __init__(self, context): State.__init__(self, context, None, None, None)
def apply(self, state): self.T += 1 st = State.parse(state) self.reset_precomputed() all_actions_of_all_ships = [] for ship in st.ships: if ship.id not in self.thrust_predictors: self.thrust_predictors[ship.id] = ThrustPredictor() self.thrust_predictors[ship.id].add(ship.last_actions) my_ships = [] enemy_ships = [] for some_ship in st.ships: if some_ship.id not in self.birthday: self.birthday[some_ship.id] = self.T if some_ship.player == st.me: my_ships.append(some_ship) else: enemy_ships.append(some_ship) self.precompute_enemy_stuff(some_ship) if self.printships: print(f'T:{self.T} Player {st.me}:' + '\n' + "\n".join(str(s) for s in my_ships)) for my_ship in my_ships: # TODO: beter logic if my_ship.laser > 0 and my_ship.lives == 1: all_actions_of_all_ships.extend( self.laser_ship.apply(st, my_ship, enemy_ships, self.enemy_location)) continue actions = [] my_ship = my_ship birthday = self.birthday[my_ship.id] age = self.T - birthday my_pos = [my_ship.x, my_ship.y] my_vel = [my_ship.vx, my_ship.vy] razduplyaemsya = True cur_closest, cur_farthest = trace_orbit(my_pos[0], my_pos[1], my_vel[0], my_vel[1], 265 - self.T) thrust = (0, 0) if cur_closest <= 24: thrust = (-sign(my_pos[0]), -sign(my_pos[0])) if abs( my_pos[0]) > abs(my_pos[1]) else (sign(my_pos[1]), -sign(my_pos[1])) razduplyaemsya = False if cur_farthest > st.field_size: thrust = (sign(my_vel[0]), sign(my_vel[1])) razduplyaemsya = False if self.duplicate and my_ship.lives > 1 and razduplyaemsya: actions.append(my_ship.do_duplicate()) # find closest friend - if too close randomize movement (include velocity in distance computation) closest_ship, dist = None, 1000 for other in my_ships: if other.id == my_ship.id: continue od = abs(other.x - my_ship.x) + abs(other.y - my_ship.y) + abs( other.vx - my_ship.vx) + abs(other.vy - my_ship.vy) if od < dist: dist = od closest_ship = other if closest_ship and dist < 2 and my_ship.vx == closest_ship.vx and my_ship.vy == closest_ship.vy: dx = random.randint(-1, 1) dy = random.randint(-1, 1) x = thrust[0] if thrust[0] == dx else thrust[0] + dx y = thrust[1] if thrust[1] == dy else thrust[0] + dy thrust = x, y # if len(enemy_ships) == 1 and self.T > 200 and st.me == ATACKER: # enemy_ship = enemy_ships[0] # predicted_thrust = self.thrust_predictors[enemy_ship.id].predict() # ex, ey = enemy_ship.next_round_expected_location(predicted_thrust) # x = move_towards(my_ship.x, my_ship.vx, ex) # y = move_towards(my_ship.y, my_ship.vy, ey) # thrust = x, y if my_ship.heat + THRUST_HEAT > my_ship.max_heat: thrust = 0, 0 actions.append([0, my_ship.id, thrust]) thrust_action = Thrust(*thrust) enemy_ship = self.choose_laser_target(my_ship, thrust_action, enemy_ships) if enemy_ship: predicted_thrust = self.enemy_thrust[enemy_ship.id] ex, ey = self.enemy_location[enemy_ship.id] next_dist = my_ship.next_dist(thrust_action, enemy_ship, predicted_thrust) if my_ship.laser and self.do_laser: power = self.asses_laser_power(my_ship, thrust_action, enemy_ship) if power > 0: actions.append(my_ship.do_laser(ex, ey, power)) enemy_ship = self.choose_explode_target(my_ship, thrust_action, enemy_ships) if enemy_ship: predicted_thrust = self.enemy_thrust[enemy_ship.id] next_dist = my_ship.next_dist(thrust_action, enemy_ship, predicted_thrust) if next_dist < 6 and st.me == ATACKER and self.T > 7 and len( my_ships) >= len(enemy_ships): actions = [my_ship.do_explode()] if next_dist < 6 and st.me == DEFENDER and self.T > 7 and len( my_ships) > len(enemy_ships): actions = [my_ship.do_explode()] all_actions_of_all_ships.extend(actions) return all_actions_of_all_ships
def __init__(self, scene, num_steps): State.__init__(self, scene) self.num_steps = num_steps
def __init__(self, scene): State.__init__(self, scene) self.factory_index = 0 self.selection = None
def __init__(self, scene): State.__init__(self, scene) self.hover_filter = lambda x: True
from flask_wtf import FlaskForm from wtforms import StringField, PasswordField, SelectField, SelectMultipleField, HiddenField from wtforms.validators import DataRequired, Email, Optional, EqualTo from wtforms.fields.html5 import TelField from industry import Industry from waste import Waste from states import State from district import District from place import Place ALL_INDUSTRIES = Industry.get_all_industry() ALL_WASTES = Waste.get_all_waste() ALL_STATES = State.get_all_states() ALL_DISTRICTS = District.get_all_district() ALL_PLACES = Place.get_all_places() class EmailPasswordForm(FlaskForm): email = StringField('Email', validators=[DataRequired(), Email()]) password = PasswordField('Password', validators=[DataRequired()]) class ResetPasswordForm(FlaskForm): email = StringField('Email', validators=[DataRequired(), Email()]) password = PasswordField('Password', validators=[DataRequired(), EqualTo('confirm', message='Passwords must match')]) confirm = PasswordField('Repeat Password') class RegisterForm(FlaskForm): industry = SelectField('Industry', choices=map(lambda x: (str(x.id), x.industry), ALL_INDUSTRIES))
def dispatch(self, runtime, event, param): return State.dispatch(self, runtime, event, param)
def __init__(self, driver): State.__init__(self, driver) self._title = pygame.image.load("title.png").convert() mainMenu = [(1, 'Start Game', 0), (2, 'Quit', 0)] self._menu = Menu(driver, (5, 400), mainMenu, None, self) self._shownMenu = 0
def __init__(self, scene, tutorial): State.__init__(self, scene) self.tutorial = tutorial
def id_strategy(state): print('= ID STRATEGY =') State.parse(state) print('===============') return []
# gettin q0 first_state = lines[2].strip() # getting F finall_nfa_states = lines[3].strip().split(" ") # gettin Q Q = lines[1].strip().split(" ") finall_dfa_stated = set() nfa_states = {} dfa_states = {} for x in Q: # making the State objects according to Q nfa_states[x] = State(x) # speify the real states of the states in Q nfa_states[x].add_real_state(x) for x in finall_nfa_states: # specify the states in nfa_states which are final nfa_states[x].set_final() for i in range(len(lines[4:])): # getting the transitions and add them to the relevant state deltas splited = lines[i + 4].split() nfa_states[splited[0]].add_delta(splited[2], splited[1]) for x in nfa_states: # check if the following state has the transition char 't'
def __init__(self, driver): State.__init__(self, driver) self._engine = TileEngine('dungeon.map', driver, self) self._font = pygame.font.Font(None, 20) self._name = random.choice(names) self._messages = [(0, "Welcome to %s" % self._name)] self._deequip = None self._visited = None mapinfo = self._engine.getMapInfo() self._mapinfo = mapinfo self.xp = localXP = 3500 playerStats = { 'level': localXP / 100, 'str': 30, 'dex': 30, 'int': 30, } self.gender = 'Male' self.race = 'Human' self.charClass = 'Guardian' armorStats = { 'name': '+10 Robes of the Guardian', 'absorb': 20, 'toDodge': 10 } weaponStats = { 'name': '+10 Flaming Angelic Sword', 'damageMin': 25, 'damageMax': 75, 'toHit': 10, } weapon = entities.Weapon('sword.png', self._engine, 0, 0, weaponStats) armor = entities.Armor('armor.png', self._engine, 0, 0, armorStats) self._player = Character('player.png', self._engine, mapinfo['startx'], mapinfo['starty'], playerStats, 1) self._player.giveItem(weapon) self._player.equip(weapon) self._player.giveItem(armor) self._player.equip(armor) self._engine.addSprite(self._player) self._engine.centerOn(self._player) staffStats = {'name': 'Terrifyingly Powerful Staff of Glok-Yar'} self._staff = entities.Staff('staff.png', self._engine, mapinfo['staffx'], mapinfo['staffy'], staffStats) self._engine.addSprite(self._staff) self._entries = [] counter = 1 while counter: try: entranceX = mapinfo['entranceX%d' % counter] entranceY = mapinfo['entranceY%d' % counter] entrance = entities.Entry('stairs.png', self._engine, entranceX, entranceY) self._entries.append(entrance) self._engine.addSprite(entrance) counter += 1 except KeyError: counter = 0 self._turn = 0 mixer.music.load(localSoundsDir + '23 - Cold_Mountain_Clouds.ogg') mixer.music.set_volume(localVol * 4) mixer.music.play(-1)
def __init__(self, scene, tank): self.tank = tank State.__init__(self, scene)