コード例 #1
0
ファイル: test.py プロジェクト: raphapassini/py-tictactoe
    def test_winner_by_2nd_diagonal(self):
        """Player1 should win wen complete the 2nd diagonal"""
        self.board = ttt.make_move('0,2', self.board, self.p1)
        self.board = ttt.make_move('1,1', self.board, self.p1)
        self.board = ttt.make_move('2,0', self.board, self.p1)

        ttt.print_board(self.board)
        self.assertEqual(ttt.status(self.board, [self.p1, self.p2]), '#')
コード例 #2
0
ファイル: test.py プロジェクト: raphapassini/py-tictactoe
    def test_winner_by_col(self):
        """Player1 should win wen complete a col"""
        self.board = ttt.make_move('0,0', self.board, self.p1)
        self.board = ttt.make_move('1,0', self.board, self.p1)
        self.board = ttt.make_move('2,0', self.board, self.p1)

        ttt.print_board(self.board)
        self.assertEqual(ttt.status(self.board, [self.p1, self.p2]), '#')
コード例 #3
0
ファイル: test.py プロジェクト: raphapassini/py-tictactoe
    def test_should_be_no_moves_at_the_end(self):
        """Should be no moves at the end of the game"""

        #player1 moves
        self.board = ttt.make_move('0,0', self.board, self.p1)
        self.board = ttt.make_move('0,2', self.board, self.p1)
        self.board = ttt.make_move('1,1', self.board, self.p1)
        self.board = ttt.make_move('1,2', self.board, self.p1)
        self.board = ttt.make_move('2,1', self.board, self.p1)

        #player2 moves
        self.board = ttt.make_move('0,1', self.board, self.p2)
        self.board = ttt.make_move('1,0', self.board, self.p2)
        self.board = ttt.make_move('2,0', self.board, self.p2)
        self.board = ttt.make_move('2,2', self.board, self.p2)

        self.assertEqual(ttt.moves_left(self.board), 0)
コード例 #4
0
ファイル: test.py プロジェクト: raphapassini/py-tictactoe
    def test_status_tie_game(self):
        """Should be no winner in a tie game"""

        #player1 moves
        self.board = ttt.make_move('0,0', self.board, self.p1)
        self.board = ttt.make_move('0,2', self.board, self.p1)
        self.board = ttt.make_move('1,1', self.board, self.p1)
        self.board = ttt.make_move('1,2', self.board, self.p1)
        self.board = ttt.make_move('2,1', self.board, self.p1)

        #player2 moves
        self.board = ttt.make_move('0,1', self.board, self.p2)
        self.board = ttt.make_move('1,0', self.board, self.p2)
        self.board = ttt.make_move('2,0', self.board, self.p2)
        self.board = ttt.make_move('2,2', self.board, self.p2)

        ttt.print_board(self.board)
        self.assertFalse(ttt.status(self.board, [self.p1, self.p2]))
コード例 #5
0
def new_winnable_board():
    player = 1
    board = create_board()
    status = ''
    while True:
        if status == 'win':
            if player == 1:
                break
            else:
                board = create_board()
        if not True in [0 in i for i in board]:
            board = create_board()
        move = random.randrange(0, 10)
        [status, player, board] = make_move(move, player, board)
    y = int(move / 3)
    x = move % 3
    board[y][x] = 0
    return [board, move]
コード例 #6
0
ファイル: test.py プロジェクト: raphapassini/py-tictactoe
 def test_can_make_move(self):
     """Can make a move"""
     self.board = ttt.make_move('0,0', self.board, self.p1)
     self.assertEqual(self.board[0][0], self.p1)
コード例 #7
0
ファイル: test.py プロジェクト: raphapassini/py-tictactoe
 def test_move_already_done(self):
     """Cant do a move already done"""
     self.board = ttt.make_move('0,0', self.board, self.p1)
     self.assertFalse(ttt.move_allowed('0,0', self.board))