Esempio n. 1
0
def testRegexMatchingSimple3():
    rx_cache.clear()
    config.dictionary = ['abc', 'abcd', 'abcde']
    matches = findAllPossibleWordsForLine('a.c.')
    print matches
    assert len(matches) == 1
    assert matches[0] == 'abcd'
Esempio n. 2
0
def testGridPlacementNoPossibilities():
    rx_cache.clear()
    config.dictionary = ['abcd']
    grid = Grid()
    player = BasicPlayer('test')
    coord = player.placeLetter(grid, 'x')
    
    # the corners do the least 'damage' (still allow 4 letter words on both rows and cols)
    print "coord", coord
    assert coord in [(0,0), (0,4), (4,0), (4,4)]
Esempio n. 3
0
def testChoosesLetterToCompleteWordFromDictionary():
    rx_cache.clear()
    config.dictionary = ['abc']
    grid = Grid()
    player = BasicPlayer('test')
    setWholeGrid(grid, 'z')
    grid.setLetter(0,0,'a', True)
    grid.setLetter(0,1,'b', True)
    grid.setLetter(0,2, config.null_char, True)
    
    letter = player.chooseLetter(grid)
    assert letter == 'c'
Esempio n. 4
0
def testEmptyGridChoosing():
    rx_cache.clear()
    config.dictionary = ['abcde']
    grid = Grid()
    player = BasicPlayer('test')
    letter = player.chooseLetter(grid)
    coord = player.placeLetter(grid, letter)
    
    # least damaging placement is a in top left corner
    print "letter", letter
    assert letter == 'a'
    assert coord == (0,0)
Esempio n. 5
0
def testPlacesLetterToCompleteWordFromDictionary():
    rx_cache.clear()
    config.dictionary = ['abc']
    grid = Grid()
    player = BasicPlayer('test')
    setWholeGrid(grid, 'z')
    grid.setLetter(0,0,'a', True)
    grid.setLetter(0,1,'b', True)
    grid.setLetter(0,2, config.null_char, True)

    coord = player.placeLetter(grid, 'c')
    print "coord", coord
    assert coord == (0,2)
Esempio n. 6
0
def testScoreComparisonForSingleRowForChooseLetter():
    rx_cache.clear()
    config.dictionary = ['abcd']
    grid = Grid()
    player = BasicPlayer('test')
    setWholeGrid(grid, 'z')
    grid.setLetter(0,0,'a', True)
    grid.setLetter(0,1,'b', True)
    grid.setLetter(0,2, config.null_char, True)
    grid.setLetter(0,3, config.null_char, True)

    # player could reasonably pick 'c' or 'd'
    letter = player.chooseLetter(grid)
    print "letter", letter
    assert letter in ['c', 'd']
Esempio n. 7
0
def testScoreComparisonForSingleRow():
    rx_cache.clear()
    config.dictionary = ['abcd']
    grid = Grid()
    player = BasicPlayer('test')
    setWholeGrid(grid, 'z')
    grid.setLetter(0,0,'a', True)
    grid.setLetter(0,1,'b', True)
    grid.setLetter(0,2, config.null_char, True)
    grid.setLetter(0,3, config.null_char, True)

    for i in range(0, 10):
        # 0,2 is clearly the best position to place the letter c
        coord = player.placeLetter(grid, 'c')
        print "coord", coord
        assert coord == (0,2)