MCPcopy Create free account
hub / github.com/battlecode/battlecode-2018 / test_worker_harvest

Function test_worker_harvest

battlecode-engine/src/world.rs:3084–3117  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3082
3083 #[test]
3084 fn test_worker_harvest() {
3085 // Create the game world, which by default has 10 karbonite everywhere.
3086 let mut world = GameWorld::test_world();
3087
3088 // Select a deposit, and test that it can be mined out as expected.
3089 let deposit = MapLocation::new(Planet::Earth, 0, 0);
3090 let expected_karbonite = [10, 7, 4, 1, 0];
3091 let expected_team_karbonite = [100, 103, 106, 109, 110];
3092 for i in 0..4 {
3093 let worker = world.create_unit(Team::Red, deposit.add(Direction::North),
3094 UnitType::Worker).unwrap();
3095 assert![world.can_harvest(worker, Direction::South)];
3096 assert_eq![world.karbonite_at(deposit).unwrap(), expected_karbonite[i]];
3097 assert_eq![world.karbonite(), expected_team_karbonite[i]];
3098 assert![world.harvest(worker, Direction::South).is_ok()];
3099 // The robot can no longer harvest, as it has already done so.
3100 assert![!world.can_harvest(worker, Direction::South)];
3101 assert_eq![world.karbonite_at(deposit).unwrap(), expected_karbonite[i+1]];
3102 assert_eq![world.karbonite(), expected_team_karbonite[i+1]];
3103 world.destroy_unit(worker);
3104 }
3105
3106 // The deposit has been mined out, so it cannot be harvested.
3107 let worker = world.create_unit(Team::Red, deposit.add(Direction::North),
3108 UnitType::Worker).unwrap();
3109 assert![!world.can_harvest(worker, Direction::South)];
3110
3111 // Other deposits can still be harvested, including in the robot's own space.
3112 assert![world.can_harvest(worker, Direction::Center)];
3113
3114 // Deposits off the edge of the map can obviously not be harvested, but checking
3115 // this should not error.
3116 assert![!world.can_harvest(worker, Direction::West)];
3117 }
3118
3119 #[test]
3120 fn test_worker_blueprint_and_build() {

Callers

nothing calls this directly

Calls 3

create_unitMethod · 0.80
destroy_unitMethod · 0.80
addMethod · 0.45

Tested by

no test coverage detected