Skip to content

Instantly share code, notes, and snippets.

@harsh-98
Last active May 12, 2022 14:50
Show Gist options
  • Save harsh-98/3d6cedfcecf23d130a449220e95900c7 to your computer and use it in GitHub Desktop.
Save harsh-98/3d6cedfcecf23d130a449220e95900c7 to your computer and use it in GitHub Desktop.
%lang starknet
from starkware.cairo.common.math import (signed_div_rem, sqrt)
from starkware.cairo.common.cairo_builtins import HashBuiltin
const FP = 10 ** 12
const RANGE_CHECK_BOUND = 2 ** 64
const FRICTION = 40 * FP
@event
func increase_balance_called(
current_balance : felt, amount : felt
):
end
@view
func mul_fp {range_check_ptr} (
a : felt,
b : felt
) -> (
c : felt
):
# signed_div_rem by FP after multiplication
#position.emit(aa, bb)
let (c, _) = signed_div_rem(a * b, FP, RANGE_CHECK_BOUND)
return (c)
end
@view
func div_fp {range_check_ptr} (
a : felt,
b : felt
) -> (
c : felt
):
#
# multiply by FP before signed_div_rem
#
let (c, _) = signed_div_rem(a * FP, b, RANGE_CHECK_BOUND)
return (c)
end
@view
func acc {range_check_ptr} (x: felt, y:felt) -> (c: felt):
alloc_locals
tempvar v_2 = x*x+y*y
let (local v) = sqrt (v_2)
let a_mul_vx: felt = mul_fp(FRICTION, -1*x)
let c: felt = div_fp(a_mul_vx, v)
increase_balance_called.emit(x, c)
return (c)
end
@external
func submit_move_for_level {syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr} (
level : felt,
move_x : felt,
move_y : felt
) -> (
is_solution : felt,
is_solution_family_new : felt,
solution_id : felt,
solution_family : felt,
score : felt
):
return (0,0,0,0,0)
end
@harsh-98
Copy link
Author

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment