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 Game | |
attr_accessor :board, :comp_winning_combos, :human_winning_combos, :comp_moves, :human_moves | |
def initialize(user, computer) | |
#Initialize the variables, this will launch the game into first_turn | |
@user="O" | |
@computer="X" | |
@comp_moves=[] | |
@human_moves=[] |
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 fourth_turn | |
if win_two | |
else | |
block_two | |
#block _two either executes or goes into the next_move method, which finds an optimal move. If optimal_move executes, it calls another user_turn, which in turn calls fifth_turn as the computer still has not yet won in its fourth_turn to continue the game. This continues until the last turn, fifth_turn, in which the computer either wins or it's Cat's Game. |
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
#In initialize method | |
@game_over=false | |
def third_turn | |
if win_one |
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 Game | |
def initialize(play_game=false) | |
@no_space=8 | |
@board={"1"=>"1", "2"=>"2", "3"=>"3", "4"=>"4", "5"=>"5", | |
"6"=>"6", "7"=>"7", "8"=>"8", "9"=>"9"} |
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 Game | |
attr_accessor :board, :no_space | |
def initialize(board=board, no_space=8) | |
@no_space=no_space | |
@board={"1"=>"1", "2"=>"2", "3"=>"3", "4"=>"4", "5"=>"5", | |
"6"=>"6", "7"=>"7", "8"=>"8", "9"=>"9"} |
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
new_game=Game.new | |
player=Players.new | |
player.welcome | |
player.user_turn | |
new_game.game_over? | |
# until new_game.game_over? | |
# player.user_turn | |
# player.computer_turn |
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 Game | |
attr_accessor :board, :no_space | |
def initialize(board=board, no_space=8) | |
@no_space=no_space | |
@board={"1"=>"1", "2"=>"2", "3"=>"3", "4"=>"4", "5"=>"5", | |
"6"=>"6", "7"=>"7", "8"=>"8", "9"=>"9"} |
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 Game | |
attr_reader :board, :computer_player, :human_player, :no_space | |
def initialize(board, computer_player, human_player) | |
@board = board | |
@computer_player = computer_player | |
@human_player = human_player | |
@no_space=no_space | |
end | |
@no_space=8 |
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
user_interface = UserInterface.new | |
computer_player= ComputerPlayer.new(board) | |
human_player= HumanPlayer.new(board, user_interface) | |
board= Board.new(computer_player, human_player, user_interface) | |
new_game= Game.new(board, computer_player, human_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 Board | |
attr_reader :board, :no_error | |
def initialize | |
@board={"1"=>"1", "2"=>"2", "3"=>"3", "4"=>"4", "5"=>"5", | |
"6"=>"6", "7"=>"7", "8"=>"8", "9"=>"9"} | |
end | |
def human_move(answer, board, ui, new_game) | |
OlderNewer