1 ! Copyright (C) 2006 Alex Chapman
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: kernel arrays namespaces sequences math tetris-colours ;
6 TUPLE: tetromino states colour ;
13 { 0 0 } { 1 0 } { 2 0 } { 3 0 }
24 { 0 1 } { 1 1 } { 2 1 }
30 { 0 0 } { 1 0 } { 2 0 }
44 { { 0 0 } { 1 0 } { 2 0 }
52 { 0 1 } { 1 1 } { 2 1 }
61 { { 0 0 } { 1 0 } { 2 0 }
69 { 0 1 } { 1 1 } { 2 1 }
98 } [ call <tetromino> ] map tetrominoes set-global
100 : random-tetromino ( -- tetromino )
101 tetrominoes get dup length random-int swap nth ;
103 : blocks-max ( blocks quot -- max )
104 ! add 1 to each block since they are 0 indexed
105 ! [ 1+ ] append map 0 [ max ] reduce ;
106 map [ 1+ ] map 0 [ max ] reduce ;
108 : blocks-width ( blocks -- width )
109 [ first ] blocks-max ;
111 : blocks-height ( blocks -- height )
112 [ second ] blocks-max ;