# [−][src]Struct coliseum::space::Discrete

`pub struct Discrete(pub u32);`

The Discrete space allows a fixed range of non-negative numbers, so in this case valid actions are either 0 or 1.

# Examples

Discrete contains actions 0..Discrete(N-1)

```use coliseum::space::{Discrete, Space};

let N = 10;
let discrete = Discrete(N);

// what's the idiomatic way to avoid cloning here?
assert!(discrete.clone().sample() < 10);
assert!(!discrete.clone().contains(10));```

We can represent N*2 states for Discrete{N}

```use coliseum::space::{Discrete, Space};
let discrete = Discrete(3);

let sample: (u32, u32, u32) = match discrete.sample() {
0 => (1, 0, 0),
1 => (0, 1, 0),
2 => (0, 0, 1),
_ => panic!("This is out of bounds!")
};

assert_eq!(sample.0 + sample.1 + sample.2, 1)
```

# Examples

```use coliseum::env;
use env::{Environment, State};
use env::rock_paper_scissors::RockPaperScissors;

let mut game = RockPaperScissors::default();
game.reset();

// our player loves rock
let agent = || 1;

loop {
let State { reward, done, .. } = game.step(agent());

if done {
break;
}
}
```

### `impl Space<u32> for Discrete`[src]

#### `fn sample(self) -> u32`[src]

Draws a random item from [0, u32]

#### `fn contains(self, sample: u32) -> bool`[src]

Checks if the sample is part of the set

## Blanket Implementations

### `impl<T> ToOwned for T where    T: Clone, `[src]

#### `type Owned = T`

The resulting type after obtaining ownership.

### `impl<T, U> TryFrom<U> for T where    U: Into<T>, `[src]

#### `type Error = Infallible`

The type returned in the event of a conversion error.

### `impl<T, U> TryInto<U> for T where    U: TryFrom<T>, `[src]

#### `type Error = <U as TryFrom<T>>::Error`

The type returned in the event of a conversion error.