programgames/2048/2048.xtl

source · imports t: games/2048/Twenty48.xtl

b : Int

value · line 8
b ← 4 4 r̲eshape 2 2 2 2 0 2 0 2 4 4 8 8 2 0 0 4

ᵘp̲ick : (Num a, Truthy a, Num b) => a -> b

function · line 22

A whole game by a simple corner player: left, then down, then right, then up, the first of them that moves anything.

ᵘp̲ick ← { s →
  ok ← '{ n̲ot (s ᵗm̲ove ⍵) m̲atch s } e̲ach 1 4 2 3
  f̲irst (ok r̲eplicate 1 4 2 3) c̲at 1
}
Used in: ᵘg̲ame

ᵘg̲ame : (Num a, Truthy a) => a -> a

function · line 26
ᵘg̲ame ← { s →
  0 < ᵗs̲tatus s ? s
  ᵘg̲ame s ᵗm̲ove ᵘp̲ick s
}
Used in: ᵘg̲ame, end

end : Int

value · line 30
end ← ᵘg̲ame ᵗn̲ew 0

ok : Unit

value · line 38
ok ← "('+ r_/ r_avel b) = '+ r_/ r_avel b t:s_lide 2" a̲ssert< "a slide keeps the tiles' total"
a̲ssert< expands to
({ @ → (('+ r̲/ r̲avel b) = '+ r̲/ r̲avel b ᵗs̲lide 2) ? @◆ ⎕E̲RR "assertion failed: ('+ r_/ r_avel b) = '+ r_/ r_avel b t:s_lide 2 (a slide keeps the tiles' total) [games/2048/2048.xtl:38]"◆ @ } @)

ok : Unit

value · line 39
ok ← "2 = t:s_tatus end" a̲ssert< "the game ends with no move left"
a̲ssert< expands to
({ @ → (2 = ᵗs̲tatus end) ? @◆ ⎕E̲RR "assertion failed: 2 = t:s_tatus end (the game ends with no move left) [games/2048/2048.xtl:39]"◆ @ } @)