Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modified lib/game.rb #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions lib/game.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Game
attr_reader :board

def initialize(player_1, player_2, board = Board.new)
@players = [player_1, player_2]
@players = player_1, player_2
@board = board
@current_player_id = 0
end
Expand Down Expand Up @@ -38,29 +38,26 @@ def swap_players

def ask_a_valid_move(player)
move = player.next_move?(@board)
if valid_move?(move)
move
else
ask_a_valid_move(player)
end
if valid_move?(move) then move
else ask_a_valid_move(player) end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

end at 42, 36 is not aligned with if at 41, 6.

end

def valid_move?(move)
x, y = move
numeric_check(x, y)
range_check(x, y)
occupied_check(x, y)
numeric?(x, y)
range?(x, y)
occupied?(x, y)
end

def numeric_check(x, y)
def numeric?(x, y)
return false unless x.is_a?(Numeric) && y.is_a?(Numeric)
end

def range_check(x, y)
def range?(x, y)
return false if x < 0 || y < 0 || x > 2 || y > 2
end

def occupied_check(x, y)
def occupied?(x, y)
@board.cell_empty?(x, y)
end
end
Expand Down