Ejemplo n.º 1
0
def test_ask_move_invalid_input(monkeypatch):

    pawn_number = StringIO(f"\n")
    monkeypatch.setattr("sys.stdin", pawn_number)
    with pytest.raises(Exception):
        assert action.ask_move(1)

    pawn_number = StringIO("a_string\n")
    monkeypatch.setattr("sys.stdin", pawn_number)
    with pytest.raises(Exception):
        assert action.ask_move(1)

    pawn_number = StringIO(f"-1\n")
    monkeypatch.setattr("sys.stdin", pawn_number)
    with pytest.raises(Exception):
        assert action.ask_move(1)

    pawn_number = StringIO(f"1.3\n")
    monkeypatch.setattr("sys.stdin", pawn_number)
    with pytest.raises(Exception):
        assert action.ask_move(1)

    pawn_number = StringIO(f"4\n")
    monkeypatch.setattr("sys.stdin", pawn_number)
    with pytest.raises(Exception):
        assert action.ask_move(1)
Ejemplo n.º 2
0
def test_ask_move_valid_input(monkeypatch):

    pawn_number = StringIO("0\n")
    monkeypatch.setattr("sys.stdin", pawn_number)
    assert action.ask_move(1) == 0

    pawn_number = StringIO("1\n")
    monkeypatch.setattr("sys.stdin", pawn_number)
    assert action.ask_move(1) == 1

    pawn_number = StringIO("2\n")
    monkeypatch.setattr("sys.stdin", pawn_number)
    assert action.ask_move(1) == 2

    pawn_number = StringIO("3\n")
    monkeypatch.setattr("sys.stdin", pawn_number)
    assert action.ask_move(1) == 3
Ejemplo n.º 3
0
def test_ask_move_invalid_move(monkeypatch):
    with pytest.raises(AssertionError):
        action.ask_move([])

    pawn_number = StringIO(f"a\n")
    monkeypatch.setattr("sys.stdin", pawn_number)
    with pytest.raises(EOFError):
        action.ask_move([Piece(1, 1, 1)])

    pawn_number = StringIO(f"B\n")
    monkeypatch.setattr("sys.stdin", pawn_number)
    with pytest.raises(EOFError):
        action.ask_move([Piece(1, 0, 1)])
Ejemplo n.º 4
0
def play(num_players: int, num_pieces: int, first_player: Player) -> None:
    status = set_board(num_players, num_pieces)

    next = first_player.number
    win = False
    while not win:
        redraw(status)
        dice = roll_dice(next)
        player = Player.get(next)
        valid_moves = get_valid_moves(player, dice, status)
        valid = not valid_moves
        while not valid:
            piece_to_move = ask_move(valid_moves)
            valid = do_move(status, player, piece_to_move, dice)

        win = check_endgame(status)
        if not win and dice != 6:
            next = (next + 1) % num_players

    end_game(status, player)
Ejemplo n.º 5
0
def test_ask_move_valid_input(monkeypatch):

    Player.create()
    pieces = [Piece(0, 0, 1), Piece(0, 1, 1), Piece(0, 2, 1), Piece(0, 3, 1)]

    pawn_number = StringIO("A\n")
    monkeypatch.setattr("sys.stdin", pawn_number)
    assert action.ask_move(pieces) == 0

    pawn_number = StringIO("B\n")
    monkeypatch.setattr("sys.stdin", pawn_number)
    assert action.ask_move(pieces) == 1

    pawn_number = StringIO("C\n")
    monkeypatch.setattr("sys.stdin", pawn_number)
    assert action.ask_move(pieces) == 2

    pawn_number = StringIO("D\n")
    monkeypatch.setattr("sys.stdin", pawn_number)
    assert action.ask_move(pieces) == 3

    pawn_number = StringIO("a\n")
    monkeypatch.setattr("sys.stdin", pawn_number)
    assert action.ask_move(pieces) == 0

    pawn_number = StringIO("b\n")
    monkeypatch.setattr("sys.stdin", pawn_number)
    assert action.ask_move(pieces) == 1

    pawn_number = StringIO("c\n")
    monkeypatch.setattr("sys.stdin", pawn_number)
    assert action.ask_move(pieces) == 2

    pawn_number = StringIO("d\n")
    monkeypatch.setattr("sys.stdin", pawn_number)
    assert action.ask_move(pieces) == 3
Ejemplo n.º 6
0
def test_ask_move_invalid_input(monkeypatch):

    Player.create()
    pieces = [Piece(0, 0, 1), Piece(0, 1, 1), Piece(0, 2, 1), Piece(0, 3, 1)]

    pawn_number = StringIO("\n")
    monkeypatch.setattr("sys.stdin", pawn_number)
    with pytest.raises(EOFError):
        action.ask_move(pieces)

    pawn_number = StringIO("long_string\n")
    monkeypatch.setattr("sys.stdin", pawn_number)
    with pytest.raises(EOFError):
        action.ask_move(pieces)

    pawn_number = StringIO("F\n")
    monkeypatch.setattr("sys.stdin", pawn_number)
    with pytest.raises(EOFError):
        action.ask_move(pieces)

    pawn_number = StringIO("g\n")
    monkeypatch.setattr("sys.stdin", pawn_number)
    with pytest.raises(EOFError):
        action.ask_move(pieces)

    pawn_number = StringIO("0\n")
    monkeypatch.setattr("sys.stdin", pawn_number)
    with pytest.raises(EOFError):
        action.ask_move(pieces)

    pawn_number = StringIO("-1\n")
    monkeypatch.setattr("sys.stdin", pawn_number)
    with pytest.raises(EOFError):
        action.ask_move(pieces)

    pawn_number = StringIO("1.3\n")
    monkeypatch.setattr("sys.stdin", pawn_number)
    with pytest.raises(EOFError):
        action.ask_move(pieces)

    pawn_number = StringIO("4\n")
    monkeypatch.setattr("sys.stdin", pawn_number)
    with pytest.raises(EOFError):
        action.ask_move(pieces)
Ejemplo n.º 7
0
def test_ask_limited_valid_input(monkeypatch):

    Player.create()
    pieces = [Piece(0, 1, 1)]

    pawn_number = StringIO("A\n")
    monkeypatch.setattr("sys.stdin", pawn_number)
    with pytest.raises(EOFError):
        action.ask_move(pieces)

    pawn_number = StringIO("B\n")
    monkeypatch.setattr("sys.stdin", pawn_number)
    assert action.ask_move(pieces) == 1

    pawn_number = StringIO("\n")
    monkeypatch.setattr("sys.stdin", pawn_number)
    assert action.ask_move(pieces) == 1

    pawn_number = StringIO("C\n")
    monkeypatch.setattr("sys.stdin", pawn_number)
    with pytest.raises(EOFError):
        action.ask_move(pieces)

    pawn_number = StringIO("D\n")
    monkeypatch.setattr("sys.stdin", pawn_number)
    with pytest.raises(EOFError):
        action.ask_move(pieces)

    pawn_number = StringIO("a\n")
    monkeypatch.setattr("sys.stdin", pawn_number)
    with pytest.raises(EOFError):
        action.ask_move(pieces)

    pawn_number = StringIO("b\n")
    monkeypatch.setattr("sys.stdin", pawn_number)
    assert action.ask_move(pieces) == 1

    pawn_number = StringIO("c\n")
    monkeypatch.setattr("sys.stdin", pawn_number)
    with pytest.raises(EOFError):
        action.ask_move(pieces)

    pawn_number = StringIO("d\n")
    monkeypatch.setattr("sys.stdin", pawn_number)
    with pytest.raises(EOFError):
        action.ask_move(pieces)