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

Chupa master #6

Open
wants to merge 177 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
177 commits
Select commit Hold shift + click to select a range
b233133
Initial commit
dmilburn Mar 26, 2015
78e9d91
Set up skeleton
dmilburn Mar 26, 2015
4fccecf
added initial files
dieselroar Mar 26, 2015
69eec32
Pseudocode
dmilburn Mar 26, 2015
8fe847c
Merge pull request #1 from nyc-rock-doves-2015/DBD_development
costolo Mar 26, 2015
f46df1c
add queen and knight class attributes
costolo Mar 26, 2015
6e96b28
Add pawn and king classes
dmilburn Mar 26, 2015
6d730b1
prepping for work division
dieselroar Mar 26, 2015
6b390e1
Whatever
amihalopoulos Mar 26, 2015
c32cd49
created rook and bishop class
Doralyp Mar 26, 2015
0941018
updated from master
Doralyp Mar 26, 2015
57e2074
Merge pull request #2 from nyc-rock-doves-2015/DBD_development_pawn_king
costolo Mar 26, 2015
c185303
Merge pull request #4 from nyc-rock-doves-2015/DBD_development_ben
costolo Mar 26, 2015
a893db5
Add attr accessor and readers
dmilburn Mar 26, 2015
b1deda4
possibilities.
amihalopoulos Mar 26, 2015
e2935e0
fix merge
amihalopoulos Mar 26, 2015
b2c6e00
slight changes in board.rb
dieselroar Mar 26, 2015
d9a7045
Fixed constants
Doralyp Mar 26, 2015
e5f442a
have start of display working correctly
dieselroar Mar 26, 2015
e9007da
have start of display working correctly
dieselroar Mar 26, 2015
17279d5
Added rook and bishop
Doralyp Mar 26, 2015
a5bb6b2
Merge pull request #3 from nyc-rock-doves-2015/dora_bishop_rook
costolo Mar 26, 2015
8d95778
Merge pull request #5 from nyc-rock-doves-2015/DBD_development
costolo Mar 26, 2015
181753c
instantiate white pawn/rooks and black pawns and board
dmilburn Mar 26, 2015
ee1499f
Valid moves logic
grantziolkowski Mar 26, 2015
0aa0e4a
Add icons to pieces
amihalopoulos Mar 26, 2015
6576eec
display method should be working for a board passed in with icons and…
dieselroar Mar 26, 2015
08c86d7
Merge pull request #6 from nyc-rock-doves-2015/chupacabras_developmen…
dieselroar Mar 26, 2015
390deb4
Grant merge to Charles
grantziolkowski Mar 26, 2015
a3be469
Add moves instance vars to each piece class
amihalopoulos Mar 26, 2015
bff32f9
Add piece classes moves
amihalopoulos Mar 26, 2015
94a1804
Valid Logic moves to Grant branch
grantziolkowski Mar 26, 2015
0dcb858
Fix merge conflicts
amihalopoulos Mar 26, 2015
f206b43
Merge Charles view Grant moves
grantziolkowski Mar 26, 2015
e717809
Update for merge
amihalopoulos Mar 27, 2015
75fcd3d
initialized all pieces
dmilburn Mar 27, 2015
d54e521
Fix merge
amihalopoulos Mar 27, 2015
6e00a31
Merge alexei branch
amihalopoulos Mar 27, 2015
4bda278
Merge pull request #7 from nyc-rock-doves-2015/chupacabras_developmen…
dieselroar Mar 27, 2015
3d1a2f2
add set_up_board and place methods
dmilburn Mar 27, 2015
81cfa98
Merge pull request #8 from nyc-rock-doves-2015/DBD_development
costolo Mar 27, 2015
0e89d76
Add BOARDLENGTH constant
grantziolkowski Mar 27, 2015
2823f43
Add BOARDLENGTH constant
grantziolkowski Mar 27, 2015
1b81d17
Grant first pass at recursive move check
grantziolkowski Mar 27, 2015
59c994c
add additional rspec tests
costolo Mar 27, 2015
4753059
Display method fix and replace board instance variable with hard code…
amihalopoulos Mar 27, 2015
0794959
"Quick Display fix"
amihalopoulos Mar 27, 2015
120fe13
Add line to place
dmilburn Mar 27, 2015
e3e48d5
Make todo list
dmilburn Mar 27, 2015
29eecd0
Grant recursive valid move draft location
grantziolkowski Mar 27, 2015
9dc8987
Add first move logic for pawn
grantziolkowski Mar 27, 2015
bfa206e
add additional test
costolo Mar 27, 2015
0682158
Merge pull request #10 from nyc-rock-doves-2015/chupacabras_grant
dieselroar Mar 27, 2015
225abed
Merge pull request #11 from nyc-rock-doves-2015/DBD_development_ben
costolo Mar 27, 2015
c7a198d
Add check_move_helper method
dmilburn Mar 27, 2015
1679eea
add rspec tests
costolo Mar 27, 2015
0fb8c73
add todo_list.txt
costolo Mar 27, 2015
a042f56
Merge pull request #12 from nyc-rock-doves-2015/DBD_development_ben
costolo Mar 27, 2015
2a2628c
Removed tests in model
dmilburn Mar 27, 2015
ac7aa67
Merge pull request #13 from nyc-rock-doves-2015/DBD_development_check…
dmilburn Mar 27, 2015
4f06650
Add grant logic with old stuff commented
amihalopoulos Mar 27, 2015
0f0cf3e
Move method working
amihalopoulos Mar 27, 2015
fe32e95
Working move
amihalopoulos Mar 27, 2015
d207af0
Add king_move method
dmilburn Mar 27, 2015
8766868
Merge pull request #14 from nyc-rock-doves-2015/DBD_development_move_…
dmilburn Mar 27, 2015
ff10fb9
add additional tests
costolo Mar 27, 2015
f96039e
managing pull
costolo Mar 27, 2015
1d74084
Make standard direction order for piece moves attribute
dmilburn Mar 27, 2015
9fd66f6
working display board
dieselroar Mar 27, 2015
4498071
Hardcode with move method
amihalopoulos Mar 27, 2015
258cf6d
fix merge conflict
amihalopoulos Mar 27, 2015
25c0719
Write pseudocode for RQB move method and recursive method
dmilburn Mar 27, 2015
d905f82
Temp board
Doralyp Mar 27, 2015
fda1d62
making new branch
dieselroar Mar 27, 2015
7d12aa7
to_s method complete with black pieces
Doralyp Mar 27, 2015
a6f9c99
to_s method complete
Doralyp Mar 27, 2015
1f347b9
completed to_s method
Doralyp Mar 27, 2015
5626165
to_s
Doralyp Mar 27, 2015
de9703d
Committing so I can merge changes from group
dmilburn Mar 27, 2015
ca14185
Merging changes
dmilburn Mar 27, 2015
5b6c776
basic bad user input handling working
dieselroar Mar 27, 2015
268c68f
basic bad user input handling working
dieselroar Mar 27, 2015
607326e
Add rqb_move method and rqb_move_recursive method
dmilburn Mar 27, 2015
584b095
Merge pull request #15 from nyc-rock-doves-2015/DBD_development_move_…
dmilburn Mar 27, 2015
3152eba
Finished knight method
Doralyp Mar 27, 2015
0f255e1
finished knight method
Doralyp Mar 27, 2015
831ddcb
Merge pull request #16 from nyc-rock-doves-2015/dora_bishop_rook
Doralyp Mar 27, 2015
8ea6eb2
Remove extra space in white_pieces_array and black_pieces_array
dmilburn Mar 27, 2015
d7e6813
central controller play method coming along nicely
dieselroar Mar 27, 2015
554cb5e
central controller play method coming along nicely
dieselroar Mar 27, 2015
346274a
Recursive check 90% working
amihalopoulos Mar 27, 2015
9bd6488
Working pawn_move method
dmilburn Mar 27, 2015
99fd978
Recursive check 90% working
amihalopoulos Mar 27, 2015
bd10c44
Clean up
dmilburn Mar 27, 2015
592bbc7
Merge pull request #18 from nyc-rock-doves-2015/DBD_development_move_…
costolo Mar 27, 2015
99ec1ef
Valid moves complete?
amihalopoulos Mar 27, 2015
68fc29d
Merge pull request #20 from nyc-rock-doves-2015/chupa_master_alexei
dieselroar Mar 27, 2015
ef1129f
something is odd with display on board but everything else involving …
dieselroar Mar 27, 2015
5e6f922
Finish move check
amihalopoulos Mar 27, 2015
c8985cd
merging
dieselroar Mar 28, 2015
cc3b7cc
created many new display messages
dieselroar Mar 28, 2015
4f0f3d9
fix subarrays issue in valid_move
amihalopoulos Mar 28, 2015
70d734f
fixed merge conflicts
dieselroar Mar 28, 2015
855a13f
Remove p piece.moves from valid_moves
amihalopoulos Mar 28, 2015
1492ded
Merge pull request #26 from nyc-rock-doves-2015/chupa_master_charles
dieselroar Mar 28, 2015
cf03f0c
fix merge conflicts
amihalopoulos Mar 28, 2015
9e50d69
Merge pull request #27 from nyc-rock-doves-2015/chupa_master_alexei
dieselroar Mar 28, 2015
3ec87e7
Merge branch 'master' of https://github.com/nyc-rock-doves-2015/chess…
dieselroar Mar 28, 2015
b5b6b6b
merging
dieselroar Mar 28, 2015
4ac6ee6
merging to merge
dieselroar Mar 28, 2015
3b2c31d
Merge Master version to Grant's version
grantziolkowski Mar 28, 2015
94eff23
Merge Game master to Grant's computer
grantziolkowski Mar 28, 2015
7162f50
fixed display method
dieselroar Mar 28, 2015
270ad2b
Back to working
amihalopoulos Mar 28, 2015
067d2e6
Fix merge conlficts
amihalopoulos Mar 28, 2015
50a65ae
Pulled chupa_master
grantziolkowski Mar 28, 2015
198673d
working display method and working through move issues
dieselroar Mar 28, 2015
72fb510
display and move working correctly
dieselroar Mar 28, 2015
8977bd5
Add pawn first move logic
amihalopoulos Mar 28, 2015
7119c85
merging
dieselroar Mar 28, 2015
c1b9d26
fdacv
amihalopoulos Mar 28, 2015
79dfe06
Fix merge conflicts
amihalopoulos Mar 28, 2015
afd278c
Merge pull request #33 from nyc-rock-doves-2015/chupa_master_alexei
dieselroar Mar 28, 2015
6f7ac9f
Initial check logic
grantziolkowski Mar 28, 2015
ab6ae82
working on captured piece/valid_moves logic
dieselroar Mar 28, 2015
7808c3a
Initial check logic
grantziolkowski Mar 28, 2015
54c2e76
working on valid movesuser input vanitizing
dieselroar Mar 28, 2015
4681fe7
add capture
amihalopoulos Mar 28, 2015
ce13e8c
Most recent checkmate logic
grantziolkowski Mar 28, 2015
8c16507
fix merge conflicts
amihalopoulos Mar 28, 2015
9931f64
Most recent Board
grantziolkowski Mar 28, 2015
2e62569
Most recent Board master
grantziolkowski Mar 28, 2015
3623b41
Most recent refactored game master
grantziolkowski Mar 28, 2015
fac7b45
display and move working well, working on sanitizing user input to pr…
dieselroar Mar 28, 2015
5f31b61
Check working still finishing checkmate
grantziolkowski Mar 28, 2015
4e8d235
Editing checkmate logic
grantziolkowski Mar 28, 2015
77fc387
user input sanitizied. user should not be able to break game intentio…
dieselroar Mar 28, 2015
f05985a
Fix pawn first move
amihalopoulos Mar 28, 2015
6aa360f
Fix merge conflicts
amihalopoulos Mar 28, 2015
983ae15
Merge pull request #35 from nyc-rock-doves-2015/chupa_master_alexei
dieselroar Mar 28, 2015
c486557
merging
dieselroar Mar 28, 2015
5b6e1b6
merged
dieselroar Mar 28, 2015
0c954e4
utterly sanitized user inputs. PLayers can only select their own piec…
dieselroar Mar 28, 2015
e74a834
Fix pawn attack
amihalopoulos Mar 28, 2015
f3ddf47
Fix merge conflicts
amihalopoulos Mar 28, 2015
d595d3c
Merge pull request #37 from nyc-rock-doves-2015/chupa_master_alexei
dieselroar Mar 28, 2015
bef8d13
testing a couple small things
dieselroar Mar 28, 2015
2e8ed95
fixed valid_move_choice method, working on captured piece message
dieselroar Mar 28, 2015
ba59ba0
capture message working
dieselroar Mar 28, 2015
3707e47
have blocked piece error messages working
dieselroar Mar 29, 2015
9942f5e
have king taken logic working
dieselroar Mar 29, 2015
00368e1
have king taken logic working
dieselroar Mar 29, 2015
63568a2
changed MCV around a bit and did my best to #pimp the terminal display
dieselroar Mar 29, 2015
57ce22d
simplified valid_pick? method
dieselroar Mar 29, 2015
5958026
bit of refactoring
dieselroar Mar 29, 2015
d2fb8c7
branching to work on deselection feature
dieselroar Mar 29, 2015
88e8ba7
Check is correct not checkmate
grantziolkowski Mar 29, 2015
d5a12ba
Improving checkmate logic
grantziolkowski Mar 29, 2015
766c669
Checkmate works but untested
grantziolkowski Mar 29, 2015
3b6a590
Checkmate working
grantziolkowski Mar 29, 2015
0e6c16e
Merged group master to my grant master
grantziolkowski Mar 30, 2015
921c531
Merged chupa master to grant
grantziolkowski Mar 30, 2015
aa61b98
Merged chupa master with grant branch
grantziolkowski Mar 30, 2015
446faaa
Fixing errors to run
grantziolkowski Mar 30, 2015
8711ce6
Checkmate works includes most recent valid moves pawn attacks
grantziolkowski Mar 30, 2015
de0dff2
Grant most recent with rspec
grantziolkowski Mar 30, 2015
8fd500b
Merge pull request #45 from nyc-rock-doves-2015/chupa_grant
grantziolkowski Mar 30, 2015
283ace9
fixed color nil bug
dieselroar Mar 30, 2015
9d3d2ab
"merging"
dieselroar Mar 30, 2015
6be913e
merging
dieselroar Mar 30, 2015
a7e336f
merging back into master
dieselroar Mar 30, 2015
ce454b8
Merge pull request #46 from nyc-rock-doves-2015/chupa_master_deselection
dieselroar Mar 30, 2015
43ccb2f
fixed nil coord error
dieselroar Mar 30, 2015
3113f3a
fixed minor bug and merging
dieselroar Mar 30, 2015
640c508
Refactor checkmate method- incomplete
grantziolkowski Mar 30, 2015
cb1fc53
Group chess project merged to Grant checkmate logic does not catch al…
grantziolkowski Mar 30, 2015
4310510
Merge pull request #47 from nyc-rock-doves-2015/chupa_grant
grantziolkowski Mar 30, 2015
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
394 changes: 394 additions & 0 deletions Board.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,394 @@


# TODO: refactor
# TODO: group into public/private methods

# TODO: fix the hardcoded board initialization, for the very least do it for nil values.
# if any array is less than 8 values, fill it with nils after you initialize.



# require "byebug"

class Board


attr_accessor :board, :board_values, :game_over, :checkmate
attr_reader :captured
def initialize
@checkmate = false
@board = [[Rook.new([0,0]), Knight.new([0, 1]), Bishop.new([0, 2]), Queen.new([0, 3]), King.new([0, 4]), Bishop.new([0, 5]), Knight.new([0, 6]), Rook.new([0,7])], [Pawn.new([1,0]), Pawn.new([1,1]), Pawn.new([1,2]), Pawn.new([1,3]), Pawn.new([1,4]), Pawn.new([1,5]), Pawn.new([1,6]), Pawn.new([1,7])], [nil, nil, nil, nil, nil,nil, nil, nil], [nil, nil, nil, nil, nil,nil, nil, nil], [nil, nil, nil, nil, nil,nil, nil, nil], [nil, nil, nil, nil, nil,nil, nil, nil], [Pawn.new([6,0], "black"), Pawn.new([6,1], "black"), Pawn.new([6,2], "black"), Pawn.new([6,3], "black"), Pawn.new([6,4], "black"), Pawn.new([6,5], "black"), Pawn.new([6,6], "black"), Pawn.new([6, 7], "black")], [Rook.new([7, 0], "black"), Knight.new([7, 1], "black"), Bishop.new([7, 2], "black"), King.new([7, 3], "black"), Queen.new([7, 4], "black"), Bishop.new([7, 5], "black"), Knight.new([7, 6], "black"), Rook.new([7, 7], "black")]]
@col_letters = ["a","b","c","d","e","f","g", "h"]
@boardlength = 8
@display_board = ""
@board_values = { "a1"=> [0,0], "b1"=> [0,1], "c1"=> [0,2], "d1" => [0,3], "e1" => [0,4], "f1" => [0,5], "g1" => [0,6], "h1" => [0,7], "a2" => [1,0], "b2" => [1,1], "c2" => [1,2], "d2" => [1,3], "e2" => [1,4], "f2" => [1,5], "g2" => [1,6], "h2" => [1,7], "a3" => [2,0], "b3" => [2,1], "c3" => [2,2], "d3" => [2,3], "e3" => [2,4], "f3" => [2,5], "g3" => [2,6], "h3" => [2,7], "a4" => [3,0], "b4" => [3,1], "c4" => [3,2], "d4" => [3,3], "e4" => [3,4], "f4" => [3,5], "g4" => [3,6], "h4" => [3,7], "a5" => [4,0], "b5" => [4,1], "c5" => [4,2], "d5" => [4,3], "e5" => [4,4], "f5" => [4,5], "g5" => [4,6], "h5" => [4,7], "a6" => [5,0], "b6" => [5,1], "c6" => [5,2], "d6" => [5,3], "e6" => [5,4], "f6" => [5,5], "g6" => [5,6], "h6" => [5,7], "a7" => [6,0], "b7" => [6,1], "c7" => [6,2], "d7" => [6,3], "e7" => [6,4], "f7" => [6,5], "g7" => [6,6], "h7" => [6,7], "a8" => [7,0], "b8" => [7,1], "c8" => [7,2], "d8" => [7,3], "e8" => [7,4], "f8" => [7,5], "g8" => [7,6], "h8" => [7,7] }
@captured = []
@game_over = false
@empty_square_mark = "."
end

def display
format
end

def format
row_num = 8
@board_string = ""
board_row = []
@board.reverse.each do |row|
@board_string += "#{row_num} "
row.each do |cell|
cell == nil ? cell = @empty_square_mark : cell = cell.display_icon
@board_string +=" " + cell + " "
end
@board_string += "\n" + "\n"
row_num -= 1
end
@board_string += " " + @col_letters.join(" ")

end

def move(piece,new_pos)
p new_pos
old_pos = piece.location
@board[new_pos[0]][new_pos[1]] = piece
@board[old_pos[0]][old_pos[1]] = nil
piece.set_location(new_pos)
end


def free_space?(piece, check_row, check_col)
@board[check_row][check_col] == nil
end

def find_piece(location)
piece = square(location[0], location[1])
end

def friendly_fire?(piece, check_row, check_col)
return false if free_space?(piece,check_row, check_col)
square(check_row, check_col).color == piece.color
end

def piece_captured?(piece, location)
(@board[location[0]][location[1]] != nil)

end

def capture_piece(location)
@captured << square(location[0], location[1])
@board[location[0]][location[1]] = nil
end


def piece_captured?(piece, location)
(@board[location[0]][location[1]] != nil)
end

def capture_piece(location)
@captured << square(location[0], location[1])
@board[location[0]][location[1]] = nil
@game_over = true if king_taken?
end

def valid_move(piece)
valid_moves = []
piece.respond_to?(:pawn_attack) ? piece_moves = piece.moves(@board) : piece_moves = piece.moves
current_location = piece.location
piece_moves.each do |move|
x = current_location[0] + move[0]
y = current_location[1] + move[1]
next if out_of_bounds?([x,y])
if free_space?(piece, x, y)
valid_moves << [x,y] #fix
vector_array = check_direction(piece, x, y, move[0], move[1])
vector_array.each { |coord| valid_moves << coord } unless piece.multiple_moves == false || vector_array == []
# valid_moves << vector_array
elsif (@board[x][y]).color != piece.color
valid_moves << [x,y]
else
next
end
end
valid_moves
end


# private


def out_of_bounds?(location)
x = location[0]
y = location[1]
(x < 0 || y < 0 || x > 7|| y > 7)
end


def king_taken?
@captured.each do |object|
return true if object.name == "king"
end
end


def check_direction(piece, x, y, add_x, add_y, array_direction = [])
if out_of_bounds?([x + add_x, y + add_y])
return array_direction
elsif friendly_fire?(piece, x + add_x, y + add_y) #&& piece.name != 'knight'
return array_direction
elsif free_space?(piece,x + add_x, y + add_y)
array_direction << [x + add_x, y + add_y]
check_direction(piece, x + add_x, y + add_y, add_x, add_y, array_direction )
else
array_direction << [x + add_x, y + add_y]
end
array_direction
end

def find_piece(location)
piece = square(location[0], location[1])
end

def check?(player, board_state=board) #does player color put the other teams king in check?
result = false
team = all_pieces_same_color(player)# all of one player's pieces on board
all_possible_team_moves = [] # all the potential moves by all the player's pieces
team.each do |piece|
valid_move(piece).each do |move|
x = move[0]
y = move[1]
all_possible_team_moves << move
next if board_state[x][y] == nil
if board_state[x][y].name == "king" #if one of your valid moves equals the king
king_location = [x,y] # location, the king is in check
result = true
checkmate?(player, all_possible_team_moves, king_location)
end

end
end
result
end

def checkmate?(player, all_possible_team_moves, king_location)
king_x = king_location[0]

Choose a reason for hiding this comment

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

king_x, king_y = king_location This pattern could probably save a lot of typing throughout. For example

row, col = location instead of using location[0] and location[1] all over.

king_y = king_location[1]
@checkmate = valid_move(@board[king_x][king_y]).all? do |king_move|
all_possible_team_moves.include?(king_move) || #if the king is in check, and your valid moves also cover its valid moves
king_moves_into_check?(player, king_move, king_x, king_y)
#if king captures a location, if he is then in check
end

end

def king_moves_into_check?(player, king_move, king_x, king_y)
king = @board[king_x][king_y]
return if king == nil
self.move(king, king_move)
check?(player, board)
end

def all_pieces_same_color(player)
team = []
@board.each_with_index do |row, r_i|
row.each_with_index.select do |col,c_i|
next if @board[r_i][c_i] == nil
team << @board[r_i][c_i] if @board[r_i][c_i].color == player
end
end
team
end



def square(x,y)
@board[x][y]
end


end


class Piece
attr_accessor :color, :moves, :location, :name
attr_reader :display, :multiple_moves
def initialize(location, color = "white")
@icon = icon
@all_adjacent = [[0, 1],[0, -1],[1,0],[-1,0],[1,1],[-1,1],[1,-1],[-1,-1]]
@location = location
@multiple_moves = true
end

def display_icon
@icon
end

def set_location(new_pos)
self.location = new_pos
end
end

class Pawn < Piece
attr_reader :color
attr_accessor :multiple_moves
#logic for capturing?
def initialize(location, color = "white")
@location = location
@color = color
@color == "white" ? @icon = "♟" : @icon = '♙'
@multiple_moves = false
# first_move? == true if self.location[0] == 1 || self.location[0] == 6 #initial row value for pawns
# moves << [0,2] if first_move?
# moves << [1,1] if capturing?
@name = "pawn"
end

def moves(board = nil)
moves = []
if @location[0] == 1 && @color == "white"
moves = [[1,0], [2,0]]
elsif @color == "white"
moves = [[1,0]]
elsif @location[0] == 6 && @color == "black"
moves = [[-1,0], [-2,0]]
else
moves = [[-1, 0]]
end
if pawn_attack(board) == []
moves
else
pawn_attack(board).each { |coord| moves << coord }
moves
end

end

def pawn_attack(board)
x = location[0]
y = location[1]
array = []
if board[x + 1][y + 1] != nil && board[x + 1][y + 1].color != self.color && color == "white"
array << [1, 1]
end
if board[x+1][y-1] != nil && (board[x+1][y-1]).color != self.color && color == "white"
array << [1, -1]
end
if board[x-1][y-1] != nil && board[x-1][y-1].color != color && color == "black"
array << [-1, -1]
end
if board[x-1][y+1] != nil && board[x-1][y+1].color != self.color && color == "black"
array << [-1, +1]
end
array
end
end

# TODO: deal with possible_moves method
class Rook < Piece
attr_reader :color
attr_accessor :moves, :multiple_moves
def initialize(location, color = "white")
@location = location
@multiple_moves = true
@color = color
@icon = @color == "white" ? "♜" : '♖'
@moves = [[0,1], [1,0], [-1,0], [0, -1]]
@name = "rook"
end

end

class King < Piece
attr_reader :color
attr_accessor :moves, :multiple_moves
def initialize(location, color = "white")
@location = location
@color = color
@color =="white" ? @icon = "♚" : @icon = '♔'
@multiple_moves = false
@moves = [[0, 1],[0, -1],[1,0],[-1,0],[1,1],[-1,1],[1,-1],[-1,-1]]
@name = "king"
end
end

class Queen < Piece
attr_reader :color
attr_accessor :moves, :multiple_moves
def initialize(location, color = "white")
@location = location
@color = color
@color == "white" ? @icon = "♛" : @icon = '♕'
@moves = [[0, 1],[0, -1],[1,0],[-1,0],[1,1],[-1,1],[1,-1],[-1,-1]]
@name = "queen"
end
end

class Bishop < Piece
attr_reader :color
attr_accessor :moves, :multiple_moves
def initialize(location, color = "white")
@location = location
@color = color
@color == "white" ? @icon = "♝" : @icon = '♗'

Choose a reason for hiding this comment

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

@icon = (@color == "white" ? "♝" : '♗')

@moves = [[1, 1], [1, -1], [-1, 1], [-1, -1]]
@name = "bishop"
end
end

class Knight < Piece
attr_reader :color
attr_accessor :moves, :multiple_moves
def initialize(location, color = "white")
@location = location
@color = color
@color == "white" ? @icon = "♞" : @icon = '♘'
@multiple_moves = false
@moves = [[1, 2], [1, -2], [2, 1], [2, -1], [-1, 2], [-1, -2], [-2, 1], [-2, -1]]
@name = "knight"
end
end



b = Board.new

# p b.board


# b.move([1,3], [3,3])
# b.move([1,4], [3,4])
# b.move([1,5], [3,5])
# b.move([6,1], [5,1])
# # p b.board[3][4]
# # p b.valid_move(b.board[3][4])
# p b.valid_move(b.board[5][1])
# #puts b.display
# p b.board[1][1]

b = Board.new

b = Board.new
b.all_pieces_same_color("white")

b.board
board2 = Board.new
test_board = board2.board
test_board.each_with_index.map do |row, row_index|
row.each_with_index.map do |col, col_index|
test_board[row_index][col_index] = nil
end
end
test_board[0][0] = King.new([0,0])
test_board[0][1] = Queen.new([0,1], "black")
test_board[0][2] = Rook.new([0,2], "black")
# test_board[1][1] = Bishop.new([1,1], "black")
p "king"
p board2.valid_move(test_board[0][0])
p "rook"
p board2.valid_move(test_board[0][2])
p "queen"
p board2.valid_move(test_board[0][1])

# p board2.board
p board2.check?("black")
p board2.checkmate
Loading