Ejemplo n.º 1
0
 def test_mis_matched_config(self):
     config = {'colors': [None, 'r'],
               'c_range': [0.2, 0.7],
               'static': 0.1,
               'match_direction': ['right']}
     color_dict = square.make_color_map(config['colors'])
     self.assertRaises(NotImplementedError, square.set_match_colors, config, color_dict)
Ejemplo n.º 2
0
 def test_fixed_match_colors(self):
     config = {'colors': ['b'],
               'c_range': [0.2, 0.7],
               'static': 0.1,
               'match_direction': ['right']}
     color_dict = square.make_color_map(config['colors'])
     color_list = square.set_match_colors(config, color_dict)
     self.assertEqual([0.1, 0.1, 0.7], color_list)
Ejemplo n.º 3
0
 def test_mis_matched_config(self):
     config = {
         'colors': [None, 'r'],
         'c_range': [0.2, 0.7],
         'static': 0.1,
         'match_direction': ['right']
     }
     color_dict = square.make_color_map(config['colors'])
     self.assertRaises(NotImplementedError, square.set_match_colors, config,
                       color_dict)
Ejemplo n.º 4
0
 def test_fixed_match_colors(self):
     config = {
         'colors': ['b'],
         'c_range': [0.2, 0.7],
         'static': 0.1,
         'match_direction': ['right']
     }
     color_dict = square.make_color_map(config['colors'])
     color_list = square.set_match_colors(config, color_dict)
     self.assertEqual([0.1, 0.1, 0.7], color_list)
Ejemplo n.º 5
0
 def test_translate_color_map(self):
     config = {'colors': ['r', 'b'], 'c_range': [0.2, 0.7], 'static': 0.1}
     color_dict = square.make_color_map(config['colors'])
     # start at extreme ends, should translate to -1, 1
     color_list = (0.2, 0.1, 0.7)
     # after translating,
     x_y = [-1, 1]
     translated, factor = square.translate_color_map(
         config, color_dict, color_list)
     self.assertAlmostEqual(4, factor)
     self.assertEqual(x_y, translated)
Ejemplo n.º 6
0
 def test_translate_color_map_expanded(self):
     config = {'colors': ['r', 'b'],
               'c_range': [0.1, 0.9],
               'static': 0.1}
     color_dict = square.make_color_map(config['colors'])
     # start at extreme ends, should translate to -1, 1
     color_list = (0.1, 0.1, 0.9)
     # after translating,
     x_y = [-1, 1]
     translated, factor = square.translate_color_map(config, color_dict, color_list)
     self.assertAlmostEqual(2.5, factor)
     self.assertEqual(x_y, translated)
Ejemplo n.º 7
0
 def test_make_color_map(self):
     colors = ['r', 'b']
     color_map = square.make_color_map(colors)
     # mapping, x, y, z, r is 0, g is 1, b is 2
     known = {0: 0, 1: 2, 2: None}
     self.assertEqual(color_map, known)
Ejemplo n.º 8
0
 def test_make_color_map_with_new_order(self):
     colors = ['g', 'b', 'r']
     color_map = square.make_color_map(colors)
     known = {0: 1, 1: 2, 2: 0}
     self.assertEqual(color_map, known)
Ejemplo n.º 9
0
 def test_make_color_map_with_z(self):
     colors = ['r', 'b', 'g']
     color_map = square.make_color_map(colors)
     known = {0: 0, 1: 2, 2: 1}
     self.assertEqual(color_map, known)
Ejemplo n.º 10
0
    def __init__(self, config=None):
        # keep track of velocity, this allows me to counteract joystick with keyboard
        self.velocity = LVector3(0)
        if config is None:
            self.config = {}
            execfile('config.py', self.config)
        else:
            self.config = config
        self.reward = None
        if pydaq:
            self.reward = pydaq.GiveReward()
        self.reward_count = 0
        # self.color_map always corresponds to (r, g, b)
        # does not change during game, each game uses a particular color space
        self.color_dict = square.make_color_map(self.config['colors'])
        # sets the range of colors for this map
        self.c_range = self.config['c_range']
        # color variables (make dictionary?)
        # color_list is set in beginning, and then after that this is only
        # called again for non-random (training)
        self.color_list = square.set_start_position_colors(self.config)
        self.color_match = [0, 0, 0]
        self.color_tolerance = []
        self.last_avt, self.avt_factor = square.translate_color_map(
            self.config, self.color_dict, self.color_list)
        print 'starting avt position', self.last_avt
        print 'map avatar factor', self.avt_factor
        self.random = True
        if self.config.get('match_direction'):
            self.random = False
        # adjustment to speed so corresponds to gobananas task
        # 7 seconds to cross original environment
        # speed needs to be adjusted to both speed in original
        # environment and c_range of colors
        # self.speed = 0.05 * (self.c_range[1] - self.c_range[0])
        # speed is own variable, so can be changed during training.
        self.speed = self.config['speed']
        # map avatar variables
        self.render2d = None
        self.match_square = None
        self.map_avt_node = []

        # need a multiplier to the joystick output to tolerable speed
        self.vel_base = 3
        self.max_vel = [500, 500, 0]

        self.card = None

        self.base = ShowBase()
        self.base.disableMouse()
        # assume we are showing windows unless proven otherwise
        if self.config.get('win', True):
            # only need inputs if we have a window
            self.inputs = Inputs(self.base)
            props = WindowProperties()
            props.setCursorHidden(True)
            props.setForeground(True)
            print self.config.get('resolution')
            if self.config.get('resolution'):
                props.set_size(int(self.config['resolution'][0]),
                               int(self.config['resolution'][1]))
                props.set_origin(0, 0)
            else:
                props.set_size(600, 600)
                props.set_origin(400, 50)
            self.base.win.requestProperties(props)
            # print self.base.win.get_size()
            # setup color map on second window
            sq_node = square.setup_square(self.config)
            self.setup_display2(sq_node)
        # print 'background color', self.base.getBackgroundColor()
        # create the avatar
        self.avatar = NodePath(ActorNode("avatar"))
        self.avatar.reparentTo(self.base.render)
        self.avatar.setH(self.base.camera.getH())
        self.base.camera.reparentTo(self.avatar)
        self.base.camera.setPos(0, 0, 0)

        # initialize task variables
        self.frame_task = None
        self.started_game = None
        self.showed_match = None
        self.gave_reward = None

        # initialize and start the game
        self.set_next_trial()
Ejemplo n.º 11
0
 def test_make_color_map(self):
     colors = ['r', 'b']
     color_map = square.make_color_map(colors)
     # mapping, x, y, z, r is 0, g is 1, b is 2
     known = {0: 0, 1: 2, 2: None}
     self.assertEqual(color_map, known)
Ejemplo n.º 12
0
 def test_make_color_map_with_new_order(self):
     colors = ['g', 'b', 'r']
     color_map = square.make_color_map(colors)
     known = {0: 1, 1: 2, 2: 0}
     self.assertEqual(color_map, known)
Ejemplo n.º 13
0
 def test_make_color_map_with_z(self):
     colors = ['r', 'b', 'g']
     color_map = square.make_color_map(colors)
     known = {0: 0, 1: 2, 2: 1}
     self.assertEqual(color_map, known)
Ejemplo n.º 14
0
    def __init__(self, config=None):
        # keep track of velocity, this allows me to counteract joystick with keyboard
        self.velocity = LVector3(0)
        if config is None:
            self.config = {}
            execfile('config.py', self.config)
        else:
            self.config = config
        self.reward = None
        if pydaq:
            self.reward = pydaq.GiveReward()
        self.reward_count = 0
        # self.color_map always corresponds to (r, g, b)
        # does not change during game, each game uses a particular color space
        self.color_dict = square.make_color_map(self.config['colors'])
        # sets the range of colors for this map
        self.c_range = self.config['c_range']
        # color variables (make dictionary?)
        # color_list is set in beginning, and then after that this is only
        # called again for non-random (training)
        self.color_list = square.set_start_position_colors(self.config)
        self.color_match = [0, 0, 0]
        self.color_tolerance = []
        self.last_avt, self.avt_factor = square.translate_color_map(self.config, self.color_dict, self.color_list)
        print 'starting avt position', self.last_avt
        print 'map avatar factor', self.avt_factor
        self.random = True
        if self.config.get('match_direction'):
            self.random = False
        # adjustment to speed so corresponds to gobananas task
        # 7 seconds to cross original environment
        # speed needs to be adjusted to both speed in original
        # environment and c_range of colors
        # self.speed = 0.05 * (self.c_range[1] - self.c_range[0])
        # speed is own variable, so can be changed during training.
        self.speed = self.config['speed']
        # map avatar variables
        self.render2d = None
        self.match_square = None
        self.map_avt_node = []

        # need a multiplier to the joystick output to tolerable speed
        self.vel_base = 3
        self.max_vel = [500, 500, 0]

        self.card = None

        self.base = ShowBase()
        self.base.disableMouse()
        # assume we are showing windows unless proven otherwise
        if self.config.get('win', True):
            # only need inputs if we have a window
            self.inputs = Inputs(self.base)
            props = WindowProperties()
            props.setCursorHidden(True)
            props.setForeground(True)
            print self.config.get('resolution')
            if self.config.get('resolution'):
                props.set_size(int(self.config['resolution'][0]), int(self.config['resolution'][1]))
                props.set_origin(0, 0)
            else:
                props.set_size(600, 600)
                props.set_origin(400, 50)
            self.base.win.requestProperties(props)
            # print self.base.win.get_size()
            # setup color map on second window
            sq_node = square.setup_square(self.config)
            self.setup_display2(sq_node)
        # print 'background color', self.base.getBackgroundColor()
        # create the avatar
        self.avatar = NodePath(ActorNode("avatar"))
        self.avatar.reparentTo(self.base.render)
        self.avatar.setH(self.base.camera.getH())
        self.base.camera.reparentTo(self.avatar)
        self.base.camera.setPos(0, 0, 0)

        # initialize task variables
        self.frame_task = None
        self.started_game = None
        self.showed_match = None
        self.gave_reward = None

        # initialize and start the game
        self.set_next_trial()