small elixir learning exercise
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

add cli

pfeyz 6a126f88 557637fd

+19 -5
+1 -1
lib/board.ex
··· 92 92 IO.puts "" 93 93 for x <- 0..2 do 94 94 row = for c <- Board.row(board, x) do 95 - if c do c else '.' end 95 + if c do c else "." end 96 96 end 97 97 IO.puts(Enum.join row, " ") 98 98 end
+18 -3
lib/tit_tac_toe.ex
··· 15 15 :world 16 16 17 17 """ 18 - def run(_) do 19 - Logger.configure [level: :info] 20 - game = [o: Client.Random, x: Client.Random] |> Game.new |> Game.play 18 + def run(args) do 19 + Logger.configure [level: :debug] 20 + 21 + 22 + player_map = %{ 23 + "rand" => Client.Random, 24 + "term" => Client.Terminal, 25 + "udp" => Client.UDP 26 + } 27 + 28 + args = case args do 29 + [] -> ["rand", "rand"] 30 + args -> args 31 + end 32 + 33 + [px, po] = Enum.map(args, fn name -> Map.fetch!(player_map, name) end) 34 + 35 + game = [x: px, o: po] |> Game.new |> Game.play 21 36 case game do 22 37 {:ok, game} -> Game.State.inspect(game) 23 38 {:error, error} -> IO.inspect error
-1
mix.exs
··· 8 8 elixir: "~> 1.16", 9 9 start_permanent: Mix.env() == :prod, 10 10 deps: deps(), 11 - default_task: "start_game" 12 11 ] 13 12 end 14 13