예제 #1
0
def test_losing():
    """test losing states"""

    losing_state = list('XXOO.....')

    for i in range(10):
        random.shuffle(losing_state)
        assert find_winner(''.join(losing_state)) == None
예제 #2
0
def test_losing():
    """test losing boards"""

    losing_board = list('XXOO.....')

    for _ in range(10):
        random.shuffle(losing_board)
        assert find_winner(''.join(losing_board)) is None
예제 #3
0
def test_winning():
    """test winning states"""

    wins = [('PPP......'), ('...PPP...'), ('......PPP'), ('P..P..P..'),
            ('.P..P..P.'), ('..P..P..P'), ('P...P...P'), ('..P.P.P..')]

    for player in 'XO':
        other_player = 'O' if player == 'X' else 'X'

        for state in wins:
            state = state.replace('P', player)
            dots = [i for i in range(len(state)) if state[i] == '.']
            mut = random.sample(dots, k=2)
            test_state = ''.join([
                other_player if i in mut else state[i]
                for i in range(len(state))
            ])
            assert find_winner(test_state) == player
예제 #4
0
def test_winning():
    """test winning boards"""

    wins = [('PPP......'), ('...PPP...'), ('......PPP'), ('P..P..P..'),
            ('.P..P..P.'), ('..P..P..P'), ('P...P...P'), ('..P.P.P..')]

    for player in 'XO':
        other_player = 'O' if player == 'X' else 'X'

        for board in wins:
            board = board.replace('P', player)
            dots = [i for i in range(len(board)) if board[i] == '.']
            mut = random.sample(dots, k=2)
            test_board = ''.join([
                other_player if i in mut else board[i]
                for i in range(len(board))
            ])
            assert find_winner(test_board) == player
예제 #5
0
    '''check if the move is valid and add to the history'''
    if tictactoe.make_move(Board, move, Players[turn % 2]):
       # print ("drop piece")
        Tries = 0
        History.append(move)
        
    '''if players makes more than 3 invalid moves, the game is stuck'''
    if Tries > 3:
        print ('Player {} is stuck!'.format((turn % 2) + 1))
        break

    
    '''prints the updated board'''
    tictactoe.print_board(Board)
    print()
    print()

    '''check for winner after the move'''
    Winner = tictactoe.find_winner(Board)
    
    '''checks for a draw board'''
    Draw = tictactoe.check_full_board(Board)
    #print (Winner)
 
if Winner:
    print ('The Winner is {}'.format(tictactoe.PIECE_COLOR_MAP[Winner]))
elif Draw:
    print('It is a draw')

writeToFile()