-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.rs
65 lines (54 loc) · 1.71 KB
/
lib.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#![no_std]
use soroban_sdk::{contractimpl, contracttype, symbol, vec, BytesN, Env, IntoVal, Map, RawVal};
pub struct Solution;
#[contracttype]
enum Direction {
Up,
DownLeft,
}
#[contractimpl]
impl Solution {
pub fn solve(env: Env, engine_id: BytesN<32>) {
let mut ship: (i32, i32) = (8, 8);
let turn = |dir: &Direction| {
env.invoke_contract::<RawVal>(
&engine_id,
&symbol!("p_turn"),
vec![&env, dir.into_val(&env)],
);
};
let go = |amount: u32| {
env.invoke_contract::<RawVal>(
&engine_id,
&symbol!("p_move"),
vec![&env, RawVal::from_u32(amount)],
);
};
let shoot = || {
env.invoke_contract::<RawVal>(&engine_id, &symbol!("p_shoot"), vec![&env]);
};
let harvest = || {
env.invoke_contract::<RawVal>(&engine_id, &symbol!("p_harvest"), vec![&env]);
};
let map = || -> Map<(i32, i32), RawVal> {
env.invoke_contract(&engine_id, &symbol!("get_map"), vec![&env])
};
while ship.0 != -562 {
for p in 0..16 {
// if something is above the spaceship, move there and
// shoot and harvest without checking out what it is
if map().contains_key((ship.0, ship.1 + p)) {
turn(&Direction::Up);
go(p as u32);
shoot();
harvest();
ship.1 += p;
}
}
turn(&Direction::DownLeft);
go(1);
ship = (ship.0 - 1, ship.1 - 1);
}
}
}
mod test;