CS计算机代考程序代写 ant /**

/**
* DO NOT EDIT THIS FILE. When testing your code, we will
* replace this file with our own version!
*/
use bronze_gc::*;

#[derive(Debug)]
pub struct World {
pub spiders: u32,
pub ants: u32,
}

impl World {
pub fn new() -> World {
World {spiders: 0, ants: 0}
}
}

pub trait TurtlePower {
fn activate(&mut self, world: &mut World);
}

impl core::fmt::Debug for dyn TurtlePower {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, “TurtlePower”)
}
}

simple_empty_finalize_trace![dyn TurtlePower];

#[derive(Debug)]
pub struct Wand {
charges: u32,
}

impl Wand {
pub fn new(charges: u32) -> Wand {
Wand { charges }
}
}

impl TurtlePower for Wand {
/**
* If ‘charges’ is positive, should increase the
* number of spiders in the world (turtle food).
* Otherwise, should do nothing.
*/
fn activate(&mut self, world: &mut World) {
if self.charges > 0 {
world.spiders = world.spiders + 1;
self.charges -= 1;
}
}
}

#[derive(Debug)]
pub struct Crystal {}

impl Crystal {
pub fn new() -> Crystal {
Crystal {}
}
}

impl TurtlePower for Crystal {
/**
* Crystals last forever. Activating a crystal makes a new ant
* in the world (turtle food!).
*/
fn activate(&mut self, world: &mut World) {
world.ants = world.ants + 1;
}
}