Paste: Sequence index out of bounds

Author: Ilyak
Mode: factor
Date: Sat, 15 Aug 2009 13:22:57
Plain Text |
! Copyright (C) 2006, 2007, 2008 Alex Chapman
! See http://factorcode.org/license.txt for BSD license.
USING: kernel arrays namespaces sequences math math.order
math.vectors colors colors.constants random accessors ;
IN: tetcolor.tetromino

TUPLE: tetromino states colours ;

C: <tetromino> tetromino

SYMBOL: tetrominoes

{
  [
    { {
        { 0 0 } { 1 0 } { 2 0 } { 3 0 }
      }
      { { 0 0 }
        { 0 1 }
        { 0 2 }
        { 0 3 }
      }
    }
  ] [
    {
      {         { 1 0 }
        { 0 1 } { 1 1 } { 2 1 }
      } {
        { 0 0 }
        { 0 1 } { 1 1 }
        { 0 2 }
      } {
        { 0 0 } { 1 0 } { 2 0 }
                { 1 1 }
      } {
                { 1 0 }
        { 0 1 } { 1 1 }
                { 1 2 }
      }
    }
  ] [
    { { { 0 0 } { 1 0 }
        { 0 1 } { 1 1 } }
    }
  ] [
    {
      { { 0 0 } { 1 0 } { 2 0 }
        { 0 1 }
      } {
        { 0 0 } { 1 0 }
                { 1 1 }
                { 1 2 }
      } {
                        { 2 0 }
        { 0 1 } { 1 1 } { 2 1 }
      } {
        { 0 0 }
        { 0 1 }
        { 0 2 } { 1 2 }
      }
    }
  ] [
    {
      { { 0 0 } { 1 0 } { 2 0 }
                        { 2 1 }
      } {
                { 1 0 }
                { 1 1 }
        { 0 2 } { 1 2 }
      } {
        { 0 0 }
        { 0 1 } { 1 1 } { 2 1 }
      } {
        { 0 0 } { 1 0 }
        { 0 1 }
        { 0 2 }
      }
    }
  ] [
    {
      {          { 1 0 } { 2 0 }
        { 0 1 } { 1 1 }
      } {
        { 0 0 }
        { 0 1 } { 1 1 }
                { 1 2 }
      }
    }
  ] [
    {
      {
        { 0 0 } { 1 0 }
                { 1 1 } { 2 1 }
      } {
                { 1 0 }
        { 0 1 } { 1 1 }
        { 0 2 }
      }
    }
  ]
} [ { } first <tetromino> ] map tetrominoes set-global

: paint-tetromino ( tetromino -- tetromino )
    4 [ {
  COLOR: red
  COLOR: green
  COLOR: blue
  COLOR: yellow
  COLOR: cyan
  COLOR: magenta
    } random ] replicate >>colours ;

: random-tetromino ( -- tetromino )
    tetrominoes get random paint-tetromino ;

: blocks-max ( blocks quot -- max )
    map [ 1 + ] [ max ] map-reduce ; inline

: blocks-width ( blocks -- width )
    [ first ] blocks-max ;

: blocks-height ( blocks -- height )
    [ second ] blocks-max ;

Annotation: The same thing

Author: Ilyak
Mode: factor
Date: Sat, 15 Aug 2009 13:32:41
Plain Text |
! Copyright (C) 2006, 2007, 2008 Alex Chapman
! See http://factorcode.org/license.txt for BSD license.
USING: kernel arrays namespaces sequences math math.order
math.vectors colors colors.constants random accessors ;
IN: tetcolor.tetromino

TUPLE: tetromino colours states ;

: <tetromino> ( array -- tetromino )
    { } tetromino boa ;

SYMBOL: tetrominoes

{
  [
    { {
        { 0 0 } { 1 0 } { 2 0 } { 3 0 }
      }
      { { 0 0 }
        { 0 1 }
        { 0 2 }
        { 0 3 }
      }
    }
  ] [
    {
      {         { 1 0 }
        { 0 1 } { 1 1 } { 2 1 }
      } {
        { 0 0 }
        { 0 1 } { 1 1 }
        { 0 2 }
      } {
        { 0 0 } { 1 0 } { 2 0 }
                { 1 1 }
      } {
                { 1 0 }
        { 0 1 } { 1 1 }
                { 1 2 }
      }
    }
  ] [
    { { { 0 0 } { 1 0 }
        { 0 1 } { 1 1 } }
    }
  ] [
    {
      { { 0 0 } { 1 0 } { 2 0 }
        { 0 1 }
      } {
        { 0 0 } { 1 0 }
                { 1 1 }
                { 1 2 }
      } {
                        { 2 0 }
        { 0 1 } { 1 1 } { 2 1 }
      } {
        { 0 0 }
        { 0 1 }
        { 0 2 } { 1 2 }
      }
    }
  ] [
    {
      { { 0 0 } { 1 0 } { 2 0 }
                        { 2 1 }
      } {
                { 1 0 }
                { 1 1 }
        { 0 2 } { 1 2 }
      } {
        { 0 0 }
        { 0 1 } { 1 1 } { 2 1 }
      } {
        { 0 0 } { 1 0 }
        { 0 1 }
        { 0 2 }
      }
    }
  ] [
    {
      {          { 1 0 } { 2 0 }
        { 0 1 } { 1 1 }
      } {
        { 0 0 }
        { 0 1 } { 1 1 }
                { 1 2 }
      }
    }
  ] [
    {
      {
        { 0 0 } { 1 0 }
                { 1 1 } { 2 1 }
      } {
                { 1 0 }
        { 0 1 } { 1 1 }
        { 0 2 }
      }
    }
  ]
} [ first <tetromino> ] map tetrominoes set-global

: paint-tetromino ( tetromino -- tetromino )
    4 [ {
  COLOR: red
  COLOR: green
  COLOR: blue
  COLOR: yellow
  COLOR: cyan
  COLOR: magenta
    } random ] replicate >>colours ;

: random-tetromino ( -- tetromino )
    tetrominoes get random paint-tetromino ;

: blocks-max ( blocks quot -- max )
    map [ 1 + ] [ max ] map-reduce ; inline

: blocks-width ( blocks -- width )
    [ first ] blocks-max ;

: blocks-height ( blocks -- height )
    [ second ] blocks-max ;

New Annotation

Summary:
Author:
Mode:
Body: