Skip to content

Instantly share code, notes, and snippets.

View pumpkincouture's full-sized avatar

Sylwia Bridges pumpkincouture

View GitHub Profile
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=[]
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.
#In initialize method
@game_over=false
def third_turn
if win_one
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"}
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"}
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
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"}
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
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)
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)