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

Source Code for Module state

  1  ################################################################################## 
  2  # Copyright (c) 2011, 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, angularSpeed):
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 __str__(self):
71 return "\nExternal State:" + \ 72 " x=" + str(self.x) + \ 73 " y=" + str(self.y) + \ 74 " orientation=" + str(self.orientation) + \ 75 " speed=" + str(self.speed) + \ 76 " angularSpeed=" + str(self.angularSpeed) + "\n"
77 78 79 80 81
82 -class State:
83 """ 84 This is a base class for the world state. 85 """ 86
87 - def __init__(self, sea, ships, shipExternalStates):
88 """ 89 Initialize the world state that is external to the agent. 90 91 @type sea: Sea 92 @param sea: the sea model 93 94 @type ships: array of Ship 95 @param ships: the ships being simulated 96 97 @type shipExternalStates: array of ShipExternalStates 98 @param shipExternalStates: the external states of the ships, namely their global positions 99 """ 100 #print 'Creating world state' 101 self.sea = sea 102 self.ships = ships 103 self.shipExternalStates = shipExternalStates
104
105 - def __str__(self):
106 res = "\n\nWorld State: \n" 107 res += str(self.sea) 108 res += "\nShips:\n" 109 for ship, state in zip(self.ships, self.shipExternalStates): 110 res += str(ship) + str(state) 111 return res
112 113 # def generateSuccessorFromTime( self, timePassed ): 114 # """ 115 # State change due to time passing 116 # """ 117 # 118 # # TODO: is function needed? 119 # 120 # util.raiseNotDefined() 121 # return self 122 # 123 # 124 # def generateSuccessorFromAction( self, action, shipIndex ): 125 # """ 126 # State change due to ship action 127 # """ 128 # 129 # # TODO: is this function needed? 130 # 131 # util.raiseNotDefined() 132 # self.ships[shipIndex].applyAction( action ) 133 # 134 # return self 135 # 136