Advertisement
Guest User

chess960.rb

a guest
Dec 7th, 2012
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.72 KB | None | 0 0
  1. #960 chess position generator
  2. def assignment
  3.     positions = [1,3,5,7]
  4.     temppos = [2,4,6,8]
  5.  
  6.     assignments = {}
  7.  
  8.     positions.shuffle!
  9.     temppos.shuffle!
  10.  
  11.     assignments['B1'] = positions.pop
  12.     assignments['B2'] = temppos.pop
  13.  
  14.     positions = positions + temppos
  15.     positions.shuffle!
  16.  
  17.     assignments['Q'] = positions.pop
  18.     assignments['N1'] = positions.pop
  19.     assignments['N2'] = positions.pop
  20.  
  21.     positions.sort!
  22.  
  23.     assignments['K'] = positions[1]
  24.     assignments['R1'] = positions[0]
  25.     assignments['R2'] = positions[2]
  26.  
  27.     positions = String.new
  28.     pieces = String.new
  29.  
  30.     assignments.sort_by { |k, v| v}.each do |k, v|
  31.         pieces << k[0] + " "
  32.         positions << v.to_s + " "
  33.     end
  34.  
  35.     #puts positions
  36.     return pieces
  37. end
  38.  
  39. puts assignment
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement