corewars_sim

Struct Core

Source
pub struct Core { /* private fields */ }
Expand description

The full memory core at a given point in time

Implementations§

Source§

impl Core

Source

pub fn new(core_size: u32) -> Result<Self, Error>

Create a new Core with the given number of possible instructions.

Source

pub fn steps_taken(&self) -> usize

Source

pub fn len(&self) -> u32

Get the number of instructions in the core (available to programs via the CORESIZE label)

Source

pub fn is_empty(&self) -> bool

Whether the core is empty or not (almost always false)

Source

pub fn get(&self, index: i32) -> &Instruction

Get an instruction from a given index in the core

Source

pub fn get_mut(&mut self, index: i32) -> &mut Instruction

Get a mutable instruction from a given index in the core

Source

pub fn load_warrior(&mut self, warrior: &Warrior) -> Result<(), Error>

Load a Warrior into the core starting at the front (first instruction of the core). Returns an error if the Warrior was too long to fit in the core, or had unresolved labels

Source

pub fn step(&mut self) -> Result<(), Error>

Run a single cycle of simulation. This will continue to execute even after MAXCYCLES has been reached

Source

pub fn run<T: Into<Option<usize>>>( &mut self, max_cycles: T, ) -> Result<(), Error>

Run a core to completion. Return value determines whether the core resulted in a tie (Ok) or something cause the warrior to stop executing ([process::Error])

Trait Implementations§

Source§

impl Debug for Core

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Core

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for Core

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Index<Range<usize>> for Core

Source§

type Output = [Instruction]

The returned type after indexing.
Source§

fn index(&self, index: Range<usize>) -> &Self::Output

Performs the indexing (container[index]) operation. Read more

Auto Trait Implementations§

§

impl Freeze for Core

§

impl RefUnwindSafe for Core

§

impl Send for Core

§

impl Sync for Core

§

impl Unpin for Core

§

impl UnwindSafe for Core

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.