Skip to content

Instantly share code, notes, and snippets.

@gabrie30
Created December 14, 2014 00:22
Show Gist options
  • Save gabrie30/819f481ab0ec44f13447 to your computer and use it in GitHub Desktop.
Save gabrie30/819f481ab0ec44f13447 to your computer and use it in GitHub Desktop.
class Checkers
attr_accessor :position, :piece
def initialize(position,piece)
@position = position
@piece = piece
$piece_position[@position] = @piece
end
end
class Board
def ui_board()
puts "8 |_#{$piece_position["a8"]}_|_#{$piece_position["b8"]}_|_#{$piece_position["c8"]}_|_#{$piece_position["d8"]}_|_#{$piece_position["e8"]}_|_#{$piece_position["f8"]}_|_#{$piece_position["g8"]}_|_#{$piece_position["h8"]}_| "
puts "7 |_#{$piece_position["a7"]}_|_#{$piece_position["b7"]}_|_#{$piece_position["c7"]}_|_#{$piece_position["d7"]}_|_#{$piece_position["e7"]}_|_#{$piece_position["f7"]}_|_#{$piece_position["g7"]}_|_#{$piece_position["h7"]}_| "
puts "6 |_#{$piece_position["a6"]}_|_#{$piece_position["b6"]}_|_#{$piece_position["c6"]}_|_#{$piece_position["d6"]}_|_#{$piece_position["e6"]}_|_#{$piece_position["f6"]}_|_#{$piece_position["g6"]}_|_#{$piece_position["h6"]}_| "
puts "5 |_#{$piece_position["a5"]}_|_#{$piece_position["b5"]}_|_#{$piece_position["c5"]}_|_#{$piece_position["d5"]}_|_#{$piece_position["e5"]}_|_#{$piece_position["f5"]}_|_#{$piece_position["g5"]}_|_#{$piece_position['h5']}_| "
puts "4 |_#{$piece_position["a4"]}_|_#{$piece_position["b4"]}_|_#{$piece_position["c4"]}_|_#{$piece_position["d4"]}_|_#{$piece_position["e4"]}_|_#{$piece_position["f4"]}_|_#{$piece_position["g4"]}_|_#{$piece_position["h4"]}_| "
puts "3 |_#{$piece_position["a3"]}_|_#{$piece_position["b3"]}_|_#{$piece_position["c3"]}_|_#{$piece_position["d3"]}_|_#{$piece_position["e3"]}_|_#{$piece_position["f3"]}_|_#{$piece_position["g3"]}_|_#{$piece_position['h3']}_| "
puts "2 |_#{$piece_position["a2"]}_|_#{$piece_position["b2"]}_|_#{$piece_position["c2"]}_|_#{$piece_position["d2"]}_|_#{$piece_position["e2"]}_|_#{$piece_position["f2"]}_|_#{$piece_position["g2"]}_|_#{$piece_position["h2"]}_| "
puts "1 |_#{$piece_position["a1"]}_|_#{$piece_position["b1"]}_|_#{$piece_position["c1"]}_|_#{$piece_position["d1"]}_|_#{$piece_position["e1"]}_|_#{$piece_position["f1"]}_|_#{$piece_position["g1"]}_|_#{$piece_position["h1"]}_| "
puts " A B C D E F G H"
end
end
board1 = Board.new()
$piece_position = {"a1"=>" ", "b1"=>" ", "c1"=>" ", "d1"=>" ", "e1"=>" ", "f1"=>" ", "g1"=>" ", "h1"=>" ", "a2"=>" ", "b2"=>" ", "c2"=>" ", "d2"=>" ", "e2"=>" ", "f2"=>" ", "g2"=>" ", "h2"=>" ", "a3"=>" ", "b3"=>" ", "c3"=>" ", "d3"=>" ", "e3"=>" ", "f3"=>" ", "g3"=>" ", "h3"=>" ", "a4"=>" ", "b4"=>" ", "c4"=>" ", "d4"=>" ", "e4"=>" ", "f4"=>" ", "g4"=>" ", "h4"=>" ", "a5"=>" ", "b5"=>" ", "c5"=>" ", "d5"=>" ", "e5"=>" ", "f5"=>" ", "g5"=>" ", "h5"=>" ", "a6"=>" ", "b6"=>" ", "c6"=>" ", "d6"=>" ", "e6"=>" ", "f6"=>" ", "g6"=>" ", "h6"=>" ", "a7"=>" ", "b7"=>" ", "c7"=>" ", "d7"=>" ", "e7"=>" ", "f7"=>" ", "g7"=>" ", "h7"=>" ", "a8"=>" ", "b8"=>" ", "c8"=>" ", "d8"=>" ", "e8"=>" ", "f8"=>" ", "g8"=>" ", "h8"=>" "}
bp1 = Checkers.new("a1", "O")
bp2 = Checkers.new("b1", "O")
bp3 = Checkers.new("c1", "O")
bp4 = Checkers.new("d1", "O")
bp5 = Checkers.new("e1", "O")
bp6 = Checkers.new("f1", "O")
bp7 = Checkers.new("g1", "O")
bp8 = Checkers.new("h1", "O")
rp1 = Checkers.new("a8", "X")
rp2 = Checkers.new("b8", "X")
rp3 = Checkers.new("c8", "X")
rp4 = Checkers.new("d8", "X")
rp5 = Checkers.new("e8", "X")
rp6 = Checkers.new("f8", "X")
rp7 = Checkers.new("g8", "X")
rp8 = Checkers.new("h8", "X")
while $piece_position.values.include?("X") && $piece_position.values.include?("O")
board1.ui_board
puts "Where do you want to move from? "
move_from = gets.downcase.chomp
puts "Where do you want to move to? "
move_to = gets.downcase.chomp
$piece_position[move_to] = $piece_position[move_from]
$piece_position[move_from] = " "
board1.ui_board
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment