def FindBestMove(self, hand, board): #Return word, anchor, anchorindex, direction #Get words for each anchor, find best word, compare best words sequentially anchors = board.GetAnchors() random.shuffle(anchors) bestWord = Word() bestWord.SetScore(min) for anchor in anchors: # get list of possible words for each anchor # match words to hand words = self.MatchWords(hand, anchor, board) # check for case no legal move is found if words is not None : # set scores for words, find best word for word in words.keys(): word.SetScore(self.heuristic.ScoreWord(word, hand)) if word.GetScore() > bestWord.GetScore() : bestWord = word bestAnchor = anchor bestIndex = words[word][0] bestDirection = words[word][1] # check for case no legal move is found if bestWord.GetScore() is min: raise Exception("BRI: No valid word options found!") return bestWord, bestAnchor, bestIndex, bestDirection
def test_Constructor_CallWithDefaultParameters_WordSetCorrectly(self): # Arrange expectedTiles = None expectedString = '' expectedScore = 0 expectedPrime = 1 # Act testWord = Word() actualTiles = testWord.GetTiles() actualString = testWord.GetString() actualScore = testWord.GetScore() actualPrime = testWord.GetPrime() # Assert self.assertEqual(expectedTiles, actualTiles) self.assertEqual(expectedString, actualString) self.assertEqual(expectedScore, actualScore) self.assertEqual(expectedPrime, actualPrime)
def test_Constructor_CallWithTiles_WordSetCorrectly(self): # Arrange c = Tile('C', 3, 0.04049934678472928, 29) a = Tile('A', 1, 0.07633656680151722, 7) t = Tile('T', 1, 0.06566549066880407, 17) expectedTiles = [c, a, t] expectedString = 'CAT' expectedScore = 5 expectedPrime = 29 * 7 * 17 # Act testWord = Word(expectedTiles) actualTiles = testWord.GetTiles() actualString = testWord.GetString() actualScore = testWord.GetScore() actualPrime = testWord.GetPrime() # Assert self.assertEqual(expectedTiles, actualTiles) self.assertEqual(expectedString, actualString) self.assertEqual(expectedScore, actualScore) self.assertEqual(expectedPrime, actualPrime)