struct TwentyFortyEight::Game
- TwentyFortyEight::Game
- Struct
- Value
- Object
Overview
The Game
struct does all the heavy lifting, a new game with a default size of 4
will be initialized,
then two pieces will be inserted in random a #empty
position
Defined in:
twenty_forty_eight/game.crConstructors
Instance Method Summary
-
#board : Array(Array(Int32))
Returns the current state of the games'
Board
-
#changed? : Bool
Returns a
Bool
wether the game has#changed?
since last move -
#down
Returns the
Symbol
:down
if the move#changed?
the state the game -
#empty
Returns an
Array(NamedTuple(x: Int32, y: Int32))
of:x
and:y
positions -
#insert
Returns the
Int32
value inserted at a random#empty
position -
#left
Returns the
Symbol
:left
if the move#changed?
the state the game -
#move(direction)
Returns the resulting
Symbol
of executeddirection
if successful (e.g. -
#over?
Returns a
Bool
wether the game is#over?
-
#right
Returns the
Symbol
:right
if the move#changed?
the state the game -
#score : Int32
Returns an
Int32
containing the current score -
#size : Int32
Returns an
Int32
containing the size of the currentBoard
-
#unchanged?
Returns a
Bool
- the inverted of#changed?
-
#up
Returns the
Symbol
:up
if the move#changed?
the state of the game
Constructor Detail
Returns a Game
starting with specified @board
of type Array(Array(Int32))
, no values will be inserted
and #size
will be set to @board.size
Instance Method Detail
Returns an Array(NamedTuple(x: Int32, y: Int32))
of :x
and :y
positions
Running the following example:
puts TwentyFortyEight::Game.new.empty.sample[:x]
Will output:
2