Пример #1
0
class EncoderTest( TestCase ):
	""" """

	def setUp(self):
		""" """
		self.playerFactory = PlayerFactorySetup.create()
		self.blockTypeFactory = BlockTypeFactorySetup.create()
		self.encoder = Encoder( self.playerFactory, self.blockTypeFactory )
		return None

	def size(self):
		""" """
		# there is only one block so the block id fits in one byte, same for the player
		# id, then an additional byte for the damage and an additional byte for the seed,
		# giving a total of 4
		self.assertEqual( self.encoder.size(), 4 )
		return None

	def intToBytesConversion(self):
		""" """
		self.assertEqual( self.encoder.intToByteList( 256 ), [1, 0] )
		self.assertEqual( self.encoder.intToByteList( 512 ), [2, 0] )
		self.assertEqual( self.encoder.intToByteList( 110 ), [ 110 ] )
		return None

	def bytesToIntConversion(self):
		""" """
		self.assertEqual( self.encoder.byteListToInt([1, 1]), 257 )
		self.assertEqual( self.encoder.byteListToInt([110]), 110 )
		return 

	def encoding(self):
		""" """
		player = self.playerFactory.fromName( 'Jhon' )
		dirt = self.blockTypeFactory.fromName( 'dirt' )
		block = dirt.newBlock( player )
		block.seed = 110

		self.assertIsInstance( self.encoder.encodeBlock(block), str )
		self.assertEqual( self.encoder.encodeBlock( block ), "\x01\x01\x00n" )
		return None

	def decoding(self):
		""" """
		pos = Vec3( 0, 0, 0 )
		self.assertIsInstance( self.encoder.decodeBlock( "\x01\x01\x00n", pos ), BlockIF )
		self.assertEqual( self.encoder.decodeBlock( "\x01\x01\x00n", pos ).blockType
				, self.blockTypeFactory.fromName( 'dirt' )
				)
		return None
Пример #2
0
# == ENCODER ==
# Encoder sensor A
pinEncA = 26
# Encoder sensor B
#pinEncB = 20

# == GYROSCOPE ==
# Gyroscope uses pins 2 and 3

# = SETUP SENSORS =
ultraA = Ultra.Measurement(trigA, echoA)
#ultraB = Ultra.Measurement(trigB, echoB)
#ultraC = Ultra.Measurement(trigC, echoC)

encA = Encoder(pinEncA)
#encB = Encoder(pinEncB)

gyroA = Gyroscope()


# = AUXILIARY FUNCTIONS =
def ultraA_read():
    tpp = time()
    while (True):
        raw = ultraA.raw_distance(sample_size=1, sample_wait=0.1)
        metric = ultraA.distance_metric(raw)

        #sleep(1)
        if (time() - tpp > 1):
            tpp = time()
Пример #3
0
embedding_dim = 256
units = 1024
vocab_inp_size = len(inp_lang.word_index)+1
vocab_tar_size = len(targ_lang.word_index)+1

dataset = tf.data.Dataset.from_tensor_slices((input_tensor_train, target_tensor_train)).shuffle(BUFFER_SIZE)
dataset = dataset.batch(BATCH_SIZE, drop_remainder=True)

example_input_batch, example_target_batch = next(iter(dataset))
example_input_batch.shape, example_target_batch.shape
#==================================DataPreparation=======================================


#==================================Encoder===============================================
from lib.encoder import Encoder
encoder = Encoder(vocab_inp_size, embedding_dim, units, BATCH_SIZE)

# sample input
sample_hidden = encoder.initialize_hidden_state()
sample_output, sample_hidden = encoder(example_input_batch, sample_hidden)
print ('Encoder output shape: (batch size, sequence length, units) {}'.format(sample_output.shape))
print ('Encoder Hidden state shape: (batch size, units) {}'.format(sample_hidden.shape))

#==================================Encoder===============================================

#==================================Attention=============================================
from lib.attention import BahdanauAttention

attention_layer = BahdanauAttention(10)
attention_result, attention_weights = attention_layer(sample_hidden, sample_output)
Пример #4
0
from lib.helper import Helper
from lib.encoder import Encoder
import sys

if __name__ == "__main__":
    helper = Helper(sys.argv)
    helper.ParseConfig().ShowConfigDescription()

    encoder = Encoder(helper)
    encoder.append_vars(helper.GetConfig("vars"))

    template = helper.LoadFile(helper.GetConfig("template"))
    data = template

    for evasion in helper.GetConfig("evasion"):
        data += helper.LoadFile("templates/evasions/" + evasion + ".vba")

    data = encoder.replace_var(data, "offset", encoder.get_encoding_offset())
    data = encoder.encode_user_vars(data)
    data = encoder.append_def_use_tag(data)
    data = encoder.rand_vars(data)
    data = encoder.rand_int(data)
    data = encoder.rand_smallint(data)

    encodedvars = helper.GetConfig("encodedvars")
    for var in encodedvars:
        data = encoder.replace_var(data, var, encodedvars[var], True)

    if "-s" in sys.argv or "--split_strings" in sys.argv:
        data = encoder.split_strings(data)
    if "-x" in sys.argv or "--strings_to_hex" in sys.argv:
Пример #5
0
	def setUp(self):
		""" """
		self.playerFactory = PlayerFactorySetup.create()
		self.blockTypeFactory = BlockTypeFactorySetup.create()
		self.encoder = Encoder( self.playerFactory, self.blockTypeFactory )
		return None