Exemplo n.º 1
0
 def test_220ForMove2(self):
     messageDictionary = {'op':'predict', 'direction':'up','moves':2, 'board': {'columnCount': 3, 'rowCount': 4, 'grid': [4,0,0,2,1,2,3,3,1,1,2,3]}}
     predictDictionary = predict(messageDictionary)
     highScore = predictDictionary['prediction']['highScore']
     lowScore = predictDictionary['prediction']['lowScore']
     avgScore = predictDictionary['prediction']['averageScore']
     self.assertEquals(highScore,8)
     self.assertEquals(lowScore,0)
     self.assertEquals(avgScore,3)
Exemplo n.º 2
0
 def test_210ForMove2(self):
     messageDictionary = {'op':'predict', 'direction':'left','moves':2, 'board': {'columnCount': 4, 'rowCount': 4, 'grid': [0,0,0,1,0,0,0,1,2,2,0,0,1,0,2,2]}}
     predictDictionary = predict(messageDictionary)
     highScore = predictDictionary['prediction']['highScore']
     lowScore = predictDictionary['prediction']['lowScore']
     avgScore = predictDictionary['prediction']['averageScore']
     self.assertEquals(highScore,20)
     self.assertEquals(lowScore,16)
     self.assertEquals(avgScore,19)
Exemplo n.º 3
0
 def test_200ForMove2(self):
     messageDictionary = {'op':'predict', 'direction':'right','moves':2, 'board': {'columnCount': 4, 'rowCount': 4, 'grid': [1,2,3,4,4,3,2,1,3,4,5,6,1,2,0,0]}}
     predictDictionary = predict(messageDictionary)
     highScore = predictDictionary['prediction']['highScore']
     lowScore = predictDictionary['prediction']['lowScore']
     avgScore = predictDictionary['prediction']['averageScore']
     self.assertEquals(highScore,4)
     self.assertEquals(lowScore,0)
     self.assertEquals(avgScore,2)
Exemplo n.º 4
0
def dispatch(messageJson=None):
    """
        dispatch is the microservice dispatcher for IndigoGirls, a 2048-like game.  It routes
        requests for game state transformations to the appropriate functions
        :param
            messageJson: JSON string that describes the state of the game needed for the
                        requested transformation
            :return:    A JSON string that describes the state of the game after the requested transformation
                        has taken place.
    """

    #Validate JSONness of input be converting the string to an equivalent dictionary
    try:

        messageDictionary = json.loads(messageJson)
    except:
        resultDictionary = json.dumps(buildErrorString('input JSON string is invalid'))
        return resultDictionary

    #Validate presence of dispatching code
    if(u"op" not in messageDictionary):
        resultDictionary = json.dumps(buildErrorString('op is missing'))
        return resultDictionary

    #Perform the game transformation as directed by the value of the "op" key
    #  input to each function:  a dictionary containing the name-value pairs of the input JSON string
    #  output of each function:  a dictionary containing name-value pairs to be encoded as a JSON string
    if(messageDictionary[u"op"] == u"initializeGame"):
        resultDictionary =initializeGame(messageDictionary)
    elif (messageDictionary[u"op"] == u"swipe"):
        resultDictionary = swipe(messageDictionary)
    elif (messageDictionary[u"op"] == u"recommend"):
        resultDictionary = recommend(messageDictionary)
    elif (messageDictionary[u"op"] == u"status"):
        resultDictionary = status(messageDictionary)
    elif (messageDictionary[u"op"] == u"predict"):
        resultDictionary = predict(messageDictionary)
    else:
        resultDictionary = buildErrorString('op is invalid')

    #Convert the dictionary back to a string in JSON format
    resultJson = json.dumps(resultDictionary)
    return resultJson
Exemplo n.º 5
0
#from IndigoGirls.swipe import swipe
from IndigoGirls.predict import predict
#from IndigoGirls.status import status

messageDictionary = {
    'op': 'predict',
    'direction': 'Right',
    'moves': 2,
    'board': {
        'columnCount': 4,
        'rowCount': 4,
        'grid': [0, 0, 0, 1, 0, 0, 0, 1, 2, 2, 0, 0, 1, 0, 2, 2]
    }
}
result = predict(messageDictionary)
print result

# messageDictionary = {'op':'status', 'tile': 32, 'board': {'columnCount': 4, 'rowCount': 4, 'grid': [1,2,3,4,4,3,2,1,1,2,3,4,4,3,2,1]}}
# result = status(messageDictionary)
# print result