{"action":"created","issue":{"url":"https://api.github.com/repos/TIY-ATL-ROR-2015-Sep/assignments/issues/104","labels_url":"https://api.github.com/repos/TIY-ATL-ROR-2015-Sep/assignments/issues/104/labels{/name}","comments_url":"https://api.github.com/repos/TIY-ATL-ROR-2015-Sep/assignments/issues/104/comments","events_url":"https://api.github.com/repos/TIY-ATL-ROR-2015-Sep/assignments/issues/104/events","html_url":"https://github.com/TIY-ATL-ROR-2015-Sep/assignments/issues/104","id":109354190,"number":104,"title":"Weekend Assignment 2","user":{"login":"kingcons","id":127439,"avatar_url":"https://avatars.githubusercontent.com/u/127439?v=3","gravatar_id":"","url":"https://api.github.com/users/kingcons","html_url":"https://github.com/kingcons","followers_url":"https://api.github.com/users/kingcons/followers","following_url":"https://api.github.com/users/kingcons/following{/other_user}","gists_url":"https://api.github.com/users/kingcons/gists{/gist_id}","starred_url":"https://api.github.com/users/kingcons/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kingcons/subscriptions","organizations_url":"https://api.github.com/users/kingcons/orgs","repos_url":"https://api.github.com/users/kingcons/repos","events_url":"https://api.github.com/users/kingcons/events{/privacy}","received_events_url":"https://api.github.com/users/kingcons/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"HarrisonAndrews","id":14371604,"avatar_url":"https://avatars.githubusercontent.com/u/14371604?v=3","gravatar_id":"","url":"https://api.github.com/users/HarrisonAndrews","html_url":"https://github.com/HarrisonAndrews","followers_url":"https://api.github.com/users/HarrisonAndrews/followers","following_url":"https://api.github.com/users/HarrisonAndrews/following{/other_user}","gists_url":"https://api.github.com/users/HarrisonAndrews/gists{/gist_id}","starred_url":"https://api.github.com/users/HarrisonAndrews/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HarrisonAndrews/subscriptions","organizations_url":"https://api.github.com/users/HarrisonAndrews/orgs","repos_url":"https://api.github.com/users/HarrisonAndrews/repos","events_url":"https://api.github.com/users/HarrisonAndrews/events{/privacy}","received_events_url":"https://api.github.com/users/HarrisonAndrews/received_events","type":"User","site_admin":false},"milestone":null,"comments":1,"created_at":"2015-10-01T18:17:03Z","updated_at":"2015-10-05T00:20:02Z","closed_at":null,"body":"## Assignment\n\nBuild a tested, Object Oriented game of Tic-Tac-Toe as described [here][hw].\n\n[hw]: https://github.com/TIY-ATL-ROR-2015-Sep/lectures/blob/master/wk02-object-oriented-design/thu/questions.md\n\n## Submission\n\nYour solution should be pushed to a github repo under your account by Monday morning. Post a link to it in the comments of this issue.\n"},"comment":{"url":"https://api.github.com/repos/TIY-ATL-ROR-2015-Sep/assignments/issues/comments/145404354","html_url":"https://github.com/TIY-ATL-ROR-2015-Sep/assignments/issues/104#issuecomment-145404354","issue_url":"https://api.github.com/repos/TIY-ATL-ROR-2015-Sep/assignments/issues/104","id":145404354,"user":{"login":"HarrisonAndrews","id":14371604,"avatar_url":"https://avatars.githubusercontent.com/u/14371604?v=3","gravatar_id":"","url":"https://api.github.com/users/HarrisonAndrews","html_url":"https://github.com/HarrisonAndrews","followers_url":"https://api.github.com/users/HarrisonAndrews/followers","following_url":"https://api.github.com/users/HarrisonAndrews/following{/other_user}","gists_url":"https://api.github.com/users/HarrisonAndrews/gists{/gist_id}","starred_url":"https://api.github.com/users/HarrisonAndrews/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HarrisonAndrews/subscriptions","organizations_url":"https://api.github.com/users/HarrisonAndrews/orgs","repos_url":"https://api.github.com/users/HarrisonAndrews/repos","events_url":"https://api.github.com/users/HarrisonAndrews/events{/privacy}","received_events_url":"https://api.github.com/users/HarrisonAndrews/received_events","type":"User","site_admin":false},"created_at":"2015-10-05T00:20:02Z","updated_at":"2015-10-05T00:20:02Z","body":"require './player'\r\nrequire './board'\r\n\r\n\r\n# player1 = HumanPlayer.new\r\n# player2 = OtherThing.new\r\n# maybe_something_here = ???\r\n\r\nclass Tic_tac_toe\r\n  def initialize\r\n\r\n    @player1 = Player.new(name, letter)\r\n    @player2 = Player.new(name, letter)\r\n    @board = Board.new\r\n\r\n  end\r\n\r\n  def finito\r\n    @board.show_board\r\n    if @board.win?\r\n      puts \"The game is over. You won!\"\r\n    else\r\n      puts \"The game is a draw. Maybe we should stop playing tic tac toe.\"\r\n    end\r\n  end\r\n\r\n  def tic_tac_toe\r\n\r\n    # until game_over?(board)\r\n      until win?.board || draw?.board\r\n      move = update_board.board\r\n      @board[move - 1] = @player\r\n      @player = switch_player.player\r\n    endgit\r\n    finito\r\n\r\n  end\r\n\r\n  def take_turn\r\n    move = @player1.get_move\r\n    @board.update_board(move, @player1)\r\n  end\r\n\r\n\r\n\r\n\r\n\r\nend\r\n  end\r\n\r\n\r\n\r\n# game = Tic_tac_toe.new\r\n\r\n# game.play\r\n\r\n\r\n\r\n\r\n\r\n\r\n# def tic_tac_toe\r\n#   board = (1..9).to_a\r\n#   player = choose_player\r\n#   until game_over?(board)\r\n#     move = take_turn(board, player)\r\n#     board[move - 1] = player\r\n#     player = switch_player(player)\r\n#   end\r\n#   finito(player, board)\r\n# end\r\n\r\n\r\n\r\nH\r\n\r\n\r\n\r\n\r\n### For actual human input we only need choose player X or O, and selections between 1 to 9.\r\n## For the computer we only need selections 1 .. 9, and what positions are taken on the board.\r\n## we need the board, and a way to keep track of the board.\r\n## we need what constitutes a move, and how to count the moves.\r\n##finally we need what is a win, and what is a draw.\r\n## also we need tests for the game.\r\n\r\n\r\n\r\n\r\nclass Board\r\n\r\n\r\n  # WINS = [[0,1,2], [3,4,5], [6,7,8],\r\n  #         [0,3,6], [1,4,7], [2,5,8],\r\n  #         [0,4,8], [2,4,6]]\r\n\r\n\r\n  def initialize\r\n    @board = (1..9).to_a\r\n    @wins = [[0,1,2], [3,4,5], [6,7,8],\r\n            [0,3,6], [1,4,7], [2,5,8],\r\n            [0,4,8], [2,4,6]]\r\n  end\r\n  # def board\r\n  #   @board\r\n  # end\r\n\r\n  def show_board\r\n    @board\r\n    puts \"\r\n      -----------\r\n     | #{@board[0]} | #{@board[1]} | #{@board[2]} |\r\n     | #{@board[3]} | #{@board[4]} | #{@board[5]} |\r\n     | #{@board[6]} | #{@board[7]} | #{@board[8]} |\r\n      ----------- \"\r\n\r\n    end\r\n\r\n    def update_board(move, player_letter)\r\n      @board[move] = player_letter\r\n      end\r\n\r\n  def win?\r\n    WINS.any? do |x, y, z|\r\n      @board[x] == @board[y] && @board[y] == @board[z]\r\n    end\r\n  end\r\n\r\n  def draw?\r\n    # available_moves(board).empty?\r\n    @board.all? { |x| x.is_a?(String) }\r\n  end\r\n\r\n   # def game_over?\r\n   #   win?(board) || draw?(board)\r\n   # end\r\n\r\n  def available_moves\r\n    @board.reject { |x| x.is_a?(String) }\r\n  end\r\n\r\n\r\nend\r\n\r\n\r\n\r\nclass Player\r\n  def initialize(name, letter)\r\n    puts \"Name\"\r\n    @name = name\r\n    puts \"Letter x or o only\"\r\n    @letter = letter\r\n\r\n  end\r\n\r\n  def name\r\n    @name = gets.chomp\r\n  end\r\n\r\n  def letter\r\n    @letter = gets.chomp\r\n  end\r\n\r\n  # def choose_player\r\n  #   puts \"Please choose a piece 'X' or 'O'\"\r\n  #   choice = gets.chomp.upcase\r\n  #   until %w(X O).include?(choice)\r\n  #     puts \"You have to choose 'X' or 'O'!\"\r\n  #     choice = gets.chomp.upcase\r\n  #   end\r\n  #   choice\r\n  # end\r\n\r\n  def switch_player\r\n    @letter == :X ? 'O' : 'X'\r\n  end\r\n\r\n\r\n  def take_turn(board, player)\r\n    show_board(board)\r\n    puts \"Player #{player}, please choose a numbered space on the board: \"\r\n    move = gets.chomp.to_i\r\n    until available_moves(board).include?(move)\r\n      puts \"#{move} isn't an available space. Choose again: \"\r\n      move = gets.chomp.to_i\r\n    end\r\n    move\r\n  end\r\nend\r\n"}}