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