Exemplo n.º 1
0
	def insertToken(self, verb, object):
		pos= self.pos;
		time= self.getTime(pos);
		subject= self.script.getFocusedActor(time);
		if type(object) is tuple or type(object) is str:
			newAction= action.Action(subject, verb, object);
		else:
			newAction= action.Action(subject, verb, object.value);
		actionText= newAction.toText();
		if self.isStartToken(pos) or self.isEndToken(pos):
			self.insertData(pos, time, actionText, newAction);
		else:
			begin, end= self.getTextRange(pos);
			beginText= self.value[begin:pos];
			endText= self.value[pos:end];
			beginAction= action.Action(subject, verbs.SAY, beginText);
			endAction= action.Action(subject, verbs.SAY, endText);
			beginTime= self.getTime(begin);
			self.removeData(begin, end, beginTime);
			self.insertData(begin, beginTime, endText, endAction);
			self.insertData(begin, beginTime, actionText, newAction);
			self.insertData(begin, beginTime, beginText, beginAction);
		self.moveRight();
		self.updateState();
		self.focus();
		return True;
Exemplo n.º 2
0
 def changeActor(self, newSubject):
     pos= self.pos;
     time= self.getTimeForInsert(pos);
     oldSubject= self.script.getFocusedActor(time);
     if type(newSubject) is not actor.Actor:
         newSubject= newSubject.value;
     newAction= action.Action(newSubject, verbs.FOCUS, None);
     cue= newAction.toText();
     if self.isMiddleSpeech(pos):
         #get text range
         begin, end= self.getTextRange(pos);
         beginText= self.value[begin:pos];
         endText= self.value[pos:end];
         beginAction= action.Action(oldSubject, verbs.SAY, beginText);
         endAction= action.Action(oldSubject, verbs.SAY, endText);
         beginTime= self.getTimeForDelete(begin);
         # remove old text, add in first part, change, and second part
         self.removeData(begin, end, beginTime);
         self.insertData(begin, beginTime, endText, endAction);
         self.insertData(begin, beginTime, cue, newAction);
         self.insertData(begin, beginTime, beginText, beginAction);
         self.script.changeActor(beginTime, newSubject);
     else:
         self.insertData(pos, time+1, cue, newAction);
         self.script.changeActor(time+2, newSubject);
     self.moveRight();
     self.updateState();
Exemplo n.º 3
0
 def __init__(self, default_name, path, dreamland):
     super().__init__(default_name, path)
     self.actions.append(
         action.Action(self.lay, ["lay", "sleep"], True, True))
     self.actions.append(action.Action(self.stand, ['stand'], True, True))
     self.closable = False
     self.fix_in_place('Moving the bed would require a lot of effort.')
     self.set_prepositions('on', 'onto', 'atop')
     self.dreamland = dreamland
Exemplo n.º 4
0
	def makeActions(self, character):
		"""
		Given a *State* object, creates a list of *Action*s that could be 
		applied to another state to transform it into this one.
		"""
		actionList= [action.Action(character, verbs.FEEL, self.look),
					 action.Action(character, verbs.MOVE, self.position),
					 action.Action(character, verbs.DO, self.pose),
					 action.Action(character, verbs.FACE, self.direction)];
		return actionList;
Exemplo n.º 5
0
 def __init__(self, default_name, path):
     super().__init__(default_name, path)
     self.fix_in_place(
         'The door is strongly secured in place. You can\'t take it.')
     self.opened = False
     self.view_through_door = None
     self.destination = None
     self.actions.append(action.Action(self.open, ['open'], True, False))
     self.actions.append(
         action.Action(self.close, ['close', 'shut', 'slam'], True, False))
     self.actions.append(action.Action(self.enter, ['enter'], True, False))
     self.add_adjectives(default_name)
     self.add_names('door', 'quest')
Exemplo n.º 6
0
 def push_queue_ui(self, obj: str):
     json_obj = json.loads(obj)
     act = json_obj.get('action')
     timestamp = json_obj.get('time') or self._game_obj.current_time
     if act and act[0] == '_':
         self._game_obj.enqueue(
             timestamp,
             action.Action(
                 '{"action":"_platform","ai_id":%d}' % self._ai_id, act,
                 self.send_thread.sig))
     else:
         self._game_obj.enqueue(
             timestamp, action.Action(obj, 'query', self.send_thread.sig))
Exemplo n.º 7
0
 def __init__(self, color):
     super().__init__('chair', __file__)
     self.set_description(
         '%s chair' % color,
         'This comfortable chair is covered in a %s felt-like surface.' %
         color)
     del Chair.avalible_colors[Chair.avalible_colors.index(color)]
     self.add_adjectives('comfortable', color)
     self.sitting = None
     self.actions.append(
         action.Action(self.sit, ['sit', 'relax'], True, True))
     self.actions.append(action.Action(self.stand, ['stand'], False, True))
     self.color = color
     thing.Thing.game.register_heartbeat(self)
Exemplo n.º 8
0
    def FixedGunCommand(self, cmd):
        actions = []

        if 'command' in cmd:
            if cmd['command'] == 'FIRE':

                if self.isLoaded():
                    # Reset the reload ticks
                    self.setReloadTicksToFull()

                    a = action.Action()
                    a.setType('HIGHSPEED_PROJECTILE')
                    a.addData('slot_id', self.getData('slot_id'))
                    a.addData('compname', self.getData('name'))
                    a.addData('direction',
                              self.getData('parent').getData('facing'))
                    a.addData('min_damage', self.getData('min_damage'))
                    a.addData('max_damage', self.getData('max_damage'))
                    a.addData('range', self.getData('range'))
                    actions.append(a)

            elif cmd['command'] == 'RELOAD':

                # We can reload if we aren't reloading,
                #   we are not currently loaded
                #   and we have ammo left.
                if not self.data['reloading'] and not self.isLoaded(
                ) and self.getData('ammunition') > 0:
                    self.data['reloading'] = True

        # See if we were reloading
        self.updateReloading()

        return actions
Exemplo n.º 9
0
 def __init__(self):
     super().__init__('portal', __file__)
     self.set_description('portal', 'This ancient portal is made of three vast stones, each covered '
                          'with arcane runes. A vertical sheet of glowing flame roars between the '
                          'stones, filling the portal with an inferno of powerful magic fire.')
     self.actions.append(action.Action(self.enter, ['enter'], True, False))
     self.add_adjectives('flaming', 'stone')
Exemplo n.º 10
0
def gameLoop(game):
    # set up parser
    playparser = p.Parser()
    # start playing
    while True:
        # flush standard in
        termios.tcflush(sys.stdin, termios.TCIFLUSH)

        # game.getTime() # uncomment this if you need it!

        # game continues until user enters quit at the prompt
        received = input("> ")
        if "quit" in received:
            print("Do you want to save this game? (y/n)")
            received = input("> ")
            if "y" in received:
                saveGame(game)
                return
            else:
                break
        elif "savegame" in received:
            saveGame(game)
            return
        else:
            playaction = action.Action()
            playaction = playparser.parseInput(received)
            if (isinstance(playaction, action.Action)):
                #print(playaction.verb, playaction.direction, playaction.direct_obj, playaction.indirect_obj)
                game.fromParserToGame(playaction)
Exemplo n.º 11
0
    def one_step_lookahead(self, value, error_prob=0):

        new_policy_matrix = [[[None for y in xrange(self.length)]
                              for x in xrange(self.width)]
                             for h in xrange(self.num_headings)]
        for state in self.state_space.states:
            possible_states = self.state_space.get_adjacent_states(state)
            max_action_value = float("-inf")
            best_action = None
            for action_tuple in ac.action_space:
                action = ac.Action(action_tuple[0], action_tuple[1])
                action_value = 0
                for next_state in possible_states:
                    x, y, h = next_state.get_state()
                    action_value += self.transition_prob(
                        error_prob, state, action,
                        next_state) * value[h][x][y]  # add all Psa(s')V(s')
                if action_value > max_action_value:
                    max_action_value = action_value
                    best_action = action

            x, y, h = state.get_state()
            new_policy_matrix[h][x][y] = best_action

        new_policy = pol.Policy(new_policy_matrix)
        return new_policy
Exemplo n.º 12
0
def clone():
    paper = thing.Thing('paper', __file__)
    paper.set_description('paper',
                          'This paper appears to be part of a letter.')
    paper.actions.append(action.Action(read, ['read'], True, False))
    paper.add_names('letter')
    return paper
Exemplo n.º 13
0
    def _doBegin(self, pose):
        """
		Apply the action
		"""
        self.applyAction(action.Action(self, verbs.DO, pose))
        self._actionStartTime = getCurrentTime()
        return phases.CONTINUE, 0
Exemplo n.º 14
0
def clone():
    paper = thing.Thing('paper', __file__)
    paper.set_description('torn paper',
                          'This paper appears to be torn from a book.')
    paper.actions.append(action.Action(read, ['read'], True, False))
    paper.add_adjectives('torn')
    return paper
Exemplo n.º 15
0
 def changeDirection(self, direction):
     focusedActor = self.script.controls['actor-group-focus'].value
     faceAction = action.Action(focusedActor, verbs.FACE, direction)
     self.script.applyAction(0, faceAction)
     focusedActor.state.direction = direction
     focusedActor.changeBodyDirection()
     self.script.scriptChanged()
Exemplo n.º 16
0
    def _feelBegin(self, emotion):
        """
		Changes the actor's state and immediately moves to the CONTINUE phase
		"""
        self.applyAction(action.Action(self, verbs.FEEL, emotion))
        self._actionStartTime = getCurrentTime()
        return phases.CONTINUE, 0
Exemplo n.º 17
0
    def _faceBegin(self, direction):
        """
		Change the actors direction.
		"""
        self.applyAction(action.Action(self, verbs.FACE, direction))
        self._actionStartTime = getCurrentTime()
        return phases.CONTINUE, 0
 def __init__(self, interface, automatic=False):
     """Expert is the driver that the ANN is supposed to imitate"""
     self.prev_shift_up = False
     self.prev_shift_down = False
     self.act = action.Action()
     self.interface = interface
     self.automatic = automatic
Exemplo n.º 19
0
	def changeCharacter(self, object):
		pos= self.pos;
		time= self.getTime(pos);
		oldAction= self.script.actions[time];
		oldSubject= self.script.getFocusedActor(time);
		newSubject= object.value;
		newAction= action.Action(newSubject, verbs.FOCUS, None);
		token= newAction.toText();
		if self.isStartToken(pos) or self.isEndToken(pos):
			self.insertData(pos, time, token, newAction);
			self.script.changeActor(time+1, newSubject);
		else:
			begin, end= self.getTextRange(pos);
			beginText= self.value[begin:pos];
			endText= self.value[pos:end];
			beginAction= Action(oldSubject, verbs.SAY, beginText);
			endAction= Action(oldSubject, verbs.SAY, endText);
			beginTime= self.getTime(begin);
			self.removeData(begin, end, beginTime);
			self.insertData(begin, beginTime, endText, endAction);
			self.insertData(begin, beginTime, token, newAction);
			self.insertData(begin, beginTime, beginText, beginAction);
			self.script.changeActor(time+2, newSubject);
		self.moveRight();
		self.updateState();
Exemplo n.º 20
0
def clone():
    paper = thing.Thing('paper', __file__)
    paper.set_description('paper',
                          'This paper appears to be a note of some sort.')
    paper.actions.append(action.Action(read, ['read'], True, False))
    paper.add_names('note')
    return paper
Exemplo n.º 21
0
	def __init__(self, ID, path, fixed_to):
		super().__init__(ID, path)
		self.written_on = 'domains.school.forest.woods'
		self.actions.append(action.Action(self.write, ['write'], True, False))
		self.fix_in_place('This paper is fixed to the %s with sorcery.' % fixed_to)
		self.set_description('magical piece of paper', 'This magical paper says "woods" on it.')
		self.add_names('paper')
		self.add_adjectives('magical')
Exemplo n.º 22
0
 def changeLook(self):
     look = self.script.controls['actor-select-look'].value
     focusedActor = self.script.controls['actor-group-focus'].value
     feelAction = action.Action(focusedActor, verbs.FEEL, look)
     self.script.applyAction(0, feelAction)
     focusedActor.state.look = look
     focusedActor.changeFaceExpression()
     self.script.scriptChanged()
Exemplo n.º 23
0
    def __parse_actions(self, tree):
        node = self.node.find('actions')
        if node == None:
            return

        for subnode in node.findall('action'):
            element = action.Action(subnode, tree)
            self.actions[element.name] = element
Exemplo n.º 24
0
 def changePose(self):
     pose = self.script.controls['actor-select-pose'].value
     focusedActor = self.script.controls['actor-group-focus'].value
     doAction = action.Action(focusedActor, verbs.DO, pose)
     self.script.applyAction(0, doAction)
     focusedActor.state.pose = pose
     focusedActor.changeBodyPose()
     self.script.scriptChanged()
Exemplo n.º 25
0
 def run(self):
     global root_logger
     while 1:
         if self._game.current_time > self._limit:
             root_logger.info('put stop signal')
             self._game.enqueue(0, action.Action('{"action":"_platform"}', "_end", None))
             return
         else:
             time.sleep(self._limit - self._game.current_time)
Exemplo n.º 26
0
 def insertLetter(self, letter):
     pos= self.pos;
     time= self.getTimeForInsert(pos);
     subject= self.script.getFocusedActor(time);
     if self.isNoSpeech(pos):
         #Insert somewhere without speech
         newAction= action.Action(subject, verbs.SAY, letter);
         self.insertData(pos, time+1, letter, newAction);
     else:
         #Insert at the end, middle, or beginning of speech
         begin, end= self.getTextRange(pos);
         beginText= self.value[begin:pos];
         endText= self.value[pos:end];
         text= beginText + letter + endText;
         textAction= action.Action(subject, verbs.SAY, text);
         time= self.getTimeForDelete(begin);
         self.removeData(begin, end, time);
         self.insertData(begin, time, text, textAction);
Exemplo n.º 27
0
	def insertLetter(self, letter):
		pos= self.pos;
		time= self.getTime(pos);
		subject= self.script.getFocusedActor(time);
		newAction= action.Action(subject, verbs.SAY, letter);
		if self.isStartToken(pos) and self.isEndToken(pos):
			#Insert somewhere without speech
			self.insertData(pos, time, letter, newAction);
		else:
			#Insert at the end, middle, or beginning of speech
			begin, end= self.getTextRange(pos);
			beginText= self.value[begin:pos];
			endText= self.value[pos:end];
			text= "".join(beginText,letter,endText);
			textAction= action.Action(subject, verbs.SAY, text);
			time= self.getTime(begin);
			self.removeData(begin, end, time);
			self.insertData(begin, time, text, textAction);
Exemplo n.º 28
0
def clone():
    poppy = flowerMod.Flower("poppy", __file__, 'poppy')
    poppy.set_description(
        "red poppy", "This poppy is VERY pretty! You really want to pick it!")
    poppy.set_volume(2.122)
    poppy.set_weight(200)
    poppy.add_adjectives("very", "pretty")
    poppy.actions.append(action.Action(poppy.take, ['pick'], True, False))
    return poppy
Exemplo n.º 29
0
 def deleteCue(self):
     """Returns true if it deleted a CUE, else False if it deleted a Letter or nothing."""
     pos= self.pos;
     time= self.getTimeForDelete(pos);
     subject= self.script.getFocusedActor(time);
     length= len(self.value);
     if self.isStartCue(pos): #Cue
         if self.value[pos] == '\n': #FOCUS
             end= self.value.find('\t', pos, length)+1;
             insertTime= self.getTimeForInsert(pos);
             newSubject= self.script.getFocusedActor(insertTime);
             self.removeData(pos, end, time);
             if self.isBeforeEnd(pos): #Give any other actions to this actor
                 self.script.changeActor(time, newSubject);
         else: #non-FOCUS
             end= self.value.find('>',pos, length)+1;
             self.removeData(pos, end, time);
         if self.isMiddleSpeech(pos):
             #Recombine stray speeches
             begin, end= self.getTextRange(pos);
             time= self.getTimeForDelete(begin);
             text= self.value[begin:end];
             textAction= action.Action(subject, verbs.SAY, text);
             self.removeData(begin, pos, time);
             self.removeData(begin, end-(pos-begin), time);
             self.insertData(begin, time, text, textAction);
         return True;
     elif self.isBeforeEnd(pos): #Letter
         begin, end= self.getTextRange(pos);
         beginText= self.value[begin:pos];
         endText= self.value[pos+1:end]; #skip the letter at pos
         text= beginText+endText;
         time= self.getTimeForDelete(begin);
         if text:
             #There is some text
             textAction= action.Action(subject, verbs.SAY, text);
             self.removeData(begin, end, time);
             self.insertData(begin, time, text, textAction);
         else:
             self.removeData(begin, end, time);
         return False;
     else:
         print "D'oh";
         return False;
Exemplo n.º 30
0
    def _possible_action_piece(self):
        is_free = self.board_interface.is_free
        board = self.board_interface

        moves = []
        row, col = self.position
        can_capture = False

        for delta_row in (-1, 0, 1):
            for delta_column in (-1, 0, 1):
                if delta_row == 0 and delta_column == 0:
                    continue

                current_move = (row + delta_row, col + delta_column)
                #print "Piece {0} for player {1}: Trying {2}".format(self.position, self.board_element, current_move)
                obstruction_move = (row + 2 * delta_row,
                                    col + 2 * delta_column)

                if is_free(current_move[0], current_move[1]):
                    #print "Piece {0} for player {1}: Is free".format(self.position, self.board_element)
                    if not can_capture:
                        moves.append(
                            action.Action('MOVE', (row, col), current_move))

                elif is_free(obstruction_move[0], obstruction_move[1]):
                    obstructed_piece = board.get_piece(current_move[0],
                                                       current_move[1])

                    if obstructed_piece.board_element != self.board_element:
                        moves.append(
                            action.Action('CAPTURE', (row, col),
                                          obstruction_move, obstructed_piece))
                        can_capture = True

        if can_capture:
            new_moves = []

            for move in moves:
                if move.type_ == 'CAPTURE':
                    new_moves.append(move)

            return new_moves

        return moves