Module state
[hide private]
[frames] | no frames]

Source Code for Module state

  1  ################################################################################## 
  2  # Copyright (c) 2010, 2011, 2012, 2013, Daniel Urieli, Peter Stone 
  3  # University of Texas at Austin 
  4  # All right reserved 
  5  #  
  6  # Based On: 
  7  #  
  8  # Copyright (c) 2000-2003, Jelle Kok, University of Amsterdam 
  9  # All rights reserved. 
 10  #  
 11  # Redistribution and use in source and binary forms, with or without 
 12  # modification, are permitted provided that the following conditions are met: 
 13  #  
 14  # 1. Redistributions of source code must retain the above copyright notice, this 
 15  # list of conditions and the following disclaimer. 
 16  #  
 17  # 2. Redistributions in binary form must reproduce the above copyright notice, 
 18  # this list of conditions and the following disclaimer in the documentation 
 19  # and/or other materials provided with the distribution. 
 20  #  
 21  # 3. Neither the name of the University of Amsterdam nor the names of its 
 22  # contributors may be used to endorse or promote products derived from this 
 23  # software without specific prior written permission. 
 24  #  
 25  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 26  # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 27  # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
 28  # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 
 29  # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
 30  # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
 31  # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
 32  # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 
 33  # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
 34  # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
 35  ################################################################################## 
 36   
 37   
 38   
 39   
40 -class ShipExternalState:
41 """ 42 The state of the ship for an outside observer 43 """ 44
45 - def __init__(self, x, y, orientation, speed=0, angularSpeed=0):
46 """ 47 Initialize an I{external state} of a ship, namely its position and speeds 48 49 @type x: float 50 @param x: x-position, in meters 51 52 @type y: float 53 @param y: y-position, in meters 54 55 @type orientation: float 56 @param orientation: the ship orientation, where -180 < orientation <= 180 degrees 57 58 @type speed: float 59 @param speed: ship forward speed in m/sec (TODO: need to replace it by x-speed and y-speed) 60 61 @type angularSpeed: float 62 @param angularSpeed: ship angular speed in deg / sec 63 """ 64 self.x = x 65 self.y = y 66 self.orientation = orientation 67 self.speed = speed 68 self.angularSpeed = angularSpeed
69
70 - def __eq__(self, other):
71 return (isinstance(other, self.__class__) and self.__dict__ == other.__dict__)
72
73 - def __str__(self):
74 return "\nExternal State:" + \ 75 " x=" + str(self.x) + \ 76 " y=" + str(self.y) + \ 77 " orientation=" + str(self.orientation) + \ 78 " speed=" + str(self.speed) + \ 79 " angularSpeed=" + str(self.angularSpeed) + "\n"
80 81 82 83 84
85 -class State:
86 """ 87 This is a base class for the world state. 88 """ 89
90 - def __init__(self, sea, ships, shipExternalStates):
91 """ 92 Initialize the world state that is external to the agent. 93 94 @type sea: Sea 95 @param sea: the sea model 96 97 @type ships: array of Ship 98 @param ships: the ships being simulated 99 100 @type shipExternalStates: array of ShipExternalStates 101 @param shipExternalStates: the external states of the ships, namely their global positions 102 """ 103 #print 'Creating world state' 104 self.sea = sea 105 self.ships = ships 106 self.shipExternalStates = shipExternalStates
107
108 - def __str__(self):
109 res = "\n\nWorld State: \n" 110 res += str(self.sea) 111 res += "\nShips:\n" 112 for ship, state in zip(self.ships, self.shipExternalStates): 113 res += str(ship) + str(state) 114 return res
115 116 # def generateSuccessorFromTime( self, timePassed ): 117 # """ 118 # State change due to time passing 119 # """ 120 # 121 # # TODO: is function needed? 122 # 123 # util.raiseNotDefined() 124 # return self 125 # 126 # 127 # def generateSuccessorFromAction( self, action, shipIndex ): 128 # """ 129 # State change due to ship action 130 # """ 131 # 132 # # TODO: is this function needed? 133 # 134 # util.raiseNotDefined() 135 # self.ships[shipIndex].applyAction( action ) 136 # 137 # return self 138 # 139