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
Boolwether the game has#changed?since last move -
#down
Returns the
Symbol:downif the move#changed?the state the game -
#empty
Returns an
Array(NamedTuple(x: Int32, y: Int32))of:xand:ypositions -
#insert
Returns the
Int32value inserted at a random#emptyposition -
#left
Returns the
Symbol:leftif the move#changed?the state the game -
#move(direction)
Returns the resulting
Symbolof executeddirectionif successful (e.g. -
#over?
Returns a
Boolwether the game is#over? -
#right
Returns the
Symbol:rightif the move#changed?the state the game -
#score : Int32
Returns an
Int32containing the current score -
#size : Int32
Returns an
Int32containing the size of the currentBoard -
#unchanged?
Returns a
Bool- the inverted of#changed? -
#up
Returns the
Symbol:upif 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