|
|
|
@ -143,70 +143,49 @@
|
|
|
|
|
(func $getScore (param $theirs i32) (param $ours i32) (result i32)
|
|
|
|
|
(local $diff i32)
|
|
|
|
|
|
|
|
|
|
;; get diff value
|
|
|
|
|
local.get $theirs
|
|
|
|
|
;; some modulo math to get ours - theirs (with wraparound)
|
|
|
|
|
local.get $ours
|
|
|
|
|
i32.const 3
|
|
|
|
|
i32.add
|
|
|
|
|
local.get $theirs
|
|
|
|
|
i32.sub
|
|
|
|
|
i32.const 3
|
|
|
|
|
i32.rem_s
|
|
|
|
|
local.set $diff
|
|
|
|
|
|
|
|
|
|
block $conditions
|
|
|
|
|
;; if it's a draw
|
|
|
|
|
block $checks
|
|
|
|
|
local.get $diff
|
|
|
|
|
i32.eqz
|
|
|
|
|
if
|
|
|
|
|
i32.const 3 ;; 3 points for draw
|
|
|
|
|
local.get $ours ;; points for what you played
|
|
|
|
|
i32.add
|
|
|
|
|
i32.eqz;; if we tied
|
|
|
|
|
if
|
|
|
|
|
i32.const 3
|
|
|
|
|
local.set $diff
|
|
|
|
|
br $conditions
|
|
|
|
|
br $checks
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
;; check which is greater
|
|
|
|
|
;; if we won
|
|
|
|
|
local.get $diff
|
|
|
|
|
i32.const 0
|
|
|
|
|
i32.lt_s
|
|
|
|
|
if ;; diff is negative, ours is bigger than theirs
|
|
|
|
|
|
|
|
|
|
local.get $diff
|
|
|
|
|
i32.const -2
|
|
|
|
|
i32.eq
|
|
|
|
|
if ;; if the diff is two, we did scissors (3), they did rock (1); they win
|
|
|
|
|
local.get $ours
|
|
|
|
|
local.set $diff
|
|
|
|
|
br $conditions
|
|
|
|
|
else ;; diff of one, we won (scissors beats paper, paper beats rock)
|
|
|
|
|
i32.const 6
|
|
|
|
|
local.get $ours
|
|
|
|
|
i32.add
|
|
|
|
|
local.set $diff
|
|
|
|
|
br $conditions
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
else ;; diff is positive, theirs is bigger than ours
|
|
|
|
|
|
|
|
|
|
local.get $diff
|
|
|
|
|
i32.const 2
|
|
|
|
|
i32.eq
|
|
|
|
|
if ;; if the diff is two, we did rock (1), they did scissors (3), we win
|
|
|
|
|
i32.const 6
|
|
|
|
|
local.get $ours
|
|
|
|
|
i32.add
|
|
|
|
|
local.set $diff
|
|
|
|
|
br $conditions
|
|
|
|
|
else ;; diff of one, they won
|
|
|
|
|
local.get $ours
|
|
|
|
|
local.set $diff
|
|
|
|
|
br $conditions
|
|
|
|
|
end
|
|
|
|
|
i32.const 1
|
|
|
|
|
i32.eq
|
|
|
|
|
if
|
|
|
|
|
i32.const 6
|
|
|
|
|
local.set $diff
|
|
|
|
|
br $checks
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
(; local.get $theirs ;)
|
|
|
|
|
(; local.get $ours ;)
|
|
|
|
|
(; local.get $diff ;)
|
|
|
|
|
(; call $log3 ;)
|
|
|
|
|
;; if we lost
|
|
|
|
|
local.get $diff
|
|
|
|
|
i32.const 2
|
|
|
|
|
i32.eq
|
|
|
|
|
if
|
|
|
|
|
i32.const 0
|
|
|
|
|
local.set $diff
|
|
|
|
|
br $checks
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local.get $diff
|
|
|
|
|
local.get $ours
|
|
|
|
|
i32.add
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
(func $readLine (result i32 i32)
|
|
|
|
|