This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def taken_spaces | |
@@human_spaces = [] | |
@@computer_spaces = [] | |
@board.cells.each do |k,v| | |
if @board.cells[k] == "X" | |
@@computer_spaces << k | |
elsif @board.cells[k] == "O" | |
@@human_spaces << k | |
else |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
computer_player = ComputerPlayer.new | |
human_player = HumanPlayer.new | |
ui = UserInterface.new | |
board = Board.new(ui) | |
new_example = Example.new | |
new_game = Game.new(computer_player, human_player, ui, board, new_example) | |
new_game.start |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def computer_spaces(cells) | |
computer_spaces = [] | |
cells.each do |k,v| | |
if cells[k] == "X" | |
computer_spaces << k | |
else | |
false | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def winner?(computer_spaces, human_spaces) | |
winning_combos = [[1,2,3], [4,5,6], [7,8,9], | |
[1,4,7], [2,5,8], [3,6,9], | |
[1,5,9], [3,5,7]] | |
computer_spaces.map!(&:to_i) | |
human_spaces.map!(&:to_i) | |
winning_combos.each do |sub_array| | |
if sub_array.all? {|x|computer_spaces.include?(x)} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe Game do | |
let(:cells) { {"1" => "X", "2" => "X", "3" => "X", "4" => "O", "5" => "O", "6" => "6", "7" => "O", "8" => "8", "9" => "9"} } | |
let(:human_spaces) { ["4", "5", "7"] } | |
let(:computer_spaces) { ["1", "2", "3"] } | |
let(:open_spaces) { ["6", "8", "9"] } | |
before :each do | |
@new_game = Game.new(@computer_player, @human_player, @user_interface, @board) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def choice | |
puts "Welcome to Tic Tac Toe. Please choose your level : press e for easy and h for hard." | |
player_choice = gets.chomp | |
player_choice.upcase! | |
if player_choice == "H" | |
player_choice | |
elsif player_choice == "E" | |
player_choice | |
else |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
player = ui.choice | |
if player == "E" | |
player = computer_player | |
else | |
player = intel_computer_player | |
end | |
ui.welcome(board.cells, player) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SetUp | |
def ready | |
human_player = HumanPlayer.new | |
ui = UserInterface.new | |
board = Board.new(ui) | |
player = ui.choice | |
if player == "E" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require './lib/game' | |
require './lib/board' | |
require './lib/computer_player' | |
require './lib/human_player' | |
require './lib/user_interface' | |
require './lib/intel_computer_player' | |
require './lib/set_up.rb | |
setup = SetUp.new |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class IntelComputerPlayer | |
attr_reader :comp_winning_combos | |
def initialize | |
@comp_winning_combos = [[1,2,3], [4,5,6], [7,8,9], | |
[1,4,7], [2,5,8], [3,6,9], | |
[1,5,9], [3,5,7]] | |
end |