module TicTacToe
Constants
- VERSION
Public Class Methods
move(square, saved_board=nil)
click to toggle source
# File lib/tic_tac_toe_mchliakh.rb, line 10 def self.move(square, saved_board=nil) square = square.to_i saved_board.map! {|s| s.to_i if s } if saved_board board = Board.new(saved_board) board.square(square).take(1) if board.game_over? return { board: board.serialize, winner: board.winner } end computer = Computer.new(board, 0) computer.next_move.take(0) if board.game_over? { board: board.serialize, winner: board.winner } else { board: board.serialize } end rescue IllegalMoveError => e { error: e.message } end