class Board

Defined in:

board.cr

Constant Summary

CELL_INDEXES = 0..(NUMBER_OF_CELLS_IN_BOARD - 1)
EMPTY_CELL = 0
ENCODED_STATE_RADIX = 3
NUMBER_OF_CELLS_IN_BOARD = NUMBER_OF_CELLS_PER_ROW ** 2
NUMBER_OF_CELLS_PER_ROW = 3
PLAYERS = [1, 2]
WINS = [[0, 1, 2], [3, 4, 5], [6, 7, 8], [0, 3, 6], [1, 4, 7], [2, 5, 8], [0, 4, 8], [2, 4, 6]]

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(board : Nil | Array(Int32) = nil) #

[View source]

Class Method Detail

def self.from_state(state) #

state is a transformation of each of the boards cells to digits in a base-3 number


[View source]
def self.other_player(player) #

[View source]

Instance Method Detail

def ==(other) #
Description copied from class Reference

Returns false (other can only be a Value here).


[View source]
def apply_move(move, as_player) #

Player here is a number, 1 or # 2 indicating 1st or 2nd


[View source]
def game_over? #

[View source]
def is_win_for?(player) #

[View source]
def move_options #

[View source]
def next_time_could_be_win_for?(player) #

[View source]
def next_time_is_game_over? #

[View source]
def next_time_is_win_for?(player) #

[View source]
def no_moves_left? #

[View source]
def to_a : Array(Int32) #

[View source]
def to_s(tokens = PLAYERS.map do |p| p.to_s end.reduce do |p1, p2| p1 + p2 end) #
Description copied from class Object

Returns a nicely readable and concise string representation of this object, typically intended for users.

This method should usually not be overridden. It delegates to #to_s(IO) which can be overridden for custom implementations.

Also see #inspect.


[View source]
def to_state #

state is a transformation of each of the boards cells to digits in a base-3 number


[View source]
def winner #

[View source]