Skip to content

Commit

Permalink
apply feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
scarmuega committed Mar 12, 2024
1 parent 98ca5aa commit 5e6f086
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
4 changes: 2 additions & 2 deletions plutus.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
}
}
],
"compiledCode": "59035c010000323232323232323232232232232222323232533300f32323232323232323232323232323232323232323253330243370e9001181180309919191919299981499b8748000c0a00044c8c8c8c8c94ccc0b8cdc3a4000605a00226464646464646464a66606c66e1d2004303500113232323232533303b533303b533303b533303b00b100914a020102940400852808008a503371e6eb8c050c0e000c0994ccc0e4cdc39bad300e303700233700046052266e1cdd69802981b80119b8002102714a06058002607800260680022c6002606600c460746076607600266e24cdc101580100c99b8900102c3233700600204460020404a66606466e2000520001337029000000880099b873330043756600a605c600a605c00c0580389001181a00098160008b19803005119b873330023756600660580020540349001111191919299981919b8748008004520001375a606e6060004606000264a66606266e1d200200114c0103d87a8000132323300100100222533303700114c103d87a800013232323253330383371e014004266e9520003303c375000297ae0133006006003375a60720066eb8c0dc008c0ec008c0e4004dd5981b18178011817800991980080080211299981a0008a6103d87a800013232323253330353371e010004266e95200033039374c00297ae01330060060033756606c0066eb8c0d0008c0e0008c0d80048c0c4c0c8004c0bc004c09c00458cc0040208cdd7980198138008021119198008008019129998170008a6103d87a800013232533302d300500213374a90001981880125eb804cc010010004c0c8008c0c00048c0b0004c0a8004c08801858dd61814000981400098138011bac3025001301d0033023001302300230210013019010375a603e002603e0046eb4c074004c074008dd6980d800980d8011bae3019001301100a375a602e002602e0046eb4c054004c0340145261365632533300f3370e9000000899191919299980b180c8010a4c2c6eb4c05c004c05c008dd6980a80098068028b18068021800802119299980719b87480000044c8c8c8c8c8c8c8c94ccc064c07000852616375a603400260340046eb4c060004c060008dd6980b000980b0011bae3014001300c00216300c001375a0026eb4004dd7000918029baa001230033754002ae6955ceaab9e5573eae815d0aba21",
"hash": "4169f9c7110ee486b5e1872d123b10aa4924f38c8a47291b5d8e3422"
"compiledCode": "59035e010000323232323232323232232232232222323232533300f32323232323232323232323232323232323232323253330243370e9001181180309919191919299981499b8748000c0a00044c8c8c8c8c94ccc0b8cdc3a4000605a0022646464646464646464a66606e66e1d2004303600113232323232533303c00c1533303c0091533303c0081533303c002100114a029405280a503371e6eb8c054c0e400c09d4ccc0e8cdc39bad300f303800233700048054266e1cdd69802981c00119b8002202814a0605a002607a002606a0022c6002606800e460766078607800266e24008068cdc480101699b8200102a3233700600204460020404a66606466e2000520001337029000000880099b873330043756600a605c600a605c00c0580389001181a00098160008b19803005119b873330023756600660580020540349001111191919299981919b8748008004520001375a606e6060004606000264a66606266e1d200200114c103d87a8000132323300100100222533303700114c103d87a800013232323253330383371e014004266e9520003303c375000297ae0133006006003375a60720066eb8c0dc008c0ec008c0e4004dd5981b18178011817800991980080080211299981a0008a6103d87a800013232323253330353371e010004266e95200033039374c00297ae01330060060033756606c0066eb8c0d0008c0e0008c0d80048c0c4c0c8004c0bc004c09c00458cc0040208cdd7980198138008021119198008008019129998170008a6103d87a800013232533302d300500213374a90001981880125eb804cc010010004c0c8008c0c00048c0b0004c0a8004c08801858dd61814000981400098138011bac3025001301d0033023001302300230210013019010375a603e002603e0046eb4c074004c074008dd6980d800980d8011bae3019001301100a375a602e002602e0046eb4c054004c0340145261365632533300f3370e9000000899191919299980b180c8010a4c2c6eb4c05c004c05c008dd6980a80098068028b18068021800802119299980719b87480000044c8c8c8c8c8c8c8c94ccc064c07000852616375a603400260340046eb4c060004c060008dd6980b000980b0011bae3014001300c00216300c001375a0026eb4004dd7000918029baa001230033754002ae6955ceaab9e5573eae815d0aba21",
"hash": "24dc592d83d2a81ee4e3981d3cb09f6141ef08f974e617a251745f97"
}
],
"definitions": {
Expand Down
23 changes: 19 additions & 4 deletions validators/spacetime.ak
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,25 @@ use aiken/transaction.{InlineDatum, ScriptContext, Spend, Transaction}
use aiken/transaction/value.{PolicyId, quantity_of}

type Datum {
ship_id: ByteArray,
pilot_token: ByteArray,
pos_x: Int,
pos_y: Int,
fuel: Int,
}

type Redeemer {
type MoveRedeemer {
delta_x: Int,
delta_y: Int,
}

type GatherRedeemer {GatherRedeemer}

type PotRedeemer {PotRedeemer}

fn required_fuel(distance: Int, fuel_per_step: Int) -> Int {
distance * fuel_per_step
}

fn distance(delta_x: Int, delta_y: Int) -> Int {
math.abs(delta_x) + math.abs(delta_y)
}
Expand Down Expand Up @@ -51,11 +59,12 @@ validator(ship_policy_id: PolicyId, max_speed: Int, fuel_per_step: Int) {
quantity_of(own_input.output.value, ship_policy_id, ship_id) == 1

let distance = distance(delta_x, delta_y)
let required_fuel = required_fuel(distance, fuel_per_step)

// speed = distance since we consider each block the unit of time
let must_respect_max_speed = distance <= max_speed

let must_have_enough_fuel = fuel >= fuel_per_step * distance
let must_have_enough_fuel = fuel >= required_fuel

expect InlineDatum(out_data) = own_output.datum

Expand All @@ -66,6 +75,12 @@ validator(ship_policy_id: PolicyId, max_speed: Int, fuel_per_step: Int) {

let final_ship_id_must_match = out_data.ship_id == ship_id

must_hold_ship_asset && must_respect_max_speed && must_have_enough_fuel && final_pos_must_respect_movement && final_ship_id_must_match
and {
must_hold_ship_asset,
must_respect_max_speed,
must_have_enough_fuel,
final_pos_must_respect_movement,
final_ship_id_must_match,
}
}
}

0 comments on commit 5e6f086

Please sign in to comment.