-- Compiled with roblox-ts v1.2.7 --[[ * * A output handler that converts the game into a string grid. * This is mainly for example purposes of use cases for an output handler. ]] local TicTacToeStringOutput do TicTacToeStringOutput = setmetatable({}, { __tostring = function() return "TicTacToeStringOutput" end, }) TicTacToeStringOutput.__index = TicTacToeStringOutput function TicTacToeStringOutput.new(...) local self = setmetatable({}, TicTacToeStringOutput) return self:constructor(...) or self end function TicTacToeStringOutput:constructor(sep, channel) if sep == nil then sep = "#" end self.sep = sep self.channel = channel end function TicTacToeStringOutput:onMove(tttGame) self:output(tttGame) end function TicTacToeStringOutput:onGameOver(tttGame) self:output(tttGame) end function TicTacToeStringOutput:onGameStart(tttGame) self:output(tttGame) end function TicTacToeStringOutput:output(tttGame) self.channel(table.concat(self:constructBoardLines(tttGame:getBoard()), "\n")) end function TicTacToeStringOutput:constructBoardLines(board) local lines = { string.rep(self.sep, 13) } do local row = 0 local _shouldIncrement = false while true do if _shouldIncrement then row += 1 else _shouldIncrement = true end if not (row < 3) then break end local cells = board:getRow(row) local s = "" local _arg0 = function(cell) s ..= self.sep .. (" " .. (self:getSymbolString(cell:getSymbol()) .. " ")) end -- ▼ ReadonlyArray.forEach ▼ for _k, _v in ipairs(cells) do _arg0(_v, _k - 1, cells) end -- ▲ ReadonlyArray.forEach ▲ s ..= self.sep local _s = s -- ▼ Array.push ▼ lines[#lines + 1] = _s -- ▲ Array.push ▲ end end local _arg0 = string.rep(self.sep, 13) -- ▼ Array.push ▼ lines[#lines + 1] = _arg0 -- ▲ Array.push ▲ return lines end function TicTacToeStringOutput:getSymbolString(symbol) return not (symbol ~= "" and symbol) and " " or symbol end end return { TicTacToeStringOutput = TicTacToeStringOutput, }