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

Chupacabras development #4

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
4fccecf
added initial files
dieselroar Mar 26, 2015
6d730b1
prepping for work division
dieselroar Mar 26, 2015
6b390e1
Whatever
amihalopoulos 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
e5f442a
have start of display working correctly
dieselroar Mar 26, 2015
e9007da
have start of display working correctly
dieselroar 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
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
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
29eecd0
Grant recursive valid move draft location
grantziolkowski Mar 27, 2015
9dc8987
Add first move logic for pawn
grantziolkowski Mar 27, 2015
0682158
Merge pull request #10 from nyc-rock-doves-2015/chupacabras_grant
dieselroar Mar 27, 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
182 changes: 182 additions & 0 deletions Board.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
# require "byebug"

class Board
BOARDLENGTH = 8
attr_reader :board
def initialize
@board = [Array.new(8) { Array.new(nil) }]
@first_row = [Rook.new, Knight.new, Bishop.new, Queen.new, King.new, Bishop.new, Knight.new, Rook.new]
@second_row = Array.new(8) {Pawns.new}
@board[0], @board[7] = @first_row, @first_row.reverse.map! { |piece| piece.color = "black"}
@board[1], @board[6] = @second_row, @second_row.map! { |piece| piece.color = "black"}

@board = [[" ♜ " , " ♞ ", " ♝ ", " ♛ ", " ♚ ", " ♝ ", " ♞ ", " ♜ "], [ " ♟ ", " ♟ ", " ♟ ", " ♟ ", " ♟ ", " ♟ ", " ♟ ", " ♟ "], [nil, " ♙ ",nil,nil,nil,nil,nil,nil], [nil,nil,nil,nil,nil, " ♙ ",nil,nil], [nil,nil,nil,nil,nil,nil,nil,nil],[" ♙ ", " ♙ ", " ♙ ", " ♙ ", " ♙ ",nil , " ♙ "], [" ♖ ", " ♘ ", " ♗ ", " ♕ ", " ♔ ", " ♗ ", " ♘ ", " ♖ "]]
@display_board = @board
@col_letters = [" a ", " b ", " c "," d "," e "," f "," g "," h "]
@whitespace = " "
end


# # turns display_board into icons and nils into spaces
# def to_icons
# @display_board.each do |row|
# row.each do |square|
# # if square equals piece, square = piece.value, else square = whitespace (" ")
# end
# end
# end
# need this to not puts 0 to last row
def display
board_string = ""
@display_board << @col_letters
@display_board = @display_board
@display_board.each do |col|
# if value is a piece, turn into ascii
# if value is nil, turn into " "
board_string += "#{row_num} " + col.join(" ") + "\n"
BOARDLENGTH -= 1
end
puts board_string
end

def valid_moves(valid_moves = [])
x = piece.location[0]
y= piece.location[1]
valid_moves = move_one(x, y) if valid_moves = [] #otherwise you get values from the recursive move check
#filter for out_of_bounds
#mathematical valid_moves
#check against piece.location
possibilites.each do |coordinate|
# if collision with white piece, return false
x = coordinate[0]
y = coordinate[1]
next if out_of_bounds?(x,y)
next if (@board[x][y]).color == piece.color
valid_moves << coordinate
end
valid_moves
end

def recursive_move_check(piece, check_x=0, check_y=0, valid_before_bounds_check=[])
directions = piece.moves
row = piece.location[0]
col = piece.location[1]
check_x += row #incrementing out from current x location
check_y += col #incrementing out from current y location
directions.each do |direction|
check_x += direction[0]
check_y += direction[1]
if free_space?(check_x, check_y)
valid_before_bounds_check << [check_x,check_y]
recursive_move_check(piece, check_x, check_y, valid_before_bounds_check)
else
return valid_moves(valid_before_bounds_check) #base case for if it runs into a guy
end
end

end

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

def move_one(x,y)
valid_moves = []
(piece.moves).each do |vector|
x += vectors[0]
y += vector[1]
valid_moves << [x,y]
end
valid_moves
end

def out_of_bounds?(x,y)
(x < 0 || y < 0 || x > 7|| y > 7)
end

def find_piece(location_string)
index = string_to_index(location_string
piece = @board[index[0]][index[1]]
end

def string_to_index(location_string)
# a5
col_string, row_index = location_string.split("")
row_index = BOARDLENGTH - row_index.to_i
col_index = col_string.downcase.ord - 97
[row_index, col_index]
end
end


b = Board.new
# p b.board

b.display

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


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

end

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


end

class King < Piece
def initialize(color = "white")
color =="white" ? @icon = "♚" : @icon = '♔'
@moves = @all_adjacent
name = "king"
end
end


class Queen < Piece
def initialize(color = "white")
color == "white" ? @icon = "♛" : @icon = '♕'
@moves = @all_adjacent
name = "queen"
end
end

class Bishop < Piece
def initialize(color = "white")
color == "white" ? @icon = "♝" : @icon = '♗'
@moves = @all_adjacent - [0,1] - [0,-1], [1,0], [-1,0]
name = "bishop"
end
end

class Knight < Piece
def initialize(color = "white")
color == "white" ? @icon = "♞" : @icon = '♘'
@moves = [[1, 2], [1, -2], [2, 1], [2, -1], [-1, 2], [-1, -2], [-2, 1], [-2, -1]]
name = "knight"
end
end
110 changes: 110 additions & 0 deletions game.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@

def initialize(board, view)
@board = Board.new(args)
@view = View.new
@players = ["white", "black"]
end

def play
# if !game_over
players.each do |player|
turns(player)
# clear screen
# display_board
# ask for user input
#
end
# end
end

def turns(player)
# if blank square/outside of board square
view.turn_message(player)
piece = board.find_piece(view.choose_piece)
name = piece.name.downcase!
board.recursive_move_check(piece) if name == "queen" || name == "bishop" || name == "rook"
moves = valid_moves(piece)

view.piece_chosen_message(player, name, moves)
view.display_valid_moves(player, location, move) #prompts move
view.pick_move
view.player_move_message(player, piece, move)




def display_board


end

class View

def turn_message(player)
message(player_turn_message)
end

def choose_piece
message(choose_piece_message)
@choice = user_input
end
def display_valid_moves
message(piece_chosen_message)
end
def pick_move(player, choice)
"#{player}, move #{choice} where?"
@move = user_input
end
# if user picks invalid square
def pick_again
message(choose_again_message)
end



def display_player_move
message(player_move_message)
end

def display_capture_move
message(capture_message)
end

# Messages to console

def player_turn_message(player)
"#{player}'s turn"
end

def choose_piece_message(player)
"#{player}, which piece do you want to move? ex: a5, e8"
end

def piece_chosen_message(player, piece, moves)
"moves for #{player} #{piece}" + moves.join(" ")
end
# @move gets sent to board

def player_choose_move_message(player, location, move)
"ok, #{player}, move #{location} where?"
user_input
end
def player_move_message(player, piece, move)
"ok, #{player}'s #{piece} #{choice} #{location}to move to #{move}"
end



def capture_message(player, player2, piece, captured_piece, choice, move)
"#{player}'s #{piece} {choice} captures #{player2}'s #{captured_piece} #{move}"
end

# siphon methods for prompts and inputs
def user_input
gets.chomp
end

def message(str)
puts str
end
end
30 changes: 30 additions & 0 deletions git workflow
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@


Rspec
MVC
classes



git workflow

Before working on a feature that might break something.

git checkout - b "main branch name"_feature

git checkout - b "main branch name"_anotherfeature


when you want to merge back in

1st.) ON MASTER BRANCH Git pull origin master
2nd.) git fetch origin master
3nd.) git merge master (merges with your feature branch)
4rd.) fix merge issues
5th.) git merge master
6.) git push origin (branch)
7.) make pull request
8.) compare and merge


compare base branch master to feature branch